Independent Switch


this is to break the while loop when it is pressed.

yes, another push button which is used to break the loop.

How is it same?


Hi Shramik.

This portion of the code that you gave:

while (digitalRead(pushButton))

does this mean when the button is pushed it goes inside the loop statement and goes outside the loop when the button is released? Can it be more explicit like this?

while (digitalRead(pushButton == 1))


yup you are almost right but should be opposite as the button is pulled up. so it is 1 when not pressed and it remains in the loop and when pressed it is 0 and exits the loop.

should be: while (digitalRead(pushButton) == 1)


Thanks for the swift reply. : )

1 Like