-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstormbrella.py
50 lines (35 loc) · 955 Bytes
/
stormbrella.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
#!/usr/bin/python
import RPi.GPIO as GPIO
import pygame
import time
import threading
import signal
import sys
#
# thunderStorm()
#
# Will play thunderstorm audio while flashing neopixels in pattern to look like lightning
#
def thunderStorm():
global pygame
pygame.mixer.music.set_volume(1.0)
pygame.mixer.music.play()
while pygame.mixer.music.get_busy() == True:
time.sleep(2)
continue
BUTTON = 23
TRIGGER = 24
GPIO.setwarnings(False) # we don't want to see any warnings
GPIO.setmode(GPIO.BCM) # set how the numbers of the pins are interpreted (system or bcm)
GPIO.setup(TRIGGER, GPIO.OUT)
GPIO.setup(BUTTON, GPIO.IN, pull_up_down=GPIO.PUD_UP)
# set up our audio generator
pygame.mixer.init()
pygame.mixer.music.load("/home/pi/stormbrella/thunderstorm.wav")
pygame.mixer.music.set_volume(0.0)
while (True):
if (GPIO.input(BUTTON)==0):
GPIO.output(TRIGGER, True)
time.sleep(0.1)
GPIO.output(TRIGGER, False)
thunderStorm()