Script and Tests

Script: pushbutton_test

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 ( matches the screencaptures).
  • 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 editor, click Connect, and then click Flash.   
# pushbutton_test

from microbit import *

state = 0

while True:
    state = pin6.read_digital()
    print("state = ", state)



  • In the editor, click Open Serial ( matches the screencaptures).
  • 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.