-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJoystick.py
More file actions
59 lines (48 loc) · 1.82 KB
/
Joystick.py
File metadata and controls
59 lines (48 loc) · 1.82 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
import time
import random
from colorsys import hsv_to_rgb
import board
from digitalio import DigitalInOut, Direction
from PIL import Image, ImageDraw, ImageFont
from adafruit_rgb_display import st7789
import numpy as np
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
self.button_C = DigitalInOut(board.D4)
self.button_C.direction = Direction.INPUT
# Turn on the Backlight
self.backlight = DigitalInOut(board.D26)
self.backlight.switch_to_output()
self.backlight.value = True
# Create blank image for drawing.
# Make sure to create image with mode 'RGB' for color.
self.width = self.disp.width
self.height = self.disp.height