Link to lab: https://itp.nyu.edu/physcomp/labs/labs-arduino-digital-and-analog/digital-input-and-output-with-an-arduino/
I chose to edit files with VSCode and use the Arduino CLI rather than using the Arduino IDE. It took me a moment to realize the uploading had to be done from the same directory as the sketch, but it worked!
My first sketch:
// test sketch for controlling LED output using a push button
// for lab: <https://itp.nyu.edu/physcomp/labs/labs-arduino-digital-and-analog/digital-input-and-output-with-an-arduino/>
const int pushButton = 2; // pin number for push button
const int redLED = 3; // pin number for red LED
const int whiteLED = 4; // pin number for white LED
void setup() {
pinMode(pushButton, INPUT);
pinMode(redLED, OUTPUT);
pinMode(whiteLED, OUTPUT);
}
void loop() {
// read input signal from input 2 (pushbutton)
if (digitalRead(pushButton) == HIGH) {
digitalWrite(redLED, HIGH); // turn on the red LED
digitalWrite(whiteLED, LOW); // turn off the white LED
}
else {
// if push button is open
digitalWrite(redLED, LOW); // turn off the red LED
digitalWrite(whiteLED, HIGH); // turn on the white LED
}
}
Controlling a LED light using an Arduino taking input from a pushbutton
Controlling a LED light using an Arduino taking input from a pushbutton