/ Funhouse_Door_Alert / code.py
code.py
1 # SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries 2 # SPDX-FileCopyrightText: Copyright (c) 2021 Melissa LeBlanc-Williams & John Park for Adafruit 3 # 4 # SPDX-License-Identifier: MIT 5 6 import board 7 from digitalio import DigitalInOut, Direction, Pull 8 from adafruit_funhouse import FunHouse 9 from adafruit_debouncer import Debouncer 10 11 12 RED = 0x200000 13 GREEN = 0x002000 14 15 funhouse = FunHouse(default_bg=None) 16 funhouse.peripherals.dotstars.fill(RED) 17 18 switch_pin = DigitalInOut(board.A1) 19 switch_pin.direction = Direction.INPUT 20 switch_pin.pull = Pull.UP 21 switch = Debouncer(switch_pin) 22 23 24 def send_io_data(door_value): 25 funhouse.peripherals.led = True 26 print("Sending data to adafruit IO!") 27 funhouse.network.push_to_io("door", door_value) 28 funhouse.peripherals.led = False 29 30 31 send_io_data(0) 32 33 while True: 34 35 switch.update() 36 if switch.rose: 37 print("Door is open") 38 funhouse.peripherals.play_tone(2000, 0.25) 39 funhouse.peripherals.dotstars.fill(RED) 40 send_io_data(0) 41 42 if switch.fell: 43 print("Door is closed") 44 funhouse.peripherals.play_tone(800, 0.25) 45 funhouse.peripherals.dotstars.fill(GREEN) 46 send_io_data(1)