Why might pressing the button on your GAA scoreboard prototype make the pin read zero?
Your team is building a GAA scoreboard prototype. You press a button to turn on an indicator, but the board reports zero. You let go, and it reports one. Can you make the indicator follow the button anyway?
Think back to your last embedded system. A sensor gave your program information about the world. A button can do that too. Your program reads the button through an input pin, decides what to do, then uses an output pin to drive an LED.
When you release the button, the pull-up holds the pin high, so it reads one. The pull-down holds it low, so it reads zero. When you press, the first circuit connects to ground and reads zero. The second connects to the supply and reads one. That's active-low and active-high, respectively.
Your button connects the input to ground when you press it. When you let go, the pull-up sets the pin level. What will your program read while the button is pressed? Pick an answer.
On a Raspberry Pi Pico, import Pin from the machine module. Set GPIO fourteen as an input with its internal pull-up. Set GPIO fifteen as an output that starts at zero. In the loop, read the button and write one to the LED pin only when the reading equals zero.
Press the button and the input reads zero. The test is true, so the integer conversion gives one. Write one and the LED lights. Release the button and the input reads one. The test is false, so the conversion gives zero. Write zero and the LED goes out.
Another team uses a pull-down and a button that connects the input to the supply when pressed. Their LED still lights when the output is one. Which condition should their code use to turn it on? Pick an answer.
If you assume a press reads one, you might copy the input straight to the LED pin. Here, pressing writes zero and turns the LED off. Releasing writes one and turns it on. Test for zero instead. Now pressing writes one and lights the LED, and releasing writes zero.
With power off, check the Pico pinout together. The button connects GPIO fourteen to ground when pressed. Connect GPIO fifteen to the LED's anode through a three hundred and thirty ohm resistor, then connect the cathode to ground. Power up, print both input readings and compare the LED with your trace.
Test an automatic low-light warning. Use a dial to simulate light. Wire it across three point three volts and ground, with its wiper on GPIO twenty-six. Read and store the analogue value as a sample. The LED lights when you hold the button and the simulated reading is below thirty thousand.