2 import RPi
.GPIO
as gpio
5 if gpio
.RPI_REVISION
== 1:
6 pins
= [22, 21, 17, 4, 25, 24, 23, 18]
8 pins
= [22, 27, 17, 4, 25, 24, 23, 18]
10 notes
= ['sounds/keyboard-g.wav',
11 'sounds/keyboard-a.wav',
12 'sounds/keyboard-b.wav',
13 'sounds/keyboard-c.wav',
14 'sounds/keyboard-d.wav',
15 'sounds/keyboard-e.wav',
16 'sounds/keyboard-f.wav',
17 'sounds/keyboard-g-high.wav']
22 for pin
, wav
in zip(pins
, notes
):
23 sounds
[pin
] = pygame
.mixer
.Sound(wav
)
25 def handle_sound(pin
):
32 gpio
.setup(pin
, gpio
.IN
)
33 gpio
.add_event_detect(pin
, gpio
.BOTH
, callback
=handle_sound
,