My for loop to turn 7 pins on and off in sequence works great but when I put that inside and if statement so I can control these pins using a small pir sensor, it doesn't work.
The actual code I am using is as follow; Could you, please, provide some suggestions. Thanks
Maybe you could tell us what doesn't work, so we don't have to guess. How many other "typos" are there so we don't have to go down too many rabbit holes?
When i tested the for loop by itself, it worked fine. It turns the first LED on then off and moves to next one that 's why i have that delay in my code.
but when I tried putting the for loop inside the if statement because I am using a pir sensor to trigger the LEDs when motion is sensed, it wouldn't work.
I wanted to say: when the output pin of the pir is high do the for loop which just turns the LEDs on and off in sequence as I explained else turn them off.
I hope I clarified a little bit.
Thank you
Do you know if the PIR sensor is working right? Why not add some Serial.println() calls in there to debug your sketch and see what is happening and when...
You're looping through the pins, and for each one you turn it off, then you delay, then you turn it off. Then you go through them all again in a different order and turn them all off... twice...
Why?
That whole section is pointless, as the section of code when the sensor is HIGH would have left all the LEDs off anyway. You don't need anything from the "else" to the end of the if construct.
if your 'if' statement isn't going True/high in this code, first check if the digitalRead at 8 is even going high or not when u need it . just turn on a single led may be , other than that the thing looks fine.
ferkheusa:
I added that code to make sure the LEDs stay off.
I guess I don't need it.
That's like switching off the light in your room by first flicking the switch to "off", then taking the bulb out and finally ripping the socket out of the ceiling.
Once an output is off it is off - you don't need to keep reminding it.