Skip to content

Commit 1e310a9

Browse files
authored
Merge pull request adafruit#1138 from adafruit/pyportalGuitarTuner
Adding code and files for PyPortal Guitar Tuner
2 parents 0c3ef8c + 836de16 commit 1e310a9

File tree

9 files changed

+72
-0
lines changed

9 files changed

+72
-0
lines changed

PyPortal_Guitar_Tuner/code.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import time
2+
import board
3+
import displayio
4+
import adafruit_imageload
5+
from adafruit_button import Button
6+
from adafruit_pyportal import PyPortal
7+
8+
display = board.DISPLAY
9+
10+
pyportal = PyPortal()
11+
12+
bitmap, palette = adafruit_imageload.load("/stock-pyportal.bmp",
13+
bitmap=displayio.Bitmap,
14+
palette=displayio.Palette)
15+
16+
# Create a TileGrid to hold the bitmap
17+
tile_grid = displayio.TileGrid(bitmap, pixel_shader=palette)
18+
19+
lowE = "/sounds/lowE.wav"
20+
A = "/sounds/A.wav"
21+
D = "/sounds/D.wav"
22+
G = "/sounds/G.wav"
23+
B = "/sounds/B.wav"
24+
highE = "/sounds/highE.wav"
25+
26+
notes = [lowE, A, D, G, B, highE]
27+
28+
pegs = [
29+
{'label': "lowE", 'pos': (53, 0), 'size': (65, 90)},
30+
{'label': "A", 'pos': (124, 0), 'size': (65, 90)},
31+
{'label': "D", 'pos': (194, 0), 'size': (65, 90)},
32+
{'label': "G", 'pos': (194, 150), 'size': (65, 90)},
33+
{'label': "B", 'pos': (124, 150), 'size': (65, 90)},
34+
{'label': "highE", 'pos': (53, 150), 'size': (65, 90)}
35+
]
36+
37+
pyportal.splash.append(tile_grid)
38+
39+
buttons = []
40+
for peg in pegs:
41+
button = Button(x=peg['pos'][0], y=peg['pos'][1],
42+
width=peg['size'][0], height=peg['size'][1],
43+
style=Button.RECT,
44+
fill_color=None, outline_color=0x5C3C15,
45+
name=peg['label'])
46+
pyportal.splash.append(button.group)
47+
buttons.append(button)
48+
49+
note_select = None
50+
51+
while True:
52+
touch = pyportal.touchscreen.touch_point
53+
if not touch and note_select:
54+
note_select = False
55+
if touch:
56+
for i in range(6):
57+
tuning = notes[i]
58+
button = buttons[i]
59+
if button.contains(touch) and not note_select:
60+
print("Touched", button.name)
61+
note_select = True
62+
for z in range(3):
63+
pyportal.play_file(tuning)
64+
time.sleep(0.1)

PyPortal_Guitar_Tuner/secrets.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
secrets = {
2+
'ssid' : 'your-ssid-here',
3+
'password' : 'your-password-here',
4+
'openweather_token' : 'your-openweather-token-here',
5+
'aio_username' : "your-aio-username-here",
6+
'aio_key' : 'your-aio-key-here',
7+
'location' : 'New York, US'
8+
}

PyPortal_Guitar_Tuner/sounds/A.wav

272 KB
Binary file not shown.

PyPortal_Guitar_Tuner/sounds/B.wav

258 KB
Binary file not shown.

PyPortal_Guitar_Tuner/sounds/D.wav

258 KB
Binary file not shown.

PyPortal_Guitar_Tuner/sounds/G.wav

258 KB
Binary file not shown.
258 KB
Binary file not shown.

PyPortal_Guitar_Tuner/sounds/lowE.wav

258 KB
Binary file not shown.
75.3 KB
Binary file not shown.

0 commit comments

Comments
 (0)