Skip to content

Code for guide "Glowy Message Crown" #1916

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Trinket_M0_Message_Crown/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## Glowy Message Crown

A guide in the Adafruit Learning system

2021 by Charlyn G for Adafruit Industries

MIT License
108 changes: 108 additions & 0 deletions Trinket_M0_Message_Crown/code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# SPDX-FileCopyrightText: 2021 Charlyn Gonda for Adafruit Industries
#
# SPDX-License-Identifier: MIT
#
import time
import board
from rainbowio import colorwheel
import neopixel

pixel_pin = board.D4
num_pixels = 13

pixels = neopixel.NeoPixel(pixel_pin, num_pixels, brightness=0.3,
auto_write=False)

# Lights up the message letter by letter
def spell(color, wait):
for i in range(num_pixels-1, -1, -1):
pixels[i] = color
time.sleep(wait)
pixels.show()
time.sleep(0.5)

# Lights up a word, given a startIndex and stopIndex
def show_word(startIndex, endIndex, color, wait):
pixels.fill(OFF)
pixels.show()
time.sleep(0.1)

for i in range(startIndex, endIndex-1, -1):
pixels[i] = color

pixels.show()
time.sleep(wait)

# Lights up every even-numbered index
def alternate(color, wait):
for i in range(num_pixels):
if i % 2 == 0:
pixels[i] = color
else:
pixels[i] = OFF
pixels.show()
time.sleep(wait)

# Lights up every odd-numbered index
def alternate_reverse(color, wait):
for i in range(num_pixels):
if i % 2 == 1:
pixels[i] = color
else:
pixels[i] = OFF
pixels.show()
time.sleep(wait)

# Full rainbow!
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)

RED = (255, 0, 0)
YELLOW = (255, 150, 0)
ORANGE = (255, 40, 0)
GREEN = (0, 255, 0)
CYAN = (0, 255, 255)
BLUE = (0, 0, 255)
PURPLE = (180, 0, 255)
MAGENTA = (255, 0, 20)
JADE = (0, 255, 40)
OFF = (0, 0, 0)

ALT_WAIT = 0.5
CHASE_WAIT = 0.1
WORD_WAIT = 1

while True:
# indices for "birthday" is from 12 - 5
show_word(12, 5, MAGENTA, WORD_WAIT)

# indices for "boss" is from 4 - 0
show_word(4, 0, JADE, WORD_WAIT)

# again!
show_word(12, 5, ORANGE, WORD_WAIT)
show_word(4, 0, YELLOW, WORD_WAIT)

spell(GREEN, CHASE_WAIT)
spell(CYAN, CHASE_WAIT)
spell(PURPLE, CHASE_WAIT)

alternate(JADE, ALT_WAIT)
alternate_reverse(ORANGE, ALT_WAIT)

alternate(MAGENTA, ALT_WAIT)
alternate_reverse(BLUE, ALT_WAIT)

alternate(PURPLE, ALT_WAIT)
alternate_reverse(GREEN, ALT_WAIT)

alternate(CYAN, ALT_WAIT)
alternate_reverse(MAGENTA, ALT_WAIT)

rainbow_cycle(0)
rainbow_cycle(0) # higher number, slower rainbow