I'm learning the basics of arduino and there's a problem that's been bugging me, I had a task of turning 6 leds in a row so they will turn on to the right and turn off the previous one, I also had to add a command so that if I press on a button, it will switch sides and go left instead of right.
I used the for loop and if statement for it
It works perfectly but when I switch sides I have to wait until the loop ends, which takes quite a lot of time, my question is, is there a way to make it switch sides even when it's halfway into the loop?
Read the input inside the for loop
or
let the loop() function do the looping and read the input in the loop() function
Check the button in the loop. If the button changes the direction, use the "break;" statement to exit out of that loop and go back to whatever decides which loop to run.