|
| 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) |
0 commit comments