code.py
1 # SPDX-FileCopyrightText: 2021 Brent Rubell for Adafruit Industries 2 # 3 # SPDX-License-Identifier: MIT 4 5 """ 6 'temperature_alarm.py'. 7 8 ================================================= 9 sounds an alarm when the temperature crosses a threshold 10 requires: 11 - simpleio 12 """ 13 14 import time 15 import analogio 16 import board 17 from simpleio import map_range, tone 18 19 tmp_36 = analogio.AnalogIn(board.A0) 20 21 freeze_temp = 0 22 boil_temp = 100 23 24 while True: 25 temp = map_range(tmp_36.value, 0, 65535, 0, 5) 26 # temp to degrees C 27 temp = (temp - 0.5) * 100 28 print(temp) 29 30 if temp < freeze_temp: 31 tone(board.D8, 349, 4) 32 if temp > boil_temp: 33 tone(board.D8, 523, 4) 34 time.sleep(0.5)