Updated demo.py with A/B/X/Y button example

Added code to show a simple example of the on-board A/B/X/Y button press detection and displaying the result on the display, as this feature of the Pico Explorer hardware was not being demonstrated in the initial demo.py example.
pull/48/head
SimUKdev 2021-02-09 00:47:54 +00:00 zatwierdzone przez GitHub
rodzic 71d5f0785c
commit d70708596e
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
1 zmienionych plików z 21 dodań i 3 usunięć

Wyświetl plik

@ -35,8 +35,26 @@ while True:
explorer.set_pen(0, 0, adc2 * 2)
explorer.circle(90 + adc2, 66, 10)
explorer.set_pen(255, 255, 255)
explorer.text("Plug a jumper wire from GP0 to AUDIO to hear noise!", 20, 110, 200)
# example for the on-board A/B/X/Y buttons
if explorer.is_pressed(explorer.BUTTON_A):
explorer.set_pen(255, 255, 255)
explorer.text("Button A pressed", 20, 110, 200)
elif explorer.is_pressed(explorer.BUTTON_B):
explorer.set_pen(255, 255, 255)
explorer.text("Button B pressed", 20, 110, 200)
elif explorer.is_pressed(explorer.BUTTON_X) and explorer.is_pressed(explorer.BUTTON_Y):
explorer.set_pen(255, 255, 255)
explorer.text("Buttons X and Y pressed", 20, 110, 200)
elif explorer.is_pressed(explorer.BUTTON_X):
explorer.set_pen(255, 255, 255)
explorer.text("Button X pressed", 20, 110, 200)
elif explorer.is_pressed(explorer.BUTTON_Y):
explorer.set_pen(255, 255, 255)
explorer.text("Button Y pressed", 20, 110, 200)
else:
# no button press was detected
explorer.set_pen(255, 255, 255)
explorer.text("Plug a jumper wire from GP0 to AUDIO to hear noise!", 20, 110, 200)
explorer.set_tone(i)
@ -59,4 +77,4 @@ while True:
i = 1
explorer.update()
time.sleep(0.01)
time.sleep(0.01)