Skip to content

Commit cfc9f8c

Browse files
author
Mikey Sklar
committed
talking clock - python3, circuitpython and linted
1 parent 8295a68 commit cfc9f8c

2 files changed

Lines changed: 12 additions & 16 deletions

File tree

Speech_Synthesis_on_the_Raspberry_Pi/speaking_temperature.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
tempF = tempC * 9 / 5 + 32
1515
print('Temperature: {} C {} F '.format(tempC, tempF))
1616

17-
# round temperature and convert to string for speech
17+
# drop decimal points and convert to string for speech
1818
tempC = str(int(tempC))
1919
tempF = str(int(tempF))
2020
os.system("echo 'The temperature is " + tempF + " degrees' | festival --tts")
Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
11
import time
2-
import RPi.GPIO as GPIO
32
import os
3+
import board
4+
import digitalio
45

5-
GPIO.setmode(GPIO.BCM)
6-
GPIO.setup(17,GPIO.IN)
6+
button = digitalio.DigitalInOut(board.D18)
7+
button.direction = digitalio.Direction.INPUT
8+
button.pull = digitalio.Pull.UP
79

8-
#initialise a previous input variable to 0 (assume button not pressed last)
9-
prev_input = 0
1010
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)
11+
12+
if not button.value:
13+
os.system("date '+%I:%M %P' | festival --tts")
14+
15+
# slight pause to debounce
16+
time.sleep(0.2)

0 commit comments

Comments
 (0)