Author: Vio Zhu (yz9617) | Sep 14, 2023 | Fall 2023 section: Rios Tuesday
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:
result: use analog pin A0 to adjust LED light brightness in output pin 9.