-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbutton.py
More file actions
31 lines (27 loc) · 690 Bytes
/
button.py
File metadata and controls
31 lines (27 loc) · 690 Bytes
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
import RPi.GPIO as GPIO
import time
import threading
from pygame import mixer
mixer.init()
GPIO.setmode(GPIO.BCM)
INPUT = 24
GPIO.setwarnings(False)
GPIO.setup([INPUT], GPIO.IN , pull_up_down=GPIO.PUD_DOWN)
isFirstPress = True
def music_thread():
mixer.music.load('./audio/Moose-Sound.wav')
mixer.music.play()
def handle(pin):
global isFirstPress
if isFirstPress == True:
t = threading.Thread(target=music_thread)
t.daemon = True
t.start()
print("starting playback")
isFirstPress = False
time.sleep(3)
else:
isFirstPress = True
GPIO.add_event_detect(INPUT, GPIO.RISING, handle)
while True:
time.sleep(1e6)