Last active
January 16, 2025 15:42
-
-
Save stonehippo/5084196e26c9ff644614c4dc68c8e7a2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 asyncio | |
import time | |
import board | |
import neopixel | |
from rainbowio import colorwheel | |
import adafruit_lsm303_accel | |
import adafruit_lis2mdl | |
PIXEL_PIN = board.GP0 | |
PIXEL_NUM = 12 | |
pixels = neopixel.NeoPixel(PIXEL_PIN, PIXEL_NUM, bpp=4, brightness=0.2) | |
palette = tuple(colorwheel(pos * 20) for pos in range(0, PIXEL_NUM)) | |
i2c = board.STEMMA_I2C() | |
accel = adafruit_lsm303_accel.LSM303_Accel(i2c) | |
mag = adafruit_lis2mdl.LIS2MDL(i2c) | |
def rotate_wheel(step): | |
return palette[step:] + palette[:step] | |
while True: | |
for i in range(0,12): | |
pixels[:] = rotate_wheel(i) | |
time.sleep(0.075) | |
This file contains hidden or 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
from micropython import const | |
import time | |
import asyncio | |
import board | |
import neopixel | |
from rainbowio import colorwheel | |
import adafruit_bme680 | |
import adafruit_veml7700 | |
_PIXEL_PIN = board.D6 | |
_PIXEL_NUM = const(64) | |
_ANIMATION_RATE = const(0.01) | |
i2c = board.I2C() | |
veml = adafruit_veml7700.VEML7700(i2c) | |
bme = adafruit_bme680.Adafruit_BME680_I2C(i2c) | |
pixels = neopixel.NeoPixel(_PIXEL_PIN, _PIXEL_NUM, brightness=0.4, auto_write=False) | |
pixels.fill(0) | |
pixels.write() | |
# create a palette of color that matches the size of the NeoPixel array. | |
# Using a tuple, since I won't ever modify the palette in place. | |
rainbow = tuple(colorwheel(c * 4) for c in range(0,_PIXEL_NUM)) | |
# helper to rotate the colors in the palette by slicing the tuple | |
def rotate_rainbow(n): | |
return rainbow[n:] + rainbow[:n] | |
def animate(rate): | |
for cel in range(0, _PIXEL_NUM): | |
# Clever way to adding all of the pixels at once | |
pixels[:] = rotate_rainbow(cel) | |
pixels.show() | |
time.sleep(rate) | |
while True: | |
animate(_ANIMATION_RATE) | |
print(int(veml.lux)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment