Skip to content

Commit d6982a1

Browse files
authored
Merge pull request #1515 from jedgarpark/funhouse-door
switched to use REST
2 parents 82e1f61 + fe7b806 commit d6982a1

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

Funhouse_Door_Alert/code.py

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,47 +6,42 @@
66
import board
77
from digitalio import DigitalInOut, Direction, Pull
88
from adafruit_funhouse import FunHouse
9+
from adafruit_debouncer import Debouncer
910

1011
i2c = board.I2C()
1112

1213
RED = 0x200000
1314
GREEN = 0x002000
1415

1516
funhouse = FunHouse(default_bg=None)
16-
funhouse.peripherals.set_dotstars(RED, RED, RED, RED, RED)
17+
funhouse.peripherals.dotstars.fill(RED)
1718

18-
switch = DigitalInOut(board.A1)
19-
switch.direction = Direction.INPUT
20-
switch.pull = Pull.UP
21-
22-
# Initialize a new MQTT Client object
23-
funhouse.network.init_io_mqtt()
24-
25-
print("Connecting to Adafruit IO...")
26-
funhouse.network.mqtt_connect()
27-
28-
last_door = 1
19+
switch_pin = DigitalInOut(board.A1)
20+
switch_pin.direction = Direction.INPUT
21+
switch_pin.pull = Pull.UP
22+
switch = Debouncer(switch_pin)
2923

3024

3125
def send_io_data(door_value):
3226
funhouse.peripherals.led = True
3327
print("Sending data to adafruit IO!")
34-
funhouse.network.mqtt_publish("door", door_value)
28+
funhouse.network.push_to_io("door", door_value)
3529
funhouse.peripherals.led = False
3630

3731

3832
send_io_data(0)
3933

4034
while True:
4135

42-
if switch.value and last_door is 0:
36+
switch.update()
37+
if switch.rose:
4338
print("Door is open")
4439
funhouse.peripherals.play_tone(2000, 0.25)
4540
funhouse.peripherals.dotstars.fill(RED)
4641
last_door = 1
4742
send_io_data(0)
4843

49-
elif not switch.value and last_door is 1:
44+
if switch.fell:
5045
print("Door is closed")
5146
funhouse.peripherals.play_tone(800, 0.25)
5247
funhouse.peripherals.dotstars.fill(GREEN)

0 commit comments

Comments
 (0)