#define LEDY 19 // yellow LED
#define LEDG 18 // green LED
#define LEDR 23 // red LED
#define PB1 27 // green button
#define PB2 25 // blue button
void setup()
{
Serial.begin(115200);
Serial.println("Blink program started");
pinMode(LEDR,OUTPUT);
pinMode(LEDG,OUTPUT);
pinMode(LEDY,OUTPUT);
pinMode(PB1, INPUT);
pinMode(PB2, INPUT);
digitalWrite(LEDY,HIGH); // ensure that the yellow LED remains off
}
void loop() // states the 4 possibilities
{ // put your main code here, to run repeatedly:
if (digitalRead(PB1) == 0 && digitalRead(PB2) == 0) // press both buttons
{ // both lights are on
digitalWrite(LEDR,LOW);
digitalWrite(LEDG,LOW);
}
if (digitalRead(PB1) == 1 && digitalRead(PB2) == 0) // pressed the blue button
{ // one is on while the other is off
digitalWrite(LEDR,HIGH);
digitalWrite(LEDG,LOW);
}
if (digitalRead(PB1) == 0 && digitalRead(PB2) == 1) // pressed the green button
{ // one is on while the other is off
digitalWrite(LEDR,LOW);
digitalWrite(LEDG,HIGH);
}
if (digitalRead(PB1) == 1 && digitalRead(PB2) == 1) // pressed none of the buttons
{ // both lights are off
digitalWrite(LEDR,HIGH);
digitalWrite(LEDG,HIGH);
}
}