I have Arduino with photoresistor attached to external device's LED. If this external device wants to signalise some error then it's blinking that LED. In normal operation that LED stays mostly OFF, but sometimes it can go ON without blinking. Blinking frequency may vary, i.e. sometimes it's blinking fast sometimes it's blinking slowly.
Now all I want to detect is just the fact that it's blinking. Let's say after three regular (but undefined) changes of state I would classify it as positive. What algorithm can I use for that purpose?
If the blink is regular, no matter what the speed, then you can time between The detection of low to high transition an see if there is a similar interval. If the interval is significantly different (defined by some dead band you set) then reset the detection and start again.
If the blink is regular, no matter what the speed, then you can time between The detection of low to high transition an see if there is a similar interval.
"No matter what the speed" is stretching things a bit. 20 cycles per second is measurable. 200000 is not.
I am describing an algorithm, not an implementation. In principle no matter what the speed you could use the same method. Agree in practice it suits the way the OP described requirements rather than high speed.
By undefined I mean two things. Firstly I don't know the initial state so it may start blinking from being OFF or from being ON. Secondly I don't know the interval but it must be regular. If the changes are regular and there is enough of these changes then it's blinking, otherwise it's not blinking. Also it's important that I can get time from RTC and I can not use delay().
OK thanks guys so I know I will need three predefined constants:
how many state changes until it's considered as blinking, for example 4
minimum pause between changes, for example 30 milliseconds
maximum pause between changes, for example 5 seconds