-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjoystick.py
More file actions
66 lines (55 loc) · 2.03 KB
/
joystick.py
File metadata and controls
66 lines (55 loc) · 2.03 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
58
59
60
61
62
63
64
65
66
import board
from digitalio import DigitalInOut, Direction
from adafruit_rgb_display import st7789
# 조이스틱 및 디스플레이 설정
class Joystick:
def __init__(self):
self.cs_pin = DigitalInOut(board.CE0)
self.dc_pin = DigitalInOut(board.D25)
self.reset_pin = DigitalInOut(board.D24)
self.BAUDRATE = 24000000
self.spi = board.SPI()
self.disp = st7789.ST7789(
self.spi,
height=240,
y_offset=80,
rotation=180,
cs=self.cs_pin,
dc=self.dc_pin,
rst=self.reset_pin,
baudrate=self.BAUDRATE,
)
# Input pins
self.button_A = DigitalInOut(board.D5)
self.button_A.direction = Direction.INPUT
self.button_B = DigitalInOut(board.D6)
self.button_B.direction = Direction.INPUT
self.button_L = DigitalInOut(board.D27)
self.button_L.direction = Direction.INPUT
self.button_R = DigitalInOut(board.D23)
self.button_R.direction = Direction.INPUT
self.button_U = DigitalInOut(board.D17)
self.button_U.direction = Direction.INPUT
self.button_D = DigitalInOut(board.D22)
self.button_D.direction = Direction.INPUT
# Turn on the Backlight
self.backlight = DigitalInOut(board.D26)
self.backlight.switch_to_output()
self.backlight.value = True
self.width = self.disp.width
self.height = self.disp.height
def get_command(self):
commands = []
if not self.button_U.value:
commands.append('up_pressed')
if not self.button_D.value:
commands.append('down_pressed')
if not self.button_L.value:
commands.append('left_pressed')
if not self.button_R.value:
commands.append('right_pressed')
if not self.button_A.value:
commands.append('a_pressed')
if not self.button_B.value:
commands.append('b_pressed')
return commands if commands else None