Lesson 2, digital inputs and outputs

  • In the second lesson, we are explaining how to control some leds by connecting a button as digital sensor:

    THIS IS A SOLUTION FOR THE CODE:

    void setup() {
      // initialize digital pins 13 and pin 10 as an output, and pin 2 as input
      pinMode(13, OUTPUT);
      pinMode(10, OUTPUT);

    pinMode (2, INPUT);
    }
    void loop() {

    if (digitalRead (2) == HIGH){ // condition for the button (HIGH is when pressed)
      digitalWrite(13, HIGH);  
      digitalWrite(10, LOW); // turn the LED 13 on and the LED 10 off                     
     }else {
      digitalWrite(13, LOW);
      digitalWrite(10, HIGH); // alternative ligthning     
    }

    }