Author: Vio Zhu (yz9617) | Sep 14, 2023 | Fall 2023 section: Rios Tuesday

1. Lab: Digital Input and Output

IMG_1289.mov

result: use input pin 2 as data source, pin output 3 (red) and pin output 4 (green) can output differently to light up the led.

void setup() {
  pinMode(2, INPUT);    // set the pushbutton pin to be an input
  pinMode(3, OUTPUT);   // set the yellow LED pin to be an output
  pinMode(4, OUTPUT);   // set the red LED pin to be an output
}

void loop() {
   // read the pushbutton input:
   if (digitalRead(2) == HIGH) {
     // if the pushbutton is closed:
     digitalWrite(3, HIGH);    // turn on the yellow LED
     digitalWrite(4, LOW);     // turn off the red LED
   }
   else {
     // if the switch is open:
     digitalWrite(3, LOW);     // turn off the yellow LED
     digitalWrite(4, HIGH);    // turn on the red LED
   }
 }

Things I learnt:

2. Lab: Analog Input

2.1 Potentiometer as Analog Input

IMG_1292.mov

result: use analog pin A0 to adjust LED light brightness in output pin 9.