Script and Tests

Script: pushbutton_test_x2

The pushbutton_test_x2 script displays the states of both pushbuttons in the Serial Monitor.  

  • Enter the pushbutton_test_x2 script into the micro:bit Python Editor.
  • Set the project name field to metric_prefixes_to_values, then click Save.
  • Click Send to micro:bit.
# pushbutton_test_x2

from microbit import *

state9 = 0
state6 = 0
display.off()
pin9.set_pull(pin9.NO_PULL)
pin6.set_pull(pin6.NO_PULL)

while True:
    state9 = pin9.read_digital()
    state6 = pin6.read_digital()
    print("state9:", state9, " state6:", state6)
    sleep(250)

Tests

  • In the editor, click Show serial.
  • Verify that when you do not press the P6 pushbutton, it displays state6 = 0.
  • Verify that when you press and hold the P6 pushbutton, it displays state6 = 1.
  • Verify that when you do not press the P9 pushbutton, it displays state9 = 0.
  • Verify that when you press and hold the P9 pushbutton, it displays state9 = 1.
  • When you are done, click Hide serial.