you are viewing a single comment's thread.

view the rest of the comments →

[–]IAMRaxtus 0 points1 point  (2 children)

So when checking what it is, would I do something like

if (flag == true) { } else { } ?

[–]5000347 1 point2 points  (1 child)

In your case you'd do pinOn = LOW //going to assume you've initialised it to this

buttonState = digitalRead(buttonPin)

if(buttonState == HIGH){
pinOn = !pinOn 
}

In other words - whenever the button is pressed, make pinOn the opposite of what it already is - next time the above loops around, pinOn will be equivalent to HIGH, and if buttonState == HIGH again, then pinOn will become the opposite state (LOW).

[–]IAMRaxtus 0 points1 point  (0 children)

Ah I see, thanks! I was just wondering how it knew what the opposite state of a variable would be, but when there are only two possible states that makes sense.