Hi, i have a problem in using 2 toggle buttons to light up an led.
let's say toggle A (TA) and toggle B (TB) are the toggle buttons.
The LED should light up only when TA then TB is pressed. When TB is released LED should be off.
In my mind:
a) Since its a toggle button, how do we hold or keep TA value and compare to TB (both high) to activate the LED ?
b) how do we set all button state in off before running ?
Since this is a school project, ill give you a small code piece that explains what happens:
void loop(){
if (digitalRead(TA) == HIGH){ // if the TA button is pressed
while (digitalRead(TB) != HIGH); //wait for the TB button to be pressed
while (digitalRead(TB) == HIGH); //wait for the TB button to be released
digitalWrite(LED, HIGH); //turn on the LED
while (digitalRead(TB) != HIGH); //wait for the TB button to be pressed
while (digitalRead(TB) == HIGH); //wait for the TB button to be released
digitalWrite(LED, LOW); //turn off the LED
}
}
Now do you actually mean a toggle button? The word toggle means change the state, so a toggle button would mean every time it is pressed it will change its state. This is also known as a latching switch or a push on push off switch.
I suspect you actually mean a momentary push button which is what that code is written for.