Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Rainbow Pride Traffic Lights Circuit Playground Express
# CircuitPlaygroundExpress_NeoPixel
import time
import board
import neopixel
pixels = neopixel.NeoPixel(board.A1, 11, brightness=.3)
pixels.fill((0, 0, 0))
pixels.show()
pixels2 = neopixel.NeoPixel(board.A2, 11, brightness=.3)
pixels2.fill((0, 0, 0))
pixels2.show()
# choose which demos to play
# 1 means play, 0 means don't!
trafficDemo = 1
simpleCircleDemo = 1
prideDemo = 1
def simpleCircle(wait):
RED = (255, 0, 0) # (0x10, 0, 0) also works
ORANGE = (255, 70, 0)
YELLOW = (255, 110, 0)
GREEN = (0, 255, 0)
AQUA = (0, 0x10, 0x10)
BLUE = (0, 0, 255)
PURPLE = (255, 0, 80)
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
for i in range(len(pixels)):
pixels[i] = BLACK
pixels2[i] = BLACK
time.sleep(1)
for k in range(3):
for i in range(len(pixels)):
pixels[i] = WHITE
pixels2[i] = WHITE
time.sleep(wait/2)
for i in range(len(pixels)):
pixels[i] = BLACK
pixels2[i] = BLACK
time.sleep(wait/2)
time.sleep(1)
for i in range(len(pixels)):
pixels[i] = RED
pixels2[i] = RED
time.sleep(wait)
time.sleep(1)
for i in range(len(pixels)):
pixels[i] = ORANGE
pixels2[i] = ORANGE
time.sleep(wait)
time.sleep(1)
for i in range(len(pixels)):
pixels[i] = YELLOW
pixels2[i] = YELLOW
time.sleep(wait)
time.sleep(1)
for i in range(len(pixels)):
pixels[i] = GREEN
pixels2[i] = GREEN
time.sleep(wait)
time.sleep(1)
for i in range(len(pixels)):
pixels[i] = BLUE
pixels2[i] = BLUE
time.sleep(wait)
time.sleep(1)
for i in range(len(pixels)):
pixels[i] = PURPLE
pixels2[i] = PURPLE
time.sleep(wait)
time.sleep(1)
for i in range(len(pixels)):
pixels[i] = BLACK
pixels2[i] = BLACK
time.sleep(wait)
time.sleep(1)
def trafficsignal(wait):
RED = (255, 0, 0) # (0x10, 0, 0) also works
YELLOW = (255, 110, 0)
GREEN = (0, 255, 0)
BLACK = (0, 0, 0)
for i in range(7, 10):
pixels[i] = RED
pixels2[i] = GREEN
time.sleep(3)
for i in range(7, 10):
pixels2[i] = BLACK
for k in range(6):
for i in range(4, 6):
pixels[i] = BLACK
pixels2[i] = YELLOW
time.sleep(0.5)
for i in range(4, 6):
pixels[i] = BLACK
pixels2[i] = BLACK
time.sleep(0.5)
for i in range(7, 10):
pixels[i] = BLACK
for i in range(0, 3):
pixels[i] = GREEN
pixels2[i] = RED
time.sleep(3)
for i in range(0, 3):
pixels[i] = BLACK
for k in range(6):
for i in range(4, 6):
pixels[i] = YELLOW
pixels2[i] = BLACK
time.sleep(0.5)
for i in range(4, 6):
pixels[i] = BLACK
pixels2[i] = BLACK
time.sleep(0.5)
for i in range(0, 3):
pixels2[i] = BLACK
for i in range(7, 10):
pixels[i] = RED
pixels2[i]= GREEN
time.sleep(3)
def pride(wait):
RED = (255, 0, 0) # (0x10, 0, 0) also works
ORANGE = (255, 70, 0)
YELLOW = (255, 110, 0)
GREEN = (0, 255, 0)
AQUA = (0, 0x10, 0x10)
BLUE = (0, 0, 255)
PURPLE = (255, 0, 80)
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
pixels.fill((0, 0, 0))
pixels.show()
pixels2.fill((0, 0, 0))
pixels2.show()
time.sleep(1)
for k in range (4):
for i in range(7,10):
pixels[i] = RED
for i in range(4,6):
pixels[i] = ORANGE
for i in range(0,3):
pixels[i] = YELLOW
for i in range(0,3):
pixels2[i] = GREEN
for i in range(4,6):
pixels2[i] = BLUE
for i in range(7,10):
pixels2[i] = PURPLE
time.sleep(1)
pixels.fill((0, 0, 0))
pixels2.fill((0, 0, 0))
pixels.show()
pixels2.show()
time.sleep(.2)
for i in range(4):
pixels.fill((255, 255, 255))
pixels.show()
pixels2.fill((255, 255, 255))
pixels2.show()
time.sleep(.2)
pixels.fill((0, 0, 0))
pixels2.fill((0, 0, 0))
pixels.show()
pixels2.show()
time.sleep(.2)
time.sleep(2)
while True:
if trafficDemo:
print ('Traffic Light Demo')
trafficsignal(0.5)
if simpleCircleDemo:
print('Simple Circle Demo')
simpleCircle(.05)
if prideDemo:
print('Rainbow PRIDE')
pride(.01)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment