|
2 | 2 | # If you have a Display Pack 2.0" or 2.8" use DISPLAY_PICO_DISPLAY_2 instead of DISPLAY_PICO_DISPLAY
|
3 | 3 |
|
4 | 4 | import time
|
5 |
| -from pimoroni import Button |
| 5 | +from machine import Pin |
6 | 6 | from picographics import PicoGraphics, DISPLAY_PICO_DISPLAY, PEN_P4
|
7 | 7 | from pimoroni import RGBLED
|
8 | 8 |
|
|
12 | 12 | display.set_backlight(0.5)
|
13 | 13 | display.set_font("bitmap8")
|
14 | 14 |
|
15 |
| -button_a = Button(12) |
16 |
| -button_b = Button(13) |
17 |
| -button_x = Button(14) |
18 |
| -button_y = Button(15) |
| 15 | +button_a = Pin(12, Pin.IN, Pin.PULL_UP) |
| 16 | +button_b = Pin(13, Pin.IN, Pin.PULL_UP) |
| 17 | +button_x = Pin(14, Pin.IN, Pin.PULL_UP) |
| 18 | +button_y = Pin(15, Pin.IN, Pin.PULL_UP) |
19 | 19 |
|
20 | 20 | # Set up the RGB LED For Display Pack and Display Pack 2.0":
|
21 | 21 | led = RGBLED(6, 7, 8)
|
@@ -43,31 +43,32 @@ def clear():
|
43 | 43 | clear()
|
44 | 44 |
|
45 | 45 | while True:
|
46 |
| - if button_a.read(): # if a button press is detected then... |
| 46 | + # button logic is reversed as we're using pull-ups |
| 47 | + if button_a.value() == 0: # if a button press is detected then... |
47 | 48 | clear() # clear to black
|
48 | 49 | display.set_pen(WHITE) # change the pen colour
|
49 | 50 | led.set_rgb(255, 255, 255) # set the LED colour to match
|
50 | 51 | display.text("Button A pressed", 10, 10, 240, 4) # display some text on the screen
|
51 | 52 | display.update() # update the display
|
52 | 53 | time.sleep(1) # pause for a sec
|
53 | 54 | clear() # clear to black again
|
54 |
| - elif button_b.read(): |
| 55 | + elif button_b.value() == 0: |
55 | 56 | clear()
|
56 | 57 | display.set_pen(CYAN)
|
57 | 58 | led.set_rgb(0, 255, 255)
|
58 | 59 | display.text("Button B pressed", 10, 10, 240, 4)
|
59 | 60 | display.update()
|
60 | 61 | time.sleep(1)
|
61 | 62 | clear()
|
62 |
| - elif button_x.read(): |
| 63 | + elif button_x.value() == 0: |
63 | 64 | clear()
|
64 | 65 | display.set_pen(MAGENTA)
|
65 | 66 | led.set_rgb(255, 0, 255)
|
66 | 67 | display.text("Button X pressed", 10, 10, 240, 4)
|
67 | 68 | display.update()
|
68 | 69 | time.sleep(1)
|
69 | 70 | clear()
|
70 |
| - elif button_y.read(): |
| 71 | + elif button_y.value() == 0: |
71 | 72 | clear()
|
72 | 73 | display.set_pen(YELLOW)
|
73 | 74 | led.set_rgb(255, 255, 0)
|
|
0 commit comments