Skip to content

Instantly share code, notes, and snippets.

@jasoncoon
Created September 18, 2021 13:25
Show Gist options
  • Save jasoncoon/a70d24ed38994aa669f943c2e84512e4 to your computer and use it in GitHub Desktop.
Save jasoncoon/a70d24ed38994aa669f943c2e84512e4 to your computer and use it in GitHub Desktop.
Fibonacci64 - Expanding Rainbows - CircuitPython & NeoPixel Library
# Fibonacci64 - Expanding Rainbows - CircuitPython & NeoPixel
# https://gist.github.com/jasoncoon/a70d24ed38994aa669f943c2e84512e4
# 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
pixels = neopixel.NeoPixel(
pixel_pin,
num_pixels,
brightness=0.0625,
auto_write=False)
physicalToFibonacci = (
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)
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_wheel():
global hue
for i in range(num_pixels):
h = (physicalToFibonacci[i] * 4 + hue) % 255
pixels[i] = wheel(h)
hue = (hue - 4) % 255
while True:
rainbow_wheel()
pixels.show()
time.sleep(.04)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment