Skip to content

Instantly share code, notes, and snippets.

@RobCranfill
Created February 29, 2024 18:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RobCranfill/638cd6ce62f57eb5715e96dfc1bba98a to your computer and use it in GitHub Desktop.
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.
# 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