Created
February 29, 2024 18:03
-
-
Save RobCranfill/638cd6ce62f57eb5715e96dfc1bba98a to your computer and use it in GitHub Desktop.
My standard "Hello, world" for a micro-controller with a NeoPixel on it.
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
# Based on code from Adafruit Industries | |
# SPDX-License-Identifier: MIT | |
"""Rob's CircuitPython blink example for built-in NeoPixel LED""" | |
import time | |
import board | |
import neopixel | |
import random | |
k = 20 # number of steps up or down | |
def fade_in_and_out(pix, r, g, b): | |
"""Fade up from black to the indicated color, then down again, in 1 second.""" | |
for i in range(k): | |
pix.fill((i*r/k, i*g/k, i*b/k)) | |
time.sleep(.5/k) | |
for i in range(k, 0, -1): | |
pix.fill((i*r/k, i*g/k, i*b/k)) | |
time.sleep(.5/k) | |
pixel = neopixel.NeoPixel(board.NEOPIXEL, 1) | |
pixel.fill((0, 0, 0)) # black | |
while True: | |
r = random.randint(0, 255) | |
g = random.randint(0, 255) | |
b = random.randint(0, 255) | |
# print(f"({r},{g},{b})") | |
fade_in_and_out(pixel, r, g, b) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment