ITP BLOG


Lab: Digital Input and Output with an Arduino

1. Add Digital Input and Add Digital Output:

2. Program the Arduino

    When I first uploaded, I kept getting errors. Then I realize it is better to verify the the code and check the circuit on the breadboard before uploading the code to the Arduino. 


Pin 2 connected to the switch to the Arduino and then run the output to pin 3 & 4 connected to the yellow and red LEDs. 
void setup(){
  // put your setup code here, to run once:
  pinMode(2, INPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);

}

void loop() {
// put your main code here, to run repeatedly:
  if(digitalRead(2) == HIGH) {
    digitalWrite(3, HIGH);
    digitalWrite(4, LOW);
    }  else {
    digitalWrite(3, LOW);
    digitalWrite(4, HIGH);
    }

}