Simple test
Ensure your device works with this simple test.
examples/lifx_simpletest.py
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2# SPDX-License-Identifier: MIT
3
4from os import getenv
5
6import board
7import busio
8import neopixel
9from adafruit_esp32spi import adafruit_esp32spi
10from adafruit_esp32spi.adafruit_esp32spi_wifimanager import WiFiManager
11from digitalio import DigitalInOut
12
13import adafruit_lifx
14
15# Get WiFi details and LIFX keys, ensure these are setup in settings.toml
16# (to obtain a token, visit: https://cloud.lifx.com/settings)
17ssid = getenv("CIRCUITPY_WIFI_SSID")
18password = getenv("CIRCUITPY_WIFI_PASSWORD")
19lifx_token = getenv("lifx_token")
20
21# ESP32 SPI
22esp32_cs = DigitalInOut(board.ESP_CS)
23esp32_ready = DigitalInOut(board.ESP_BUSY)
24esp32_reset = DigitalInOut(board.ESP_RESET)
25spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
26esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)
27status_pixel = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2)
28wifi = WiFiManager(esp, ssid, password, status_pixel=status_pixel)
29
30if lifx_token is None:
31 raise KeyError("Please add your lifx token to settings.toml")
32
33# Set this to your LIFX light separator label
34# https://api.developer.lifx.com/docs/selectors
35lifx_light = "label:Lamp"
36
37# Initialize the LIFX API Client
38lifx = adafruit_lifx.LIFX(wifi, lifx_token)
39
40# List all lights
41lights = lifx.list_lights()
42
43# Turn on the light
44print("Turning on light...")
45lifx.toggle_light(lifx_light)
46
47# Set the light's brightness to 50%
48light_brightness = 0.5
49lifx.set_brightness(lifx_light, light_brightness)
50
51# Cycle the light using the colors of the Python logo
52colors = ["yellow", "blue", "white"]
53for color in colors:
54 print("Setting light to: ", color)
55 lifx.set_color(lifx_light, power="on", color=color, brightness=light_brightness)
56
57# Turn off the light
58print("Turning off light...")
59lifx.toggle_light(lifx_light)