From 5e6cafeec1a742dffbdc99dca2777dde70324e47 Mon Sep 17 00:00:00 2001 From: Mike Barela Date: Fri, 14 Dec 2018 09:21:59 -0500 Subject: [PATCH 1/2] update for general numbers and fahrenheit Added fahrenheit to button b, added numbers for -299 to 299 (way more than an atmospheric thermometer). The wav files have been added to go into the thousands and millions although the read_temp function is limited to 299. --- Make_It_Talk/say-temp.py | 61 ++++++++++++++++++++++------------------ 1 file changed, 34 insertions(+), 27 deletions(-) diff --git a/Make_It_Talk/say-temp.py b/Make_It_Talk/say-temp.py index 115e2fa0..7988835b 100644 --- a/Make_It_Talk/say-temp.py +++ b/Make_It_Talk/say-temp.py @@ -1,5 +1,8 @@ # CircuitPython Speaking Thermometer Example -# Mike Barela +# Coded for Circuit Playground Express but it may be +# modified for any CircuitPython board with changes to +# button, thermister and audio board definitions. +# Mike Barela for Adafruit Industries, MIT License import time import board @@ -8,11 +11,16 @@ import audioio from digitalio import DigitalInOut, Direction, Pull D1 = board.BUTTON_A +D2 = board.BUTTON_B -# Button A setup +# Button A setup (Celcius) button_a = DigitalInOut(D1) button_a.direction = Direction.INPUT button_a.pull = Pull.DOWN +# Button B setup (Fahrenheit) +button_b = DigitalInOut(D2) +button_b.direction = Direction.INPUT +button_b.pull = Pull.DOWN # Set up reading the Circuit Playground Express thermistor thermistor = adafruit_thermistor.Thermistor( @@ -21,7 +29,7 @@ thermistor = adafruit_thermistor.Thermistor( # Audio playback object and helper to play a full file aout = audioio.AudioOut(board.A0) -# Play a wave file +# Play a wave file def play_file(wavfile): wavfile = "/numbers/" + wavfile print("Playing", wavfile) @@ -31,33 +39,32 @@ def play_file(wavfile): while aout.playing: pass -def read_temperature(temp): +# Function should take an integer -299 to 299 and say it +# Assumes wav files are available for the numbers +def read_temp(temp): play_file("temperature.wav") - if temp > 0 and temp < 20: - filename = str(temp) + ".wav" - play_file(filename) - if temp == 20: - play_file("20.wav") - if temp > 20 and temp < 30: - play_file("20.wav") - filename = str(temp - 20) + ".wav" - play_file(filename) - if temp == 30: - play_file("30.wav") - if temp > 30 and temp < 40: - play_file("30.wav") - filename = str(temp - 30) + ".wav" - play_file(filename) - if temp == 40: - play_file("40.wav") - if temp > 40 and temp < 50: - play_file("40.wav") - filename = str(temp - 40) + ".wav" - play_file(filename) + if temp < 0: + play_file("negative.wav") + temp = - temp + if temp >= 200: + play_file("200.wav") + temp = temp - 200 + elif temp >= 100: + play_file("100.wav") + temp = temp - 100 + if (temp >= 0 and temp < 20) or temp % 10 == 0: + play_file(str(temp) + ".wav") + else: + play_file(str(temp // 10) + "0.wav") + temp = temp - ((temp // 10) * 10 ) + play_file(str(temp) + ".wav") play_file("degrees.wav") - play_file("celsius.wav") while True: if button_a.value: - read_temperature(int(thermistor.temperature)) + read_temp(int(thermistor.temperature)) + play_file("celsius.wav") + if button_b.value: + read_temp(int(thermistor.temperature * 9 / 5 + 32)) + play_file("fahrenheit.wav") time.sleep(0.01) From d335592fb31415da6e578d58d45b41ec41c9f7b6 Mon Sep 17 00:00:00 2001 From: Mike Barela Date: Fri, 14 Dec 2018 09:28:05 -0500 Subject: [PATCH 2/2] whitespace and a sp change travis whitespace fix and fix one spelling --- Make_It_Talk/say-temp.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Make_It_Talk/say-temp.py b/Make_It_Talk/say-temp.py index 7988835b..74356e3d 100644 --- a/Make_It_Talk/say-temp.py +++ b/Make_It_Talk/say-temp.py @@ -13,7 +13,7 @@ from digitalio import DigitalInOut, Direction, Pull D1 = board.BUTTON_A D2 = board.BUTTON_B -# Button A setup (Celcius) +# Button A setup (Celsius) button_a = DigitalInOut(D1) button_a.direction = Direction.INPUT button_a.pull = Pull.DOWN @@ -29,7 +29,7 @@ thermistor = adafruit_thermistor.Thermistor( # Audio playback object and helper to play a full file aout = audioio.AudioOut(board.A0) -# Play a wave file +# Play a wave file def play_file(wavfile): wavfile = "/numbers/" + wavfile print("Playing", wavfile)