-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathshutdown-melting.py
More file actions
36 lines (30 loc) · 798 Bytes
/
Copy pathshutdown-melting.py
File metadata and controls
36 lines (30 loc) · 798 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
32
33
34
35
36
#!/usr/bin/env python3
from gpiozero import Button
from signal import pause
import pygame.mixer
from pygame.mixer import Sound
import time, os
holdTime = 10
offGPIO = 21
pygame.mixer.init()
melting = Sound("ImMeltingMelting.ogg")
nohome = Sound("NoPlaceLikeHome.ogg")
def shutdown():
# stop playing one sound and switch to another
melting.stop()
nohome.play()
# give it a chance to play
time.sleep(1)
# and shutdown for real
os.system("sudo poweroff")
def when_pressed():
# start playing
melting.play(loops=holdTime/melting.get_length())
def when_released():
# stop playing if released early
melting.stop()
btn = Button(offGPIO, hold_time=holdTime)
btn.when_held = shutdown
btn.when_pressed = when_pressed
btn.when_released = when_released
pause()