Complete the code to set the button pin as input with pull-up resistor.
pinMode(2, [1]);
Using INPUT_PULLUP sets the pin as input with an internal pull-up resistor enabled.
Complete the code to read the button state from pin 2.
int buttonState = digitalRead([1]);The button is connected to pin 2, so we read from pin 2.
Fix the error in the if statement to check if the button is pressed (active LOW).
if (buttonState == [1]) { // button pressed }
With pull-up resistor, the button reads LOW when pressed.
Fill both blanks to create a dictionary comprehension that maps button pins to their states if pressed.
auto pressedButtons = {pin: digitalRead(pin) [1] pin in pins if digitalRead(pin) [2] LOW};The comprehension uses for to loop and checks if the state is LOW.
Fill all three blanks to create a dictionary comprehension that stores pin numbers as keys and their pressed status as boolean values.
auto buttonStatus = { [1]: digitalRead([2]) [3] LOW for [2] in pins };The key is pin, the value checks if digitalRead(pin) == LOW for pressed.
