-
Notifications
You must be signed in to change notification settings - Fork 0
/
christmas.py
40 lines (33 loc) · 902 Bytes
/
christmas.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import time
from machine import Pin
from neopixel import NeoPixel
import random
# Initialize the Neopixel strip
strip = NeoPixel(Pin(28), 15)
# Define Christmas colors
red = (255, 0, 0)
green = (0, 255, 0)
white = (255, 255, 255)
colors = [red, green, white]
def fill(color):
for i in range(len(strip)):
strip[i] = color
strip.write()
def twinkling_effect(cycles, speed=0.1):
for _ in range(cycles):
# Randomly pick a LED to twinkle
led = random.randint(0, len(strip) - 1)
original_color = strip[led]
# Twinkle with white color
strip[led] = white
strip.write()
time.sleep(speed)
# Revert back to original color
strip[led] = original_color
strip.write()
time.sleep(speed)
while True:
for color in colors:
fill(color)
time.sleep(0.5)
twinkling_effect(10, 0.05)