from machine import UART, Pin
from neopixel import NeoPixel
import random
import time
# 58, 55, and 59 are the lengths
cloud1_leds = 172
cloud2_leds = 120
cloud1_pin = 0 # gp11
cloud2_pin = 2
random.seed()
np1 = NeoPixel(Pin(cloud1_pin), cloud1_leds)
np2 = NeoPixel(Pin(cloud2_pin), cloud2_leds)
def lightning():
bolt_length_1 = random.randint(7, 30)
bolt_length_2 = random.randint(5, 8)
offset = random.randint(5, 20)
max_start = cloud1_leds - bolt_length_1
start = random.randint(0, max_start)
end = start + bolt_length_1
start_2 = bolt_length_1 + offset
end_2 = start_2 + bolt_length_2
color = random.randint(250, 255)
delay = random.randint(250, 750)
for i in range(start, end):
np1[i] = (color, color, color)
for i in range(start_2, end_2):
np1[i] = (color, color, color)
np1.write()
time.sleep_ms(100)
for i in range(start, end):
np1[i] = (0, 0, 0)
for i in range(start_2, end_2):
np1[i] = (0, 0, 0)
np1.write()
time.sleep_ms(50)
for i in range(start, end):
np1[i] = (color, color, color)
for i in range(start_2, end_2):
np1[i] = (color, color, color)
np1.write()
time.sleep_ms(100)
for i in range(start, end):
np1[i] = (0, 0, 0)
for i in range(start_2, end_2):
np1[i] = (0, 0, 0)
np1.write()
time.sleep_ms(50)
time.sleep(random.randint(8, 15))
def clear_strip():
np1.fill((0, 0, 0))
np1.write()
np2.fill((0, 0, 0,))
np2.write()
try:
while True:
lightning()
except KeyboardInterrupt:
print("clearing")
clear_strip()