Created
October 8, 2022 08:25
-
-
Save krpors/79e6139e88b84dc310d41151d7748e7e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import board | |
from rainbowio import colorwheel | |
import neopixel | |
import random | |
import touchio | |
OFF = (0, 0, 0) | |
RED = (255, 0, 0) | |
YELLOW = (255, 150, 0) | |
GREEN = (0, 255, 0) | |
CYAN = (0, 255, 255) | |
BLUE = (0, 0, 255) | |
PURPLE = (180, 0, 255) | |
pixel_pin = board.A1 | |
num_pixels = 30 | |
pixels = neopixel.NeoPixel(pixel_pin, num_pixels, brightness=0.1, auto_write=False) | |
touch_pad = board.A2 | |
touch = touchio.TouchIn(touch_pad) | |
def color_chase(color, wait): | |
for i in range(num_pixels): | |
pixels[i] = color | |
pixels.show() | |
time.sleep(wait) | |
def rainbow_cycle(wait): | |
for j in range(255): | |
for i in range(num_pixels): | |
rc_index = (i * 256 // num_pixels) + j | |
pixels[i] = colorwheel(rc_index & 255) | |
pixels.show() | |
time.sleep(wait) | |
def stuff(wait): | |
# for x in range(num_pixels): | |
# pixels[i] = (251, 111, 80) | |
# pixels.show() | |
for c in range(0, 20): | |
rr = random.randrange(0, 255) | |
gg = random.randrange(0, 255) | |
bb = random.randrange(0, 255) | |
for z in range(num_pixels): | |
pixels[z] = (rr, gg, bb) | |
pixels.show() | |
time.sleep(0.05) | |
def test(wait): | |
for i in range(0, 20): | |
pixels[::2] = [GREEN] * (len(pixels) // 2) | |
pixels[1::2] = [RED] * (len(pixels) // 2) | |
pixels.show() | |
time.sleep(wait) | |
pixels[::2] = [RED] * (len(pixels) // 2) | |
pixels[1::2] = [GREEN] * (len(pixels) // 2) | |
pixels.show() | |
time.sleep(wait) | |
def rainbow_inc(): | |
pixels.fill(RED) | |
pixels.show() | |
touched = False | |
def shuffle(A): | |
last_index = len(A) - 1 | |
while last_index > 0: | |
rand_index = random.randint(0, last_index) | |
A[last_index], A[rand_index] = A[rand_index], A[last_index] | |
last_index -= 1 | |
return A | |
def random_fill(color): | |
lst = list(range(0, num_pixels)) | |
lst = shuffle(lst) | |
for i in range(0, len(lst)): | |
pixels[lst[i]] = color | |
pixels.show() | |
time.sleep(random.random() / 10) | |
time.sleep(50/1000) | |
def safe_set(index, color): | |
if index > 0 and index < num_pixels: | |
pixels[index] = color | |
def derp(): | |
for i in range(-9, num_pixels + 9): | |
pixels.fill(OFF) | |
index = i | |
safe_set(index - 4, PURPLE) | |
safe_set(index - 3, BLUE) | |
safe_set(index - 2, GREEN) | |
safe_set(index - 1, YELLOW) | |
safe_set(index , RED) | |
safe_set(index + 1, YELLOW) | |
safe_set(index + 2, GREEN) | |
safe_set(index + 3, BLUE) | |
safe_set(index + 4, PURPLE) | |
pixels.show() | |
time.sleep(3/1000) | |
def derp2(): | |
for i in range(num_pixels + 9, -9, -1): | |
pixels.fill(OFF) | |
index = i | |
safe_set(index - 4, PURPLE) | |
safe_set(index - 3, BLUE) | |
safe_set(index - 2, GREEN) | |
safe_set(index - 1, YELLOW) | |
safe_set(index , RED) | |
safe_set(index + 1, YELLOW) | |
safe_set(index + 2, GREEN) | |
safe_set(index + 3, BLUE) | |
safe_set(index + 4, PURPLE) | |
pixels.show() | |
time.sleep(3/1000) | |
def trinkle(): | |
num_lights = 20 | |
for x in range(-num_lights, num_pixels + num_lights): | |
pixels.fill(OFF) | |
for i in range(x, x + num_lights): | |
r = random.randrange(0, 255) | |
g = random.randrange(0, 255) | |
b = random.randrange(0, 255) | |
safe_set(i, (r, g, b)) | |
pixels.show() | |
time.sleep(3/1000) | |
def seq1(): | |
derp() | |
derp2() | |
derp() | |
derp2() | |
random_fill(RED) | |
random_fill(OFF) | |
random_fill(YELLOW) | |
random_fill(OFF) | |
random_fill(GREEN) | |
random_fill(OFF) | |
random_fill(BLUE) | |
random_fill(OFF) | |
random_fill(PURPLE) | |
random_fill(OFF) | |
trinkle() | |
trinkle() | |
trinkle() | |
wait = 50/1000 | |
color_chase(RED, wait) # Increase the number to slow down the color chase | |
color_chase(YELLOW, wait) | |
color_chase(GREEN, wait) | |
color_chase(CYAN, wait) | |
color_chase(BLUE, wait) | |
color_chase(PURPLE, wait) | |
color_chase(BLUE, wait) | |
color_chase(CYAN, wait) | |
color_chase(GREEN, wait) | |
color_chase(YELLOW, wait) | |
while True: | |
seq1() | |
# trinkle() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment