I’m using a reed contact and I want to create a loop, which adds 1 to an int every time the signal is HIGH. I used digitalRead(pin) to check whether it is HIGH or LOW. During a measurement of 10 seconds, the signal is several times HIGH and I would like to receive this as an int. I hope someone can give me some help.
How do you want to count two HIGH in a row? If you read a HIGH to you want to wait for a LOW before counting a new HIGH or is the count just as fast as the loop can spin?
J-M-L:
How do you want to count two HIGH in a row? If you read a HIGH to you want to wait for a LOW before counting a new HIGH or is the count just as fast as the loop can spin?
If I read HIGH, I want to wait for a LOW before counting. If I use if (digitalRead(x) == HIGH) count++;
it counts just as fast as the loop can spin, I think.
In which case it's not counting number of times you read HIGH, it counts the number of loops while reading HIGH.
--Michael
edit: To say it more accurately, you are counting the number of times you read high while still high, not the number of times the input goes high.
--M.