/* Red LED is always on, when button is pressed Green LED turns on and Red LED turns off. */ // constants: const int buttonPin = 7; // the number of the pushbutton pin const int ledPinRed = 2; // the number of the Red LED pin const int ledPinGreen = 3; // the number of the Gree LED pin // variables will change: int buttonState = 0; // variable for reading the pushbutton status void setup() { // initialize the LED pins as outputs: pinMode(ledPinRed, OUTPUT); pinMode(ledPinGreen, OUTPUT); // initialize the pushbutton pin as an input: pinMode(buttonPin, INPUT); } void loop() { // read the state of the pushbutton value: buttonState = digitalRead(buttonPin); // declaring the Red LED is on by default: ledPinRed == HIGH; // check if the pushbutton is pressed. If it is, the buttonState is HIGH: if (buttonState == HIGH) { // turn Green LED on: digitalWrite(ledPinGreen, HIGH); } else { // turn Green LED off: digitalWrite(ledPinGreen, LOW); } if (buttonState == HIGH) { // turn Red LED off: digitalWrite(ledPinRed, LOW); } else { // turn Red LED on: digitalWrite(ledPinRed, HIGH); } }