The pushbutton_test script displays whether or not the pushbutton is pressed as values of 1 and 0. These values are often called states. With this pushbutton circuit and script, a state of 1 indicates pressed, and 0 indicates not pressed.
- Enter the pushbutton_test script into the python.microbit.org editor.
- Set the Script Name field to pushbutton_test.
- Click Load/Save, and then click Download Project Hex to save your work.
- Close the Load/Save dialog box after downloading.
- In the python.microbit.org editor, click Connect, and then click Flash.
# pushbutton_test from microbit import * state = 0 display.off() pin6.set_pull(pin6.NO_PULL) while True: state = pin6.read_digital() print("state = ", state) sleep(250)
- In the python.microbit.org editor, click Open Serial.
- Verify that while the pushbutton is not pressed, it displays state = 0.
- Verify that when you press and hold the pushbutton, it displays state = 1.
- When you are done, click Close Serial.