Merge pull request #439 from adafruit/TheKitty-patch-42

update for general numbers and fahrenheit
This commit is contained in:
Mike Barela 2018-12-14 09:35:04 -05:00 committed by GitHub
commit 9f65f3c6b0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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 (Celsius)
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(
@ -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)