Skip to content

Commit 0b69b5d

Browse files
author
Mikey Sklar
committed
playing_sounds_using_buttons.py python3, circuitpython, linted
1 parent 8004b39 commit 0b69b5d

4 files changed

Lines changed: 62 additions & 0 deletions

File tree

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Speech_Synthesis_on_the_Raspberry_Pi
2+
3+
Code to accompany this tutorial:
4+
https://learn.adafruit.com/speech-synthesis-on-the-raspberry-pi
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import time
2+
import os
3+
import board
4+
import digitalio
5+
6+
button1 = digitalio.DigitalInOut(board.D23)
7+
button1.direction = digitalio.Direction.INPUT
8+
button1.pull = digitalio.Pull.UP
9+
10+
button2 = digitalio.DigitalInOut(board.D24)
11+
button2.direction = digitalio.Direction.INPUT
12+
button2.pull = digitalio.Pull.UP
13+
14+
button3 = digitalio.DigitalInOut(board.D25)
15+
button3.direction = digitalio.Direction.INPUT
16+
button3.pull = digitalio.Pull.UP
17+
18+
print("press a button!")
19+
20+
while True:
21+
if not button1.value:
22+
os.system('echo "Use the force Luke!" | festival --tts')
23+
24+
if not button2.value:
25+
os.system('echo "Some rescue!" | festival --tts')
26+
27+
if not button3.value:
28+
os.system('echo "I find your lack of faith disturbing." | festival --tts')
29+
30+
time.sleep(0.1)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import os
2+
3+
# Loop reading measurements every minute.
4+
print 'Press Ctrl-C to quit.'
5+
while True:
6+
temp = sensor.readTempC()
7+
os.system("flite -t 'The temperature is " + temp + " degrees'" &)
8+
time.sleep(60.0)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import time
2+
import RPi.GPIO as GPIO
3+
import os
4+
5+
GPIO.setmode(GPIO.BCM)
6+
GPIO.setup(17,GPIO.IN)
7+
8+
#initialise a previous input variable to 0 (assume button not pressed last)
9+
prev_input = 0
10+
while True:
11+
#take a reading
12+
input = GPIO.input(17)
13+
#if the last reading was low and this one high, print
14+
if ((not prev_input) and input):
15+
print("Button pressed")
16+
os.system("date '+%I:%M %P' | flite")
17+
#update previous input
18+
prev_input = input
19+
#slight pause to debounce
20+
time.sleep(0.05)

0 commit comments

Comments
 (0)