forked from ladyada/Adafruit_CircuitPython_Display_Button
-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathdisplay_button_simpletest.py
More file actions
57 lines (51 loc) · 1.3 KB
/
display_button_simpletest.py
File metadata and controls
57 lines (51 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import board
import displayio
import terminalio
from adafruit_button import Button
import adafruit_touchscreen
# --| Button Config |-------------------------------------------------
BUTTON_X = 110
BUTTON_Y = 95
BUTTON_WIDTH = 100
BUTTON_HEIGHT = 50
BUTTON_STYLE = Button.ROUNDRECT
BUTTON_FILL_COLOR = 0x00FFFF
BUTTON_OUTLINE_COLOR = 0xFF00FF
BUTTON_LABEL = "HELLO WORLD"
BUTTON_LABEL_COLOR = 0x000000
# --| Button Config |-------------------------------------------------
# Setup touchscreen (PyPortal)
ts = adafruit_touchscreen.Touchscreen(
board.TOUCH_XL,
board.TOUCH_XR,
board.TOUCH_YD,
board.TOUCH_YU,
calibration=((5200, 59000), (5800, 57000)),
size=(320, 240),
)
# Make the display context
splash = displayio.Group()
board.DISPLAY.show(splash)
# Make the button
button = Button(
x=BUTTON_X,
y=BUTTON_Y,
width=BUTTON_WIDTH,
height=BUTTON_HEIGHT,
style=BUTTON_STYLE,
fill_color=BUTTON_FILL_COLOR,
outline_color=BUTTON_OUTLINE_COLOR,
label="HELLO WORLD",
label_font=terminalio.FONT,
label_color=BUTTON_LABEL_COLOR,
)
# Add button to the display context
splash.append(button)
# Loop and look for touches
while True:
p = ts.touch_point
if p:
if button.contains(p):
button.selected = True
else:
button.selected = False