import neopixel
from machine import Pin
from time import sleep
import neoneopixel
import machine, os
pixels = neopixel
# SD Card slot
sd = machine.SDCard(slot=2)
# Cyclotron
npc = neopixel.NeoPixel(Pin(15), 64)
# Power Cell
np = neopixel.NeoPixel(Pin(2), 8)
# Wand / Vent
npw = neopixel.NeoPixel(Pin(4), 14)
# led arrays
np_j1 = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
np_j2 = [16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31]
np_j3 = [32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47]
np_j4 = [48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63]
np_wd = [0,1,2,3,4,5,6,7,8,9,10,11,12,13]
np_pc = [0,1,2,3,4,5,6,7]
def array():
np_j1,np_j2, np_j3,np_j4,np_wd,np_pc
def switch_handler(pin):
global switch_on
switch_on = pin
def button_handler(pin):
global button_pressed
button_pressed = pin
# switches and buttons
WAND_SWITCH = Pin(32, Pin.IN, Pin.PULL_UP)
PACK_SWITCH = Pin(13, Pin.IN, Pin.PULL_UP)
MUSIC_SWITCH = Pin(14, Pin.IN, Pin.PULL_UP)
FIRE1 = Pin(25, Pin.IN, Pin.PULL_UP)
FIRE2 = Pin(26, Pin.IN, Pin.PULL_UP)
def switch():
WAND_SWITCH, PACK_SWITCH, MUSIC_SWITCH
def Button():
FIRE1, FIRE2
# colors
RED = (255,0,0)
YELLOW = (255,255,0)
GREEN = (0,255,0)
BLUE = (0,0,255)
BLUE2 = (56,65,232)
WHITE = (255,255,255)
ORANGE = (255,140,0)
OFF = (0,0,0)
def color():
RED,YELLOW,GREEN,BLUE,BLUE2,WHITE,ORANGE,OFF
# theme
movie = RED
stasis = YELLOW
meson = BLUE
slime = GREEN
def theme():
movie, stasis, meson, slime
# sleep time
w1 = .25
w2 = .5
w3 = 1
w4 = 1.5
w5 = 2
def wait():
w1,w2,w3,w4,w5
def set_color(start, end, color):
for pixels in range(start, end):
npc[pixels] = color
npc.write()
def clear():
for i in npc:
npc[i] = OFF
npc.write()
def bounce(color, wait):
for i in range(4 * 8):
for j in range(8):
np[j] = color
if (i // 8) % 2 == 0:
np[i % 8] = OFF
else:
np[8 - 1 - (i % 8)] = OFF
np.write()
sleep(wait)
def cycle(color, wait):
for i in range(4 * 8):
for j in range(8):
np[j] = OFF
np[i % 8] = color
np.write()
sleep(wait)
def blink(start, end, color, wait):
for pixels in range(start, end):
npc[pixels] = color
npc.write()
sleep(wait)
for pixels in range(start, end):
npc[pixels] = OFF
npc.write()
sleep(wait)
def power_cell(wait):
np[0] = BLUE
np.write()
sleep(wait)
np[1] = BLUE
np.write()
sleep(wait)
np[2] = BLUE
np.write()
sleep(wait)
np[3] = BLUE
np.write()
sleep(wait)
np[4] = BLUE
np.write()
sleep(wait)
np[5] = BLUE
np.write()
sleep(wait)
np[6] = BLUE
np.write()
sleep(wait)
np[7] = BLUE
np.write()
sleep(wait)
np[0] = OFF
np[1] = OFF
np[2] = OFF
np[3] = OFF
np[4] = OFF
np[5] = OFF
np[6] = OFF
np[7] = OFF
np.write()
def cyclotron(theme):
while True:
blink(0, 16, theme, w1)
blink(16, 32, theme, w1)
blink(32, 48, theme, w1)
blink(48, 64, theme, w1)
#for n in range(4): # chase 4 times
# np[0] = BLUE
# np.write()
# sleep(w5)
# for i in range(1, 8): # increment each pixel
# np[i] = BLUE
# np[i-1] = (56,65,232)
# np.write()
# sleep(w5)
cyclotron(movie)