Skip to content

Commit

Permalink
Merge pull request #3 from FoamyGuy/use_keypad_in_btn_example
Browse files Browse the repository at this point in the history
use keypad in button remote example
  • Loading branch information
dhalbert authored Dec 22, 2024
2 parents 844de23 + 7ec7a87 commit 4488669
Showing 1 changed file with 34 additions and 53 deletions.
87 changes: 34 additions & 53 deletions examples/wiz_buttons_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@
wired to their own pin.
"""

import time

import board
import keypad
import wifi
from digitalio import DigitalInOut, Direction, Pull

from adafruit_wiz import SCENE_IDS, WizConnectedLight

Expand All @@ -19,22 +17,10 @@

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
# Basic push buttons initialization with keypad
buttons = keypad.Keys(
(board.D11, board.D12, board.A1, board.A0), value_when_pressed=False, pull=True
)

# 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)]
Expand All @@ -47,37 +33,32 @@
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)
# check for button press events
event = buttons.events.get()
if event and event.pressed:
if event.key_number == 0:
print("Button 0")
# toggle the on/off state
my_lamp.state = not my_lamp.state

elif event.key_number == 1:
print("Button 1")
# 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)

elif event.key_number == 2:
print("Button 2")
# 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)

elif event.key_number == 3:
print("Button 3")
# uncomment to see the available scenes
# print(SCENE_IDS.keys())

# set the scene
my_lamp.scene = "Party"

0 comments on commit 4488669

Please sign in to comment.