Skip to content

Commit

Permalink
Merge pull request #2 from FoamyGuy/new_examples
Browse files Browse the repository at this point in the history
new examples, update products, specify built-in wifi
  • Loading branch information
FoamyGuy authored Dec 19, 2024
2 parents 057f5fd + 04d4a0b commit 844de23
Show file tree
Hide file tree
Showing 4 changed files with 164 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ or individual libraries can be installed using



Works with any CircuitPython device that supports WIFI or Ethernet networking.
Works with any CircuitPython device has built-in WIFI.

`Purchase one from the Adafruit shop <http://www.adafruit.com/products/>`_

Expand Down
11 changes: 9 additions & 2 deletions adafruit_wiz.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,15 @@
**Hardware:**
Any CircuitPython device that supports WIFI or Ethernet networking.
CircuitPython devices with built-in WIFI
* `Adafruit Feather ESP32-S2 <https://www.adafruit.com/product/5000>`_
* `Adafruit Feather ESP32-S3 <https://www.adafruit.com/product/5477>`_
* `Adafruit Feather ESP32-C6 <https://www.adafruit.com/product/5933>`_
* `Raspberry Pi Pico W <https://www.adafruit.com/product/5526>`_
* `Raspberry Pi Pico 2W <https://www.adafruit.com/product/6087>`_
* `Adafruit Feather ESP32-S2 TFT <https://www.adafruit.com/product/5300>`_
* `Adafruit Feather ESP32-S3 TFT <https://www.adafruit.com/product/5483>`_
**Software and Dependencies:**
Expand Down Expand Up @@ -126,7 +134,6 @@ class WizConnectedLight:
:param str ip: IP address of the Wiz connected light. Can be found in the smartphone app.
:param int port: UDP port the Wiz connected light listens on. Default is 38899
:param radio: WIFI radio object. It will attempt to use ``wifi.radio`` if not passed.
Pass Radio objects for ESP32SPI or Wiznet ethernet networking to use them.
:param bool debug: Enable additional debugging output.
"""

Expand Down
83 changes: 83 additions & 0 deletions examples/wiz_buttons_controller.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,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)
71 changes: 71 additions & 0 deletions examples/wiz_neokey1x4_controller.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# SPDX-FileCopyrightText: Copyright (c) 2024 Tim Cocks for Adafruit Industries
#
# SPDX-License-Identifier: MIT
"""
Demonstration of Wiz light control using a Neokey 1x4 QT I2C
https://www.adafruit.com/product/4980
"""

import json
import time

import board
import wifi
from adafruit_neokey.neokey1x4 import NeoKey1x4

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)

# use default I2C bus
i2c_bus = board.STEMMA_I2C()

# Create a NeoKey object
neokey = NeoKey1x4(i2c_bus, addr=0x30)

# 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 A pressed
if neokey[0]:
print("Button A")
# toggle the on/off state
my_lamp.state = not my_lamp.state
time.sleep(0.5)

# if btn B pressed
if neokey[1]:
print("Button B")
# 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 C pressed
if neokey[2]:
print("Button C")
# 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 D pressed
if neokey[3]:
print("Button D")
# uncomment to see the available scenes
# print(SCENE_IDS.keys())

# set the scene
my_lamp.scene = "Party"

0 comments on commit 844de23

Please sign in to comment.