Skip to content

Commit dcd5ce3

Browse files
authored
Merge pull request #1916 from adafruit/TheKitty-patch-1
Code for guide "Glowy Message Crown"
2 parents 8eed36b + 11baa93 commit dcd5ce3

File tree

2 files changed

+115
-0
lines changed

2 files changed

+115
-0
lines changed

Trinket_M0_Message_Crown/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
## Glowy Message Crown
2+
3+
A guide in the Adafruit Learning system
4+
5+
2021 by Charlyn G for Adafruit Industries
6+
7+
MIT License

Trinket_M0_Message_Crown/code.py

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

0 commit comments

Comments
 (0)