Skip to content

Instantly share code, notes, and snippets.

@vigevenoj
Created October 13, 2017 15:50
Show Gist options
  • Save vigevenoj/310811c7828e72564ed710f9236a1511 to your computer and use it in GitHub Desktop.
Save vigevenoj/310811c7828e72564ed710f9236a1511 to your computer and use it in GitHub Desktop.
neopixel lantern scratchpad
import machine
import neopixel
import time
def cycle(np):
n = np.n
for i in range(4 * n):
for j in range(n):
np[j] = (0, 0, 0)
np[i % n] = (255, 255, 255)
np.write()
time.sleep_ms(25)
def bounce_blue(np):
n = np.n
for i in range(4 * n):
for j in range(n):
np[j] = (0, 0, 128)
if (i // n) % 2 == 0:
np[i % n] = (0, 0, 0)
else:
np[n - 1 - (i % n)] = (0, 0, 0)
np.write()
time.sleep_ms(60)
def fade_red(np):
n = np.n
for i in range(0, 4 * 256, 8):
for j in range(n):
if (i // 256) % 2 == 0:
val = i & 0xff
else:
val = 255 - (i & 0xff)
np[j] = (val, 0, 0)
np.write()
# Turn off all the LEDs
# self explanatory, 0 is off
def clear(np):
n = np.n
for i in range(n):
np[i] = (0, 0, 0)
np.write()
# Make a nice red-orange glow
def fire(np):
for i in range(np.n):
if i % 2 == 0:
# even LEDs are red
np[i] = (255, 0, 0)
else:
# odd LEDs are orange
np[i] = (255, 128, 0)
np.write()
if __name__ == '__main__':
# Data line is on pin 13
# and there are 12 LEDs
np = neopixel.NeoPixel(machine.Pin(13), 12)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment