Working with built-in push buttons
Figure 5.1 shows two built-in push buttons in Micro:bit. They are named A and B. They are connected to GPIO pins 5 and 11, respectively. The MicroPython implementation for Micro:bit comes with built-in methods to work with them. Let’s see a simple example, as follows:
from microbit import * try: while True: if button_a.is_pressed(): print("Button A is pressed...") elif button_b.is_pressed(): print("Button B is pressed...") else: print("No Button is pressed...") sleep(100) except KeyboardInterrupt...