digitalWrite()
PINS
int switchState = 0;
void setup()
{
pinMode (3, OUTPUT);
pinMode (4, OUTPUT);
pinMode (5, OUTPUT);
pinMode (2, INPUT); //This pin is the button as INPUT.
}
void loop()
{
switchState = digitalRead(2); //switchState will change to HIGH(1) or LOW(0) depending if the button is pressed.
if (switchState==LOW) { //If the button is not pressed.
digitalWrite (3, HIGH); //green LED will be on.
digitalWrite (4, LOW);
digitalWrite (5, LOW);
}
else { //else is applied only if the corresponding “if” state isn’t accomplished.
digitalWrite (3, LOW);
digitalWrite (4, LOW);
digitalWrite (5, HIGH);
delay(250);// wait for a quarter second
//toogle the Leds
digitalWrite (4, HIGH);
digitalWrite (5, LOW);
delay (250);// wait for a quarter second
}
}