counter analog
hi,
can tell me how counter in analog sensor? using photoresistor, want count how many times blocked, seem in code, keep counting when blocking. want button (so counted when pressed , when blocking = 1, not keep counting)
can tell me how counter in analog sensor? using photoresistor, want count how many times blocked, seem in code, keep counting when blocking. want button (so counted when pressed , when blocking = 1, not keep counting)
code: [select]
#include <timedaction.h>
int potpin = 0; // select input pin photoresistor
int ledpin = 13; // select pin led
int val = 0; // variable store value coming sensor
int currval =0;
int valshadow = 0;
timedaction resetaction = timedaction(5000,resetshadowcount);
timedaction updateshadowaction = timedaction(500,updateshadow);
void setup() {
serial.begin(9600); // value
pinmode(ledpin, output); // declare ledpin output
}
void loop() {
resetaction.check();
updateshadowaction.check();
}
void resetshadowcount(){
//valshadow += currval;
serial.print("your shadow ");
serial.print(valshadow);
serial.println(" times");
currval = 0;
valshadow = 0;
}
void updateshadow(){
val = analogread(potpin);
//serial.println(val);
if (val < 300){
currval = 1;
return;
}
//while (val < 350){
// currval != 1;
//}
valshadow += currval;
}
code: [select]
if (val < 300){
currval = 1;
return;
}
i think need set "currval = 0" if "val >= 300",
otherwise, reset every 5 seconds.
maybe lose "return" in there too?
Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > counter analog
arduino
Comments
Post a Comment