forked from adafruit/Adafruit_CircuitPython_Wiz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwiz_buttons_controller.py
83 lines (67 loc) · 2.33 KB
/
wiz_buttons_controller.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# SPDX-FileCopyrightText: Copyright (c) 2024 Tim Cocks for Adafruit Industries
#
# SPDX-License-Identifier: MIT
"""
Basic demonstration of Wiz light control using 4 push buttons each
wired to their own pin.
"""
import time
import board
import wifi
from digitalio import DigitalInOut, Direction, Pull
from adafruit_wiz import SCENE_IDS, WizConnectedLight
udp_host = "192.168.1.143" # IP of UDP Wiz connected light
udp_port = 38899 # Default port is 38899, change if your light is configured differently
my_lamp = WizConnectedLight(udp_host, udp_port, wifi.radio, debug=True)
# Basic push buttons initialization
btn_1 = DigitalInOut(board.D11)
btn_1.direction = Direction.INPUT
btn_1.pull = Pull.UP
btn_2 = DigitalInOut(board.D12)
btn_2.direction = Direction.INPUT
btn_2.pull = Pull.UP
btn_3 = DigitalInOut(board.A1)
btn_3.direction = Direction.INPUT
btn_3.pull = Pull.UP
btn_4 = DigitalInOut(board.A0)
btn_4.direction = Direction.INPUT
btn_4.pull = Pull.UP
# list of colors to cycle through
colors = [(255, 0, 0), (0, 255, 0), (0, 0, 255), (255, 255, 0), (0, 255, 255), (255, 0, 255)]
# current index in the color cycle
cur_rgb_index = 0
# list of temperatures to cycle through
temperatures = [2200, 2800, 3600, 4800, 6200]
# current index in the temperature cycle
cur_temp_index = 0
while True:
# if btn 1 pressed
if not btn_1.value:
print("Button 1")
# toggle the on/off state
my_lamp.state = not my_lamp.state
time.sleep(0.5)
# if btn 2 pressed
if not btn_2.value:
print("Button 2")
# set the current RGB color
my_lamp.rgb_color = colors[cur_rgb_index]
# increment the index for next time and wrap around to zero as needed
cur_rgb_index = (cur_rgb_index + 1) % len(colors)
time.sleep(0.5)
# if btn 3 pressed
if not btn_3.value:
print("Button 3")
# set the current light color temperature
my_lamp.temperature = temperatures[cur_temp_index]
# increment the index for next time and wrap around to zero as needed
cur_temp_index = (cur_temp_index + 1) % len(temperatures)
time.sleep(0.5)
# if btn 4 pressed
if not btn_4.value:
print("Button 4")
# uncomment to see the available scenes
# print(SCENE_IDS.keys())
# set the scene
my_lamp.scene = "Party"
time.sleep(0.5)