Skip to content

Commit c3f0f7b

Browse files
authored
Add files via upload
1 parent 022afbb commit c3f0f7b

File tree

1 file changed

+107
-0
lines changed

1 file changed

+107
-0
lines changed

Trinket_M0_Message_Crown/code.py

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# SPDX-FileCopyrightText: 2021 Charlyn Gonda for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
#
5+
import time
6+
import board
7+
from rainbowio import colorwheel
8+
import neopixel
9+
10+
pixel_pin = board.D4
11+
num_pixels = 13
12+
13+
pixels = neopixel.NeoPixel(pixel_pin, num_pixels, brightness=0.3, auto_write=False)
14+
15+
# Lights up the message letter by letter
16+
def spell(color, wait):
17+
for i in range(num_pixels-1, -1, -1):
18+
pixels[i] = color
19+
time.sleep(wait)
20+
pixels.show()
21+
time.sleep(0.5)
22+
23+
# Lights up a word, given a startIndex and stopIndex
24+
def show_word(startIndex, endIndex, color, wait):
25+
pixels.fill(OFF)
26+
pixels.show()
27+
time.sleep(0.1)
28+
29+
for i in range(startIndex, endIndex-1, -1):
30+
pixels[i] = color
31+
32+
pixels.show()
33+
time.sleep(wait)
34+
35+
# Lights up every even-numbered index of neopixel
36+
def alternate(p1, color, wait):
37+
for i in range(num_pixels):
38+
if i % 2 == 0:
39+
pixels[i] = color
40+
else:
41+
pixels[i] = OFF
42+
pixels.show()
43+
time.sleep(wait)
44+
45+
# Lights up every odd-numbered index of neopixel
46+
def alternate_reverse(p1, color, wait):
47+
for i in range(num_pixels):
48+
if i % 2 == 1:
49+
pixels[i] = color
50+
else:
51+
pixels[i] = OFF
52+
pixels.show()
53+
time.sleep(wait)
54+
55+
# Full rainbow!
56+
def rainbow_cycle(wait):
57+
for j in range(255):
58+
for i in range(num_pixels):
59+
rc_index = (i * 256 // num_pixels) + j
60+
pixels[i] = colorwheel(rc_index & 255)
61+
pixels.show()
62+
time.sleep(wait)
63+
64+
RED = (255, 0, 0)
65+
YELLOW = (255, 150, 0)
66+
ORANGE = (255, 40, 0)
67+
GREEN = (0, 255, 0)
68+
CYAN = (0, 255, 255)
69+
BLUE = (0, 0, 255)
70+
PURPLE = (180, 0, 255)
71+
MAGENTA = (255, 0, 20)
72+
JADE = (0, 255, 40)
73+
OFF = (0,0,0)
74+
75+
ALT_WAIT = 0.5
76+
CHASE_WAIT = 0.1
77+
WORD_WAIT = 1
78+
79+
while True:
80+
# indices for "birthday" is from 12 - 5
81+
show_word(12, 5, MAGENTA, WORD_WAIT)
82+
83+
# indices for "boss" is from 4 - 0
84+
show_word(4, 0, JADE, WORD_WAIT)
85+
86+
# again!
87+
show_word(12, 5, ORANGE, WORD_WAIT)
88+
show_word(4, 0, YELLOW, WORD_WAIT)
89+
90+
spell(GREEN, CHASE_WAIT)
91+
spell(CYAN, CHASE_WAIT)
92+
spell(PURPLE, CHASE_WAIT)
93+
94+
alternate(pixels, JADE, ALT_WAIT)
95+
alternate_reverse(pixels, ORANGE, ALT_WAIT)
96+
97+
alternate(pixels, MAGENTA, ALT_WAIT)
98+
alternate_reverse(pixels, BLUE, ALT_WAIT)
99+
100+
alternate(pixels, PURPLE, ALT_WAIT)
101+
alternate_reverse(pixels, GREEN, ALT_WAIT)
102+
103+
alternate(pixels, CYAN, ALT_WAIT)
104+
alternate_reverse(pixels, MAGENTA, ALT_WAIT)
105+
106+
rainbow_cycle(0)
107+
rainbow_cycle(0) # higher number, slower rainbow

0 commit comments

Comments
 (0)