Skip to content

Instantly share code, notes, and snippets.

@jasoncoon
Last active January 22, 2022 11:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasoncoon/6884626781bac0f922c48d2a406a8a57 to your computer and use it in GitHub Desktop.
Save jasoncoon/6884626781bac0f922c48d2a406a8a57 to your computer and use it in GitHub Desktop.
Fibonacci64 - Demo Reel - CircuitPython & NeoPixel
# Fibonacci64 - Demo Reel - CircuitPython & NeoPixel
# https://gist.github.com/jasoncoon/6884626781bac0f922c48d2a406a8a57
# https://www.evilgeniuslabs.org/fibonacci64-micro
# This example uses CircuitPython and the Adafruit NeoPixel library
# You'll need neopixel.mpy in your /lib directory
# More information: https://learn.adafruit.com/welcome-to-circuitpython/circuitpython-libraries
import board
import neopixel
import time
pixel_pin = board.D10
num_pixels = 64
seconds_per_pattern = 5
pixels = neopixel.NeoPixel(
pixel_pin,
num_pixels,
brightness=0.0625,
auto_write=False)
radii = [
0, 13, 26, 39, 52, 57, 44, 31,
18, 5, 10, 23, 36, 49, 62, 54,
41, 28, 15, 2, 7, 20, 33, 46,
59, 51, 38, 25, 12, 4, 17, 30,
43, 56, 61, 48, 35, 22, 9, 1,
14, 27, 40, 53, 58, 45, 32, 19,
6, 11, 24, 37, 50, 63, 55, 42,
29, 16, 3, 8, 21, 34, 47, 60
]
angles = [
0, 249, 241, 232, 223, 200, 208, 217,
226, 235, 212, 203, 194, 185, 176, 162,
171, 180, 188, 197, 174, 165, 156, 147,
139, 124, 133, 142, 151, 136, 128, 119,
110, 101, 78, 86, 95, 104, 113, 99,
90, 81, 72, 63, 40, 49, 58, 67,
75, 52, 43, 34, 25, 17, 2, 11,
20, 29, 38, 14, 6, 255, 246, 237
]
coords_x = [
140, 189, 208, 214, 208, 146, 168, 180,
180, 162, 152, 146, 129, 103, 72, 40,
70, 97, 120, 131, 107, 79, 50, 23,
0, 7, 23, 46, 76, 93, 57, 37,
28, 29, 87, 68, 59, 62, 80, 113,
91, 94, 109, 133, 202, 172, 145, 125,
117, 145, 170, 198, 227, 253, 255, 235,
210, 181, 148, 175, 207, 228, 240, 244
]
coords_y = [
128, 114, 91, 63, 34, 0, 21, 48,
76, 106, 78, 47, 25, 11, 5, 38,
35, 42, 61, 101, 87, 69, 68, 78,
98, 143, 118, 102, 98, 122, 131, 152,
179, 209, 255, 230, 202, 174, 148, 142,
181, 210, 235, 252, 235, 234, 224, 203,
170, 183, 201, 205, 198, 181, 134, 157,
171, 173, 153, 145, 138, 120, 93, 63
]
hue = 0
def wheel(pos):
# Input a value 0 to 255 to get a color value.
# The colours are a transition r - g - b - back to r.
if pos < 0 or pos > 255:
return (0, 0, 0)
if pos < 85:
return (255 - pos * 3, pos * 3, 0)
if pos < 170:
pos -= 85
return (0, 255 - pos * 3, pos * 3)
pos -= 170
return (pos * 3, 0, 255 - pos * 3)
def rainbow_radius():
global hue
for i in range(num_pixels):
h = (radii[i] * 4 + hue) % 255
pixels[i] = wheel(h)
hue = (hue - 4) % 255
def rainbow_angle():
global hue
for i in range(num_pixels):
h = (angles[i] + hue) % 255
pixels[i] = wheel(h)
hue = (hue - 4) % 255
def rainbow_x():
global hue
for i in range(num_pixels):
h = (coords_x[i] + hue) % 255
pixels[i] = wheel(h)
hue = (hue - 4) % 255
def rainbow_y():
global hue
for i in range(num_pixels):
h = (coords_y[i] + hue) % 255
pixels[i] = wheel(h)
hue = (hue - 4) % 255
def rainbow_xy():
global hue
for i in range(num_pixels):
h = (coords_x[i] + coords_y[i] + hue) % 255
pixels[i] = wheel(h)
hue = (hue - 4) % 255
patterns = [
rainbow_x,
rainbow_y,
rainbow_xy,
rainbow_angle,
rainbow_radius
]
pattern_count = len(patterns)
pattern_index = 0
# timer used to increment the pattern index
next_pattern_time = time.monotonic() + seconds_per_pattern
while True:
patterns[pattern_index]()
pixels.show()
time.sleep(.04)
if time.monotonic() > next_pattern_time:
pattern_index = (pattern_index + 1) % pattern_count
# if pattern_index >= pattern_count: pattern_index = 0
next_pattern_time = time.monotonic() + seconds_per_pattern
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment