Skip to content

Commit e8260bf

Browse files
authored
Merge pull request #1041 from pimoroni/examples/rp2350-display-pack
Display Pack: Make button example work with RP2350 boards
2 parents 6346133 + 77e6a9d commit e8260bf

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

micropython/examples/pico_display/button_test.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# If you have a Display Pack 2.0" or 2.8" use DISPLAY_PICO_DISPLAY_2 instead of DISPLAY_PICO_DISPLAY
33

44
import time
5-
from pimoroni import Button
5+
from machine import Pin
66
from picographics import PicoGraphics, DISPLAY_PICO_DISPLAY, PEN_P4
77
from pimoroni import RGBLED
88

@@ -12,10 +12,10 @@
1212
display.set_backlight(0.5)
1313
display.set_font("bitmap8")
1414

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)
1919

2020
# Set up the RGB LED For Display Pack and Display Pack 2.0":
2121
led = RGBLED(6, 7, 8)
@@ -43,31 +43,32 @@ def clear():
4343
clear()
4444

4545
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...
4748
clear() # clear to black
4849
display.set_pen(WHITE) # change the pen colour
4950
led.set_rgb(255, 255, 255) # set the LED colour to match
5051
display.text("Button A pressed", 10, 10, 240, 4) # display some text on the screen
5152
display.update() # update the display
5253
time.sleep(1) # pause for a sec
5354
clear() # clear to black again
54-
elif button_b.read():
55+
elif button_b.value() == 0:
5556
clear()
5657
display.set_pen(CYAN)
5758
led.set_rgb(0, 255, 255)
5859
display.text("Button B pressed", 10, 10, 240, 4)
5960
display.update()
6061
time.sleep(1)
6162
clear()
62-
elif button_x.read():
63+
elif button_x.value() == 0:
6364
clear()
6465
display.set_pen(MAGENTA)
6566
led.set_rgb(255, 0, 255)
6667
display.text("Button X pressed", 10, 10, 240, 4)
6768
display.update()
6869
time.sleep(1)
6970
clear()
70-
elif button_y.read():
71+
elif button_y.value() == 0:
7172
clear()
7273
display.set_pen(YELLOW)
7374
led.set_rgb(255, 255, 0)

0 commit comments

Comments
 (0)