Prop Maker Saber Light Color

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
KingRodder85
 
Posts: 4
Joined: Mon Jan 04, 2021 10:18 pm

Prop Maker Saber Light Color

Post by KingRodder85 »

Hello, I have been working on the prop maker light saber build and have followed the directions. I have got everything wired and have the code installed and working part of the way. Saber turns on and LED strip turns blue like I have the code. Once the "clash phase" is initiated, the LED's all turn white like they are supposed to do, then they all turn to different colors and stay until the unit is shaken again before returning to blue.

How do I get the lights to turn back directly from all white to "blue" after the clash occurs?

User avatar
mikeysklar
 
Posts: 13824
Joined: Mon Aug 01, 2016 8:10 pm

Re: Prop Maker Saber Light Color

Post by mikeysklar »

It looks like the default color for the saber is purple. Had you modified that to blue?

Code: Select all

COLOR = (100, 0, 255) 
I believe modifying COLOR_IDLE to be the same value as COLOR will remove the rainbow light effect you are getting inbetween hits and go directly from white to purple again.

Code: Select all

COLOR_IDLE = COLOR

Code: Select all

# Main program loop, repeats indefinitely
while True:

red_led.value = True

if not switch.value:# button pressed?
if mode == 0:# If currently off...
enable.value = True
power('on', 1.7, False)# Power up!
play_wav('idle', loop=True)     # Play background hum sound
mode = 1# ON (idle) mode now
else:# else is currently on...
power('off', 1.15, True)# Power down
mode = 0# OFF mode now
enable.value = False
while not switch.value:# Wait for button release
time.sleep(0.2)# to avoid repeated triggering

elif mode >= 1:# If not OFF mode...
x, y, z = accel.acceleration # Read accelerometer
accel_total = x * x + z * z
# (Y axis isn't needed for this, assuming Hallowing is mounted
# sideways to stick.  Also, square root isn't needed, since we're
# just comparing thresholds...use squared values instead, save math.)
if accel_total > HIT_THRESHOLD:   # Large acceleration = HIT
TRIGGER_TIME = time.monotonic() # Save initial time of hit
play_wav('hit')# Start playing 'hit' sound
COLOR_ACTIVE = COLOR_HIT# Set color to fade from
mode = 3# HIT mode
elif mode == 1 and accel_total > SWING_THRESHOLD: # Mild = SWING
TRIGGER_TIME = time.monotonic() # Save initial time of swing
play_wav('swing')# Start playing 'swing' sound
COLOR_ACTIVE = COLOR_SWING      # Set color to fade from
mode = 2# SWING mode
elif mode > 1:# If in SWING or HIT mode...
if audio.playing:# And sound currently playing...
blend = time.monotonic() - TRIGGER_TIME # Time since triggered
if mode == 2:# If SWING,
blend = abs(0.5 - blend) * 2.0 # ramp up, down
strip.fill(mix(COLOR_ACTIVE, COLOR_IDLE, blend))
strip.show()
else:# No sound now, but still MODE > 1
play_wav('idle', loop=True) # Resume background hum
strip.fill(COLOR_IDLE)      # Set to idle color
strip.show()
mode = 1# IDLE mode now

User avatar
KingRodder85
 
Posts: 4
Joined: Mon Jan 04, 2021 10:18 pm

Re: Prop Maker Saber Light Color

Post by KingRodder85 »

Still having trouble with this. I have deleted all code and made sure both bootloader and circuit python are up to date. I then re-loaded the code.py file and ran as is with no changes. I am getting rainbow LED patterns.

User avatar
mikeysklar
 
Posts: 13824
Joined: Mon Aug 01, 2016 8:10 pm

Re: Prop Maker Saber Light Color

Post by mikeysklar »

@KingRodder85,

Please post your modified code.

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”