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
 4import board
 5import busio
 6from digitalio import DigitalInOut
 7from adafruit_esp32spi import adafruit_esp32spi
 8from adafruit_esp32spi import adafruit_esp32spi_wifimanager
 9import neopixel
10
11import adafruit_lifx
12
13# Get wifi details and more from a secrets.py file
14try:
15    from secrets import secrets
16except ImportError:
17    print("WiFi and API secrets are kept in secrets.py, please add them there!")
18    raise
19
20# ESP32 SPI
21esp32_cs = DigitalInOut(board.ESP_CS)
22esp32_ready = DigitalInOut(board.ESP_BUSY)
23esp32_reset = DigitalInOut(board.ESP_RESET)
24spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
25esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)
26status_light = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2)
27wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light)
28
29# Add your LIFX Personal Access token to secrets.py
30# (to obtain a token, visit: https://cloud.lifx.com/settings)
31lifx_token = secrets["lifx_token"]
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)