-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
34 lines (26 loc) · 832 Bytes
/
Copy pathapp.py
File metadata and controls
34 lines (26 loc) · 832 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
import RPi.GPIO as g
import time
import wikiquote
import random
import subprocess
# Get the list of all quotes from Wikiquote
quotes = wikiquote.quotes("Richard Stallman")
# The button is plugged in on GPIO port 21
# One wire at 21, one at GND
g.setmode(g.BCM)
g.setup(21, g.IN, pull_up_down = g.PUD_UP)
try:
while True:
# Poll state of button
button_state = g.input(21)
# Button has been pressed
if button_state == False:
# Choose a random quote
quote = random.choice(quotes)
# Speak the word of the lord
subprocess.Popen(["espeak", "-v", "en-scottish", quote])
# Wait for a second
time.sleep(1)
except:
# Something unexpected happened; clean up after ourselves
g.cleanup()