Complete the code to set pin 13 as an output.
void setup() {
pinMode([1], OUTPUT);
}
void loop() {
// Empty loop
}Pin 13 is commonly used for the built-in LED on many Arduino boards. Setting it as OUTPUT allows us to control the LED.
Complete the code to read the state of a button connected to pin 7.
int buttonState = digitalRead([1]);To read a button connected to pin 7, use digitalRead(7).
Fix the error in the code to turn on the LED connected to pin 9.
digitalWrite([1], HIGH);The LED is connected to pin 9, so digitalWrite should use pin 9 to turn it on.
Fill both blanks to create a dictionary that maps LED pins to button pins.
const int ledPins[] = { [1] };
const int buttonPins[] = { [2] };LED pins are 9, 10, 11 and button pins are 7, 8, 12 to match each LED with a button.
Fill all three blanks to complete the loop that turns on LEDs when their buttons are pressed.
for (int i = 0; i < [1]; i++) { int buttonState = digitalRead([2][i]); if (buttonState == [3]) { digitalWrite(ledPins[i], HIGH); } else { digitalWrite(ledPins[i], LOW); } }
The loop runs 3 times for 3 LEDs and buttons. It reads each button pin from buttonPins array. If the button is pressed (LOW because buttons often connect to ground when pressed), the LED turns on; otherwise, it turns off.
