Formatting
[pi-music.git] / glove.py
1 import pygame
2 import RPi.GPIO as gpio
3
4 gpio.setmode(gpio.BCM)
5 pins = [25, 24, 18, 22]
6
7 guitars = ['sounds/guitar1.wav',
8 'sounds/guitar2.wav',
9 'sounds/guitar3.wav',
10 'sounds/guitar4.wav']
11
12 pygame.mixer.init()
13
14 sounds = {}
15 for pin, wav in zip(pins, guitars):
16 sounds[pin] = pygame.mixer.Sound(wav)
17
18 def handle_sound(pin):
19 if not gpio.input(pin):
20 sounds[pin].play()
21 else:
22 sounds[pin].stop()
23
24 for pin in pins:
25 gpio.setup(pin, gpio.IN)
26 gpio.add_event_detect(pin, gpio.BOTH, callback=handle_sound, bouncetime=200)
27
28 while True:
29 pass