Skip to content

Commit bfdeb83

Browse files
authored
Various updates (see extended description)
Some settings improvements (some not functional yet) Add drivers!! Some other minor stuff.
1 parent 1537202 commit bfdeb83

File tree

4 files changed

+284
-0
lines changed

4 files changed

+284
-0
lines changed

drivers/analog_joystick_driver.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
xa = machine.ADC(machine.Pin(36))
2+
ya = machine.ADC(machine.Pin(39))
3+
btn = machine.Pin(32, machine.Pin.IN, machine.Pin.PULL_UP)
4+
5+
xa.atten(xa.ATTN_11DB)
6+
ya.atten(ya.ATTN_11DB)
7+
8+
minval = const(500)
9+
maxval = const(2500)
10+
11+
def left():
12+
return xa.read()<=minval
13+
14+
def right():
15+
return xa.read()>=maxval
16+
17+
def up():
18+
return ya.read()<=minval
19+
20+
def down():
21+
return ya.read()>=maxval
22+
23+
def pressed():
24+
return btn.value()==0

drivers/externalSD.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import sdcard
2+
3+
try:
4+
sdspi=machine.SoftSPI(-1, sck=machine.Pin(18), mosi=machine.Pin(23), miso=machine.Pin(19))
5+
sd = sdcard.SDCard(sdspi, machine.Pin(5))
6+
os.mount(sd, '/sd')
7+
print('SD card mounted.')
8+
except Exception as e:
9+
print('No SD card present.')

drivers/onscreen_keyboard.py

Lines changed: 239 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,239 @@
1+
def numpad(textx=25, texty=10):
2+
def redraw():
3+
num = 0
4+
for i in range(0, 3):
5+
for n in range(0, 6):
6+
display.text(fontlarge, nums[num], 13+40*n, 130+34*i)
7+
num +=1
8+
for i in range(0, 3):
9+
for n in range(0, 6):
10+
display.rect(3+40*n, 130+34*i, 34, 30, st7789.BLUE)
11+
12+
redraw()
13+
14+
row = 0
15+
collum = 0
16+
17+
entered = ''
18+
19+
while True:
20+
time.sleep(0.25)
21+
display.rect(3+40*collum, 130+34*row, 34, 30, st7789.BLUE)
22+
if btn.value() == 0:
23+
if nums[row*6+collum] == '=':
24+
return entered
25+
elif nums[row*6+collum] == 'C':
26+
entered = ''
27+
display.fill_rect(11, texty, 220, 32, st7789.BLACK)
28+
display.text(fontlarge, entered, textx, texty, st7789.BLUE)
29+
print(entered)
30+
else:
31+
entered += nums[row*6+collum]
32+
display.fill_rect(11, texty, 220, 32, st7789.BLACK)
33+
display.text(fontlarge, entered, textx, texty, st7789.BLUE)
34+
35+
if xa.read() < minval:
36+
collum -= 1
37+
if xa.read() > maxval:
38+
collum += 1
39+
if ya.read() < minval:
40+
row -= 1
41+
if ya.read() > maxval:
42+
row += 1
43+
44+
if row > 2:
45+
row = 2
46+
if row < 0:
47+
row = 0
48+
if collum > 5:
49+
collum = 5
50+
if collum < 0:
51+
collum = 0
52+
53+
display.rect(3+40*collum, 130+34*row, 34, 30, st7789.BLACK)
54+
55+
def redrawletters():
56+
letter=0
57+
for i in range(0,5):
58+
for n in range(0,10):
59+
display.text(font, letters[letter], 7+n*24, 153+i*17, st7789.YELLOW)
60+
letter += 1
61+
display.fill_rect(190, 218, 50, 20, st7789.BLACK)
62+
display.fill_rect(70, 218, 74, 20, st7789.BLACK)
63+
64+
display.rect(74, 218, 68, 15, st7789.WHITE)
65+
display.rect(194, 218, 44, 15, st7789.WHITE)
66+
67+
display.text(font, 'UP', 5, 222, st7789.YELLOW)
68+
display.text(font, 'SPACE', 87, 222, st7789.YELLOW)
69+
display.text(font, 'ENTER', 196, 222, st7789.YELLOW)
70+
71+
def redrawlettersupper():
72+
letter=0
73+
for i in range(0,5):
74+
for n in range(0,10):
75+
display.text(font, lettersupper[letter], 7+n*24, 153+i*17, st7789.YELLOW)
76+
letter += 1
77+
display.fill_rect(190, 218, 50, 20, st7789.BLACK)
78+
display.fill_rect(70, 218, 74, 20, st7789.BLACK)
79+
80+
display.rect(74, 218, 68, 15, st7789.WHITE)
81+
display.rect(194, 218, 44, 15, st7789.WHITE)
82+
83+
display.text(font, 'UP', 5, 222, st7789.YELLOW)
84+
display.text(font, 'SPACE', 87, 222, st7789.YELLOW)
85+
display.text(font, 'ENTER', 196, 222, st7789.YELLOW)
86+
87+
def keyboard(pretyped=''):
88+
display.fill(0)
89+
typed = pretyped
90+
selected = ''
91+
letter = 0
92+
93+
row = 0
94+
collum = 0
95+
width = 20
96+
97+
display.rect(width, 2, 200, 15, st7789.WHITE)
98+
99+
def updatekeyboard():
100+
for i in range(0,5):
101+
for n in range(0,10):
102+
display.rect(2+n*24, 150+i*17, 20, 15, st7789.WHITE)
103+
104+
updatekeyboard()
105+
106+
redrawletters()
107+
108+
display.rect(2+collum*24, 150+row*17, width, 15, st7789.RED)
109+
110+
upper = False
111+
112+
while True:
113+
time.sleep(0.15)
114+
display.rect(2+collum*24, 150+row*17, width, 15, st7789.WHITE)
115+
116+
display.text(font, typed, 25, 5, st7789.YELLOW)
117+
if xa.read() <= minval:
118+
collum -= 1
119+
if xa.read() >= maxval:
120+
collum += 1
121+
122+
if ya.read() <= minval:
123+
row -= 1
124+
if ya.read() >= maxval:
125+
row += 1
126+
127+
if row < 0:
128+
row = 0
129+
if collum < 0:
130+
collum = 0
131+
if row > 4:
132+
row = 4
133+
if collum > 9:
134+
collum = 9
135+
136+
if row == 4 and collum >= 3 and collum <= 5:
137+
width = 68
138+
elif row == 4 and collum >= 8 and collum <= 9:
139+
width = 44
140+
else:
141+
width = 20
142+
143+
if btn.value() == 0:
144+
if selected == 'enter':
145+
return typed
146+
break
147+
else:
148+
if upper == False:
149+
selected = letters[row * 10 + collum]
150+
typed = typed + selected
151+
else:
152+
selected = lettersupper[row * 10 + collum]
153+
typed = typed + selected
154+
upper = False
155+
redrawletters()
156+
if row == 4 and collum == 8:
157+
selected = 'enter'
158+
elif row == 4 and collum == 0:
159+
selected = ''
160+
upper = True
161+
redrawlettersupper()
162+
163+
display.rect(2+collum*24, 150+row*17, width, 15, st7789.RED)
164+
165+
def unubstructingkeyboard(pretyped=''):
166+
typed = pretyped
167+
selected = ''
168+
letter = 0
169+
row = 0
170+
collum = 0
171+
width = 20
172+
173+
display.rect(width, 2, 200, 15, st7789.WHITE)
174+
175+
def updatekeyboard():
176+
for i in range(0,5):
177+
for n in range(0,10):
178+
display.rect(2+n*24, 150+i*17, 20, 15, st7789.WHITE)
179+
180+
updatekeyboard()
181+
182+
redrawletters()
183+
184+
display.rect(2+collum*24, 150+row*17, width, 15, st7789.RED)
185+
186+
upper = False
187+
188+
while True:
189+
time.sleep(0.15)
190+
display.rect(2+collum*24, 150+row*17, width, 15, st7789.WHITE)
191+
192+
display.text(font, typed, 25, 5, st7789.YELLOW)
193+
if xa.read() <= minval:
194+
collum -= 1
195+
if xa.read() >= maxval:
196+
collum += 1
197+
198+
if ya.read() <= minval:
199+
row -= 1
200+
if ya.read() >= maxval:
201+
row += 1
202+
203+
if row < 0:
204+
row = 0
205+
if collum < 0:
206+
collum = 0
207+
if row > 4:
208+
row = 4
209+
if collum > 9:
210+
collum = 9
211+
212+
if row == 4 and collum >= 3 and collum <= 5:
213+
width = 68
214+
elif row == 4 and collum >= 8 and collum <= 9:
215+
width = 44
216+
else:
217+
width = 20
218+
219+
if btn.value() == 0:
220+
if selected == 'enter':
221+
return typed
222+
break
223+
else:
224+
if upper == False:
225+
selected = letters[row * 10 + collum]
226+
typed = typed + selected
227+
else:
228+
selected = lettersupper[row * 10 + collum]
229+
typed = typed + selected
230+
upper = False
231+
redrawletters()
232+
if row == 4 and collum == 8:
233+
selected = 'enter'
234+
elif row == 4 and collum == 0:
235+
selected = ''
236+
upper = True
237+
redrawlettersupper()
238+
239+
display.rect(2+collum*24, 150+row*17, width, 15, st7789.RED)

drivers/st7789_driver.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import st7789
2+
3+
sc = machine.Pin(22, machine.Pin.OUT)
4+
5+
sc.on()
6+
7+
spi = machine.SPI(1, baudrate=40000000, polarity=1)
8+
display = st7789.ST7789(spi, 240, 240, reset=machine.Pin(27, machine.Pin.OUT), dc=machine.Pin(26, machine.Pin.OUT), backlight=sc)
9+
display.init()
10+
11+
width = 240
12+
height = 240

0 commit comments

Comments
 (0)