-
Notifications
You must be signed in to change notification settings - Fork 0
/
beetbox.py
executable file
·78 lines (57 loc) · 1.52 KB
/
beetbox.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env python
"""beetbox.py: Trigger script for the BeetBox."""
__author__ = "Scott Garner"
__email__ = "[email protected]"
import pygame
import RPi.GPIO as GPIO
import mpr121
# Use GPIO Interrupt Pin
GPIO.setmode(GPIO.BOARD)
GPIO.setup(7, GPIO.IN)
# Use mpr121 class for everything else
mpr121.TOU_THRESH = 0x30
mpr121.REL_THRESH = 0x33
mpr121.setup(0x5a)
# User pygame for sounds
pygame.mixer.pre_init(44100, -16, 12, 512)
pygame.init()
kick = pygame.mixer.Sound('samples/kick.wav')
kick.set_volume(.65);
snare = pygame.mixer.Sound('samples/snare.wav')
snare.set_volume(.65);
openhh = pygame.mixer.Sound('samples/open.wav')
openhh.set_volume(.65);
closedhh = pygame.mixer.Sound('samples/closed.wav')
closedhh.set_volume(.65);
clap = pygame.mixer.Sound('samples/clap.wav')
clap.set_volume(.65);
cymbal = pygame.mixer.Sound('samples/cymbal.wav')
cymbal.set_volume(.65);
# Track touches
touches = [0,0,0,0,0,0];
while True:
if (GPIO.input(7)): # Interupt pin is high
pass
else: # Interupt pin is low
touchData = mpr121.readData(0x5a)
for i in range(6):
if (touchData & (1<<i)):
if (touches[i] == 0):
print( 'Pin ' + str(i) + ' was just touched')
if (i == 0):
kick.play()
elif (i == 1):
snare.play()
elif (i == 2):
openhh.play()
elif (i == 3):
closedhh.play()
elif (i == 4):
clap.play()
elif (i == 5):
cymbal.play()
touches[i] = 1;
else:
if (touches[i] == 1):
print( 'Pin ' + str(i) + ' was just released')
touches[i] = 0;