-
Notifications
You must be signed in to change notification settings - Fork 776
/
Copy pathcode.py
executable file
·120 lines (106 loc) · 4.13 KB
/
code.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# SPDX-FileCopyrightText: 2020 Kattni Rembor for Adafruit Industries
#
# SPDX-License-Identifier: MIT
import board
import digitalio
import neopixel
from adafruit_magtag.magtag import MagTag
from adafruit_led_animation.animation.comet import Comet
from adafruit_led_animation.animation.sparkle import Sparkle
from adafruit_led_animation.animation.solid import Solid
from adafruit_led_animation.animation.colorcycle import ColorCycle
from adafruit_led_animation.sequence import AnimationSequence, AnimateOnce
from adafruit_led_animation.group import AnimationGroup
from adafruit_led_animation.color import RED, GREEN, BLUE, WHITE, GOLD
# =============== CUSTOMISATIONS ================
# The pin to which you connected your NeoPixel strip.
strip_pin = board.D10
# The number of NeoPixels on the strip.
strip_num = 30
# The MagTag LED brightness, where 0.0 is 0% (off) and 1.0 is 100% brightness, e.g. 0.3 is 30%.
pixel_brightness = 0.5
# The strip LED brightness, where 0.0 is 0% (off) and 1.0 is 100% brightness, e.g. 0.3 is 30%.
strip_brightness = 1
# IF YOU ADD NEW COLORS, YOU MUST IMPORT THEM.
# The colors to cycle through. Can be any number of colors.
color_cycle_colors = (RED, GREEN)
# The speed of the color cycle in seconds. Decreasing speeds it up, increasing slows it down.
cycle_speed = 0.5
# The sparkle color.
sparkle_color = GOLD
# The sparkle speed in seconds. Decreasing speeds it up, increasing slows it down.
sparkle_speed = 0.1
# The comet colors.
comet_one_color = WHITE
comet_two_color = BLUE
# The speed of the comet on the MagTag NeoPixels.
magtag_comet_speed = 0.06
# The length of the comet tail on the MagTag NeoPixels.
magtag_comet_tail = 3
# The speed of the comet on the strip of NeoPixels.
strip_comet_speed = 0.03
# The length of the comet tail on the strip of NeoPixels.
strip_comet_tail = 15
# ===============================================
# Setup MagTag library.
magtag = MagTag()
# Setup pixels.
pixels = magtag.peripherals.neopixels
pixels.brightness = pixel_brightness
magtag.peripherals.neopixel_disable = False
strip = neopixel.NeoPixel(strip_pin, strip_num, brightness=strip_brightness, auto_write=False)
# Create animations in sequences and groups.
animations = AnimationSequence(
AnimationGroup(
ColorCycle(pixels, cycle_speed, color_cycle_colors),
ColorCycle(strip, cycle_speed, color_cycle_colors),
sync=True,
),
AnimationGroup(
Sparkle(pixels, sparkle_speed, sparkle_color, 15),
Sparkle(strip, sparkle_speed, sparkle_color, 1),
),
AnimationSequence(
AnimateOnce(
AnimationGroup(
Comet(pixels, magtag_comet_speed, comet_one_color, tail_length=magtag_comet_tail),
Comet(strip, strip_comet_speed, comet_one_color, tail_length=strip_comet_tail),
),
AnimationGroup(
Comet(pixels, magtag_comet_speed, comet_two_color, tail_length=magtag_comet_tail),
Comet(strip, strip_comet_speed, comet_two_color, tail_length=strip_comet_tail),
),
),
),
AnimationGroup(
# Turn the LEDs off.
Solid(pixels, 0),
Solid(strip, 0),
),
auto_clear=True,
)
# Set the background image.
magtag.set_background("/adaflake.bmp")
# Add lines of text including button labels.
magtag.add_text(text_color=0xFFFFFF, text_position=(0, 10), text_scale=2)
magtag.set_text("Button functions:", auto_refresh=False)
magtag.add_text(text_color=0xFFFFFF, text_position=(0, 65))
magtag.set_text(" Button A: Color Cycle\n"
" Button B: Sparkle\n"
" Button C: Comet\n"
" Button D: LEDs off",
index=1,
auto_refresh=False)
magtag.add_text(text_color=0xFFFFFF, text_position=(0, 120))
magtag.set_text(" A B C D", index=2)
# Main loop.
while True:
if magtag.peripherals.button_a_pressed:
animations.activate(0)
elif magtag.peripherals.button_b_pressed:
animations.activate(1)
elif magtag.peripherals.button_c_pressed:
animations.activate(2)
elif magtag.peripherals.button_d_pressed:
animations.activate(3)
animations.animate()