Initial commit
[pi-music.git] / glove.py
1 import pygame
2 import RPi.GPIO as gpio
3 import time
4 import logging
5
6 logger = logging.getLogger(__name__)
7 loggerFileHandler = logging.FileHandler('glove.log')
8 loggerFileHandlerFormatter = logging.Formatter('%(asctime)s %(levelname)-8s %(message)s')
9 loggerFileHandler.setFormatter(loggerFileHandlerFormatter)
10 logger.addHandler(loggerFileHandler)
11 logger.setLevel(logging.WARNING)
12 logger.setLevel(logging.INFO)
13
14
15 guitars = ['sounds/guitar1.wav',
16 'sounds/guitar2.wav',
17 'sounds/guitar3.wav',
18 'sounds/guitar4.wav',
19 'sounds/guitar5.wav']
20
21 pygame.mixer.init()
22 sounds = [pygame.mixer.Sound(g) for g in guitars]
23 #for s in sounds:
24 # s.play()
25 # time.sleep(0.5)
26
27 #time.sleep(2)
28
29 gpio.setmode(gpio.BCM)
30 gpio.setup(25, gpio.IN)
31
32 last_switch = gpio.LOW
33
34 while True:
35 this_switch = gpio.input(25)
36 logger.debug("This: {0}, Last: {1}".format(this_switch, last_switch))
37 if this_switch and not last_switch:
38 sounds[0].play()
39 last_switch = this_switch
40 logger.info("Started playing")
41 if not this_switch and last_switch:
42 sounds[0].stop()
43 last_switch = this_switch
44 logger.info("Stopped playing")