Code you can copy for all your Cosplay LED Projects

Check out my CircuitPython CopyCode below (code will only show on desktop version):

import digitalio
import board
import neopixel

from adafruit_led_animation.animation.comet import Comet
from adafruit_led_animation.color import (BLUE)

NUM_PIXELS = 14

NEOPIXEL_PIN = board.D5
POWER_PIN = board.D10
ONSWITCH_PIN = board.A1

strip = neopixel.NeoPixel(NEOPIXEL_PIN, NUM_PIXELS, brightness=1, auto_write=False)
strip.fill(0)
strip.show()

enable = digitalio.DigitalInOut(POWER_PIN)
enable.direction = digitalio.Direction.OUTPUT
enable.value = True

cometBlue = Comet(strip, speed=0.1, color=(0, 0, 255), tail_length=5, ring=True, bounce=False,)

while True:
    cometBlue.animate()

 

Here is the code I used for my Majoras Mask!

This code includes the movement sensor, LED groups, playing a sound effect and different animation sequences (code will only show on desktop version):
Please note that for the sound effect to work, it has to be a mono channel .wav file with 16bits and 22050Hz.

 

import time
import digitalio
import busio
import board
import neopixel
import adafruit_lis3dh

try:
    from audiocore import WaveFile
except ImportError:
    from audioio import WaveFile

try:
    from audioio import AudioOut
except ImportError:
    try:
        from audiopwmio import PWMAudioOut as AudioOut
    except ImportError:
        pass

from adafruit_led_animation.helper import PixelSubset
from adafruit_led_animation.animation.chase import Chase
from adafruit_led_animation.animation.sparkle import Sparkle
from adafruit_led_animation.animation.comet import Comet
from adafruit_led_animation.animation.pulse import Pulse
from adafruit_led_animation.animation.solid import Solid
from adafruit_led_animation.group import AnimationGroup
from adafruit_led_animation.sequence import AnimationSequence
from adafruit_led_animation.color import (
    RED,
    ORANGE,
    YELLOW,
)

i2c = busio.I2C(board.SCL, board.SDA)
int1 = digitalio.DigitalInOut(board.D6)
accel = adafruit_lis3dh.LIS3DH_I2C(i2c, int1=int1)
accel.range = adafruit_lis3dh.RANGE_4_G
accel.set_tap(1, 100)

THRESHOLD = 200

NUM_PIXELS = 75

NEOPIXEL_PIN = board.D5
POWER_PIN = board.D10
ONSWITCH_PIN = board.A1

strip = neopixel.NeoPixel(NEOPIXEL_PIN, NUM_PIXELS, brightness=1, auto_write=False)
strip.fill(0)
strip.show()

wave_file = open("sounds/" "sound.wav", 'rb')
wave = WaveFile(wave_file)
audio = AudioOut(board.A0)

enable = digitalio.DigitalInOut(POWER_PIN)
enable.direction = digitalio.Direction.OUTPUT
enable.value = True

group1 = PixelSubset(strip, 0, 39)
group2 = PixelSubset(strip, 39, 74)

chase = Chase(group1, speed=0.1, color=(255, 0, 0), size=10, spacing=5)
sparkle = Sparkle(group2, speed=0.05, color=(0, 255, 0), num_sparkles=10)

solidOrange = Solid(group1, color=ORANGE)
solidRed = Solid(strip, color=RED)
solidClear = Solid(strip, color=(0, 0, 0))
comet_Yellow = Comet(group2, speed=0.05, color=(255, 255, 0), tail_length=5, ring=True, bounce=False,)
pulse = Pulse(group2, speed=0.1, color=YELLOW, period=3)

animations = AnimationSequence(
    AnimationGroup(
        solidOrange,
        pulse,
        sync=True,
    ),
    AnimationGroup(
        solidOrange,
        pulse,
        sync=True,
    ),
)

while True:
    animations.animate()

    x, y, z = accel.acceleration
    accel_total = x * x + y * y  # x=tilt, y=rotate

    if accel_total > THRESHOLD:
        audio.play(wave)

        solidRed.animate()
        time.sleep(1.5)
        solidClear.animate()
        animations.next()

 

This code is meant for projects using the PropMaker FeatherWing and Feather M4 circuit combo (as found on adafruit.com).
Check out my new Light & Sound Tutorial Book to find out more!

The Book of Cosplay Light and Sound Effects by Kamui Cosplay

0
    0
    Your Cart
    Your cart is emptyReturn to Shop