Skip to content

Instantly share code, notes, and snippets.

@gautric
Created October 30, 2022 16:37
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 gautric/dea36668a3458aaa05b8f6c26e585b1e to your computer and use it in GitHub Desktop.
Save gautric/dea36668a3458aaa05b8f6c26e585b1e to your computer and use it in GitHub Desktop.
halloween
# Code from
# https://learn.adafruit.com/micropython-basics-load-files-and-run-code/boot-scripts
# https://learn.adafruit.com/building-and-running-micropython-on-the-esp8266/micropython-usage
# https://docs.micropython.org/en/latest/esp8266/quickref.html#neopixel-driver
# https://docs.micropython.org/en/latest/esp8266/tutorial/neopixel.html
# sudo pip3 install adafruit-ampy
# export AMPY_PORT=/dev/cu.usbserial-14255
# ampy put test.py /main.py
# ampy run test.py
# Mini D1 : D3 == pin 0
from time import sleep
from machine import Pin
from neopixel import NeoPixel
import time
import os, machine
uart = machine.UART(0, 115200)
os.dupterm(uart, 1)
brightness = 0.03
print('Testing')
pin = Pin(0, Pin.OUT) # set GPIO0 to output to drive NeoPixels
np = NeoPixel(pin, 31) # create NeoPixel driver on GPIO0 for 8 pixels
color = [(255, 255, 255), (0, 255, 255), (255, 255, 0), (255, 0, 0), (0, 0, 255), (0, 255, 0), (0, 0, 0)]
print(color[0:-1])
def demo(np):
n = np.n
# cycle
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)
# bounce
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)
# fade in/out
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()
# clear
for i in range(n):
np[i] = (0, 0, 0)
np.write()
while True:
#demo(np)
# fade in/out
for i in range(0, 4 * 256, 8):
for j in range(31):
if (i // 256) % 2 == 0:
val = i & 0xff
else:
val = 255 - (i & 0xff)
np[j] = (val, val, val)
np.write()
print('Step 0')
for i in color :
for x in range(0,31):
np[x] = i
np.write()
time.sleep(0.5)
for i in color[0:-1] :
for t in range(0,5):
for x in range(0,31):
np[x] = i
np.write()
time.sleep(0.01)
for x in range(0,31):
np[x] = (0, 0, 0)
np.write()
time.sleep(0.5)
print('Step 1')
for i in color :
for x in range(0,31):
np[x] = i
np.write()
time.sleep(0.01)
print('Step 2')
for i in color :
for x in range(0,31):
np[x] = i
np[x-1] = (0, 0, 0)
np.write()
time.sleep(0.02)
print('Step 3')
for i in color :
for x in range(0,31):
y = 30 - x
np[y] = i
if x >= 1:
np[y+1] = (0, 0, 0)
np.write()
time.sleep(0.02)
print('Step 4')
for i in color :
for x in range(0,31):
y = 30 - x
np[y] = i
if x >= 1:
np[y+1] = (0, 0, 0)
np.write()
time.sleep(0.02)
for x in range(0,31):
np[x] = i
np[x-1] = (0, 0, 0)
np.write()
time.sleep(0.02)
print('Step 6')
for i in color :
for x in range(0,31):
np[30-x] = i
np.write()
time.sleep(0.02)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment