Hi,
I try to count a HIGH / LOW state of a signal.
The parts of the code (analog signal to digital signal) works.
Count-part in another sketch (standard arduinosketch ButtonStateChange) works
But in the total sketch the count-part don't work.
Anyone an idea? (of course... i'm still a very newbee...)
Below the code
Gr.
Johan
boolean signal;
int sensorvalue;
int signalCounter = 0; // counter for the number of button presses
int signalState = 0; // current state of the button
int lastsignalState = 0; // previous state of the button
void setup(){
Serial.begin(9600);
}
void loop(){
sensorvalue = analogRead(A0);
signalState = digitalRead(signal);
if (sensorvalue == 1006){
signal = HIGH;
}
if (sensorvalue == 0){
signal = LOW;
}
if (signalState != lastsignalState) {
if (signalState == HIGH) {
signalCounter ++;
}
lastsignalState = signalState;
}
Serial.print(sensorvalue);
Serial.print(",");
Serial.print(signal);
Serial.print(",");
Serial.println(signalCounter);
delay(500);
}