i have a for-loop fading out an LED within about 2 seconds. This loops starts, if a pin gets a Signal and ends, when the loop has finished - of course. But i need a script, which allows to end the loop immediately, when signal is lost.
But i need a script, which allows to end the loop immediately, when signal is lost.
You could look at the blink without delay example. Instead of blinking, you define what the next fade value is.
Depending on your definition of “immediately”, you could roll your own delay that involves checking for the signal, and ending the for loop when the signal goes away.
Your not reading the signal pin in the for loop, your reading what it previously was and not what it currently is. Try to digitally read the pin while in the for loop.
HazardsMind: break; will exit the for loop when it is called. So if you monitor the signal and it suddenly stops, you can call break; and it will exit the loop.
It does the same thing for while loops too.
break ; exits the innermost enclosing loop or switch statement.