Skip to content

Instantly share code, notes, and snippets.

@sargonas
Last active February 25, 2018 21:12
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 sargonas/7f819c114021fbe1edbaae50c2606898 to your computer and use it in GitHub Desktop.
Save sargonas/7f819c114021fbe1edbaae50c2606898 to your computer and use it in GitHub Desktop.
Infinity_Cat_ears
#CircuitPython code for a Trinket M0 with mini NeoPixel lights and a single button to control
#the lighting inside a set of infinity-mirror cat ears, powered by a small LiPoly battery.
from digitalio import DigitalInOut, Direction, Pull
import board
import time
import neopixel
pixelPin = board.D1 #set NeoPixel output pin
pixelNumber = 20 #set number of NeoPixels
strip = neopixel.NeoPixel(pixelPin, pixelNumber, brightness=0.5, auto_write=False)
button = DigitalInOut(board.D2) #set pin number of the button
button.direction = Direction.INPUT
button.pull = Pull.UP #register an up button as default (true)
lock = False #establish the color lock
while True:
for x in range(0, 255): #red to green cycle
strip.fill((x, 255-x, 0))
strip.write()
if ( button.value == False and lock == False): #check for button press
lock = True #set the lock state
strip.fill((x, 255-x, 0)) #lock the last used color
strip.write()
while lock == True:
if ( button.value == False): #check for resume button press
lock = False
for x in range(0, 255): #green to blue cycle
strip.fill((255-x, 0, x))
strip.write()
if ( button.value == False and lock == False): #check for button press
lock = True #set the lock state
strip.fill((255-x, 0, x)) #lock the last used color
strip.write()
while lock == True:
if ( button.value == False): #check for resume button press
lock = False
for x in range(0, 255): #blue to red cycle
strip.fill((0, x, 255-x))
strip.write()
if ( button.value == False and lock == False): #check for button press
lock = True #set the lock state
strip.fill((0, x, 255-x)) #lock the last used color
strip.write()
while lock == True:
if ( button.value == False): #check for resume button press
lock = False
time.sleep(0.01) #basic sleep timer for the loop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment