Skip to content

Commit e2d1080

Browse files
committed
add SD card test and fix middlebutton press
1 parent db39bab commit e2d1080

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

code.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
1+
import adafruit_sdcard
2+
import storage
13
from pyoa_graphics import PYOA_Graphics
4+
import board
5+
import digitalio
26

3-
7+
try:
8+
sdcard = adafruit_sdcard.SDCard(board.SPI(), digitalio.DigitalInOut(board.SD_CS))
9+
vfs = storage.VfsFat(sdcard)
10+
storage.mount(vfs, "/sd")
11+
print("SD card found") # no biggie
12+
except OSError:
13+
print("No SD card found") # no biggie
414

515
gfx = PYOA_Graphics()
616

7-
gfx.load_game("/Adafruit_CircuitPython_PYOA/robots")
8-
current_card = 2 # start with first card
17+
gfx.load_game("/sd/robots")
18+
current_card = 0 # start with first card
919

1020
while True:
1121
print("Current card:", current_card)

pyoa_graphics.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,18 @@ def display_card(self, card_num):
132132
p = self.ts.touch_point
133133
if p:
134134
print("touch: ", p)
135-
if self._left_button.contains(p):
136-
print("Left button")
137-
goto_page = card.get('button01_goto_page_id', None)
138-
if self._right_button.contains(p):
139-
print("Right button")
140-
goto_page = card.get('button02_goto_page_id', None)
135+
if button01_text and not button02_text:
136+
# showing only middle button
137+
if self._middle_button.contains(p):
138+
print("Middle button")
139+
goto_page = card.get('button01_goto_page_id', None)
140+
if button01_text and button02_text:
141+
if self._left_button.contains(p):
142+
print("Left button")
143+
goto_page = card.get('button01_goto_page_id', None)
144+
if self._right_button.contains(p):
145+
print("Right button")
146+
goto_page = card.get('button02_goto_page_id', None)
141147
self.play_sound(None) # stop playing any sounds
142148
for i, c in enumerate(self._game):
143149
if c.get('page_id', None) == goto_page:

0 commit comments

Comments
 (0)