Created
August 18, 2023 10:29
-
-
Save ammoniak/793960e6442261e66632509f2a5ce3a5 to your computer and use it in GitHub Desktop.
Micropython led rainbow - ntp synched
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import machine | |
import neopixel | |
import network | |
import ntptime | |
import random | |
import time | |
import webrepl | |
import colorsys | |
############################ | |
WIFI_ESSID = "Camp2023-open" | |
WIFI_PASSWORD = "" | |
OFFSET = 0 | |
LOCAL_PIXELS = 100 | |
TOTAL_PIXELS = 148 | |
############################ | |
pixels = machine.Pin(22, machine.Pin.OUT) | |
button = machine.Pin(0, machine.Pin.IN, machine.Pin.PULL_UP) | |
# Fetch current time via WiFi | |
print("Connecting to ", WIFI_ESSID) | |
wifi = network.WLAN(network.STA_IF) | |
if not wifi.isconnected(): | |
wifi.active(True) | |
wifi.connect(WIFI_ESSID, WIFI_PASSWORD) | |
while not wifi.isconnected(): | |
time.sleep_ms(100) | |
print(wifi.ifconfig()) | |
print("Fetching NTP time") | |
ntptime.settime() | |
print("Starting WebREPL") | |
webrepl.start(password="1d03sn0t") | |
print("Looping LED pattern") | |
np = neopixel.NeoPixel(pixels, LOCAL_PIXELS) | |
exit = False | |
while not exit: | |
sat = 1 | |
val = 0.25 | |
seed = int(time.time()) + OFFSET | |
for p in range(0, LOCAL_PIXELS): | |
hue = (seed + p) % TOTAL_PIXELS | |
np[p] = colorsys.hsv_to_rgb((hue / TOTAL_PIXELS, sat, val)) | |
np.write() | |
if not button.value(): | |
exit = True | |
break | |
time.sleep(1) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment