bio photo

Email

Digital I/O

void setup() {
  // put your setup code here, to run once:
pinMode(2, INPUT); //setting the switch pin to be an input
pinMode(3, OUTPUT); //green LED pin is OUTPUT
pinMode(4, OUTPUT); //Blue LED pin is OUTPUT
}

void loop() {
  // put your main code here, to run repeatedly:

//read the switch input
if (digitalRead(2) == HIGH) {
  // if the switch is closed:
  digitalWrite(3, HIGH); // green LED is ON
  digitalWrite(4, LOW); //blue LED is OFF
    }
else {
  digitalWrite(3, LOW); // green LED is OFF
  digitalWrite(4, HIGH); //blue LED is ON 
  }
}