/
main.py
228 lines (208 loc) · 5.73 KB
/
main.py
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
#4/1/19 initial menu
#4/28/19 rework menu
import gc
import sys
import os
import gc
import utime
from gamerGorl import gamerGorl
#import uos
#fs_stat = uos.statvfs('/')
#fs_size = fs_stat[0] * fs_stat[2]
#fs_free = fs_stat[0] * fs_stat[3]
#print("File System Size {:,} - Free Space {:,}".format(fs_size, fs_free))
menuList = ["About", "Snake", "Flappy Bird", "Simon", "Pong", "Music Box", "2048", "LED Fun", "Test All", "Files", "OS", "Reboot", "Sound: On"]
aboutList = ["Gamer Gorl by...", " Mr Wagner", " Sam A", " Katie E", " Adam M", " Jack R", " Mitchel G", " Michael W"]
def runMenu(current):
drawMenu(current)
while True:
APressed, BPressed = gg.getButtons()
gg.randint(0,1000) #keep randomizing
JoyX = gg.getJoyStickX()
if APressed or BPressed or JoyX >800:
doMenuItem(current)
JoyY = gg.getJoyStickY()
if JoyY > 800:
current += 1
if current >= len(menuList):
current = len(menuList)-1
drawMenu(current)
if JoyY < 200:
current -= 1
if current < 0:
current = 0
drawMenu(current)
def drawMenu(current):
gg.display.fill(0)
start = 0
if current > 4:
start = current - 4
for i in range(start, len(menuList)):
if i == current:
s = "> " + menuList[i]
else:
s = " " + menuList[i]
gg.display.text(s, 0, (i-start)*10 + 4)
gg.display.show()
utime.sleep_ms(100)
def drawList(current, myList):
gg.display.fill(0)
start = 0
if current > 4:
start = current - 4
for i in range(start, len(myList)):
gg.display.text(myList[i], 0, (i - start) * 10 + 4)
gg.display.show()
def runList(current, myList):
drawList(current, myList)
utime.sleep_ms(200)
while True:
JoyY = gg.getJoyStickY()
JoyX = gg.getJoyStickX()
if JoyY > 800:
current += 1
if current >= len(myList):
current = len(myList)-1
if JoyY < 200:
current -= 1
if current < 0:
current = 0
APressed, BPressed = gg.getButtons()
if JoyX <200:
break
if APressed or BPressed:
break
else:
drawList(current, myList)
def doMenuItem(current):
#menuList = ["About", "Snake", "Flappy Bird", "Simon", "Breakout", "Music Box", "2048", "LED Fun", "Test All", Files]
if current == 0:
about()
elif current == 1:
import snake
snake.main(gg)
del sys.modules['snake']
gc.collect()
drawMenu(current)
elif current == 2:
import flappy
flappy.main(gg)
del sys.modules['flappy']
gc.collect()
drawMenu(2)
elif current == 3:
import simon
simon.main(gg)
del sys.modules['simon']
gc.collect()
drawMenu(3)
elif current == 4:
import AnimeBreakout
AnimeBreakout.main(gg)
del sys.modules['AnimeBreakout']
gc.collect()
drawMenu(current)
elif current == 5:
import music
music.main(gg)
del sys.modules['music']
gc.collect()
drawMenu(current)
elif current == 6:
import g2048
g2048.main(gg)
del sys.modules['g2048']
gc.collect()
drawMenu(current)
elif current == 7:
testLEDs()
elif current == 8:
testAll()
elif current == 9:
showFiles()
elif current == 10:
showOS()
elif current == 11:
import machine
machine.reset()
elif current == 12:
utime.sleep_ms(200)
if gg.playSound:
menuList[12] = "Sound: Off"
gg.playSound = False
else:
menuList[12] = "Sound: On"
gg.playSound = True
gg.beep()
utime.sleep_ms(25)
gg.lowBeep()
utime.sleep_ms(25)
gg.beep()
utime.sleep_ms(200)
drawMenu(current)
gc.collect()
def dummy():
gg.display.fill(0)
gg.display.text("Dummy", 0, 30)
gg.display.show()
drawMenu(0)
def showFiles():
myList = os.listdir()
runList(0,myList)
drawMenu(9)
def showOS():
import micropython
micropython.mem_info(1)
gg.display.fill(0)
gg.display.text("Free: " + str(gc.mem_free()), 0, 10)
gg.display.text("Alloc: " + str(gc.mem_alloc()), 0, 20)
gg.display.show()
utime.sleep_ms(5000)
micropython.mem_info(1)
gc.collect()
drawMenu(10)
def testLEDs():
gg.display.fill(0)
gg.display.text("LED test", 0, 30)
gg.display.show()
gg.fillLEDs((255,0,255),1,19)
utime.sleep_ms(500)
gg.bounceLEDs((0,255,255),20,4)
gg.cycleLEDs((255,255,0),30,2)
gg.rainbowLEDs(5,5,0.1)
drawMenu(7)
def about():
runList(0, aboutList)
drawMenu(0)
def testAll():
count = 0
keepGoing = True
while keepGoing:
gg.display.fill(0)
JoyX = gg.getJoyStickX()
JoyY = gg.getJoyStickY()
APressed, BPressed = gg.getButtons()
gg.display.text(str(APressed), 0, 0)
if APressed:
gg.beep()
if BPressed:
gg.lowBeep()
gg.display.text(str(BPressed), 0, 10)
gg.display.text(str(JoyX), 0, 20)
gg.display.text(str(JoyY), 0, 30)
print(str(JoyX) + "\t" + str(JoyY))
gg.display.pixel(JoyX//20+50,JoyY//20,1)
gg.display.show()
count = count + 1
if APressed and BPressed:
keepGoing = False
runMenu(0)
if __name__ == '__main__':
#setup the variables
gg = gamerGorl()
gg.display.rotate(True)
gg.showPBM('done.pbm')
gg.rainbowLEDs(25, 4, 0.1)
gg.display.invert(0)
gc.collect()
runMenu(0)