Hey guys im looking for some help with my little brother’s light saber. Ive been using ColorWipe to wipe a color on to the strip, but so far ive been unable to get the color to wipe in the opposite direction in order to turn it off. My latest attempt gets to the last LED and leaves it on at which point it becomes unresponsive and he is no longer able to turn it back on until he restarts it. But if i do a regular color wipe to turn off the LEDs in the same direction they turn on (which does not look like a light saber) it works fine. Im using swtich case to make the changes.
Are you using a button to turn the light saber on/off? I’m not a fan of for loops but you can use a for loop to turn the LEDs on then if an off button is pressed use a for loop going in the opposite direction to black out the LEDs.
Im using a push button to switch through 3 colors and then off. Im gonna add a second button specifically to change colors and the first just for the on/off taking the current color value for the color wipe
Can you share your code?
You don’t need a separate button to separate the color changing from the turning on/off, at least, not if you don’t want to. You can absolutely do it with a single button: ON-COLOR1-COLOR2-COLOR3-OFF. However, adding a separate button does give you the ability to completely kill the electronics and truly power it off, whereas in the single button implementation, something has to keep running so it can read the button state.
The additional “trick” with a separate on/off button is having to add a delay before it cuts the power. it has to allow for the wipe to finish before it cuts power.
@Brian_Lewis Yeah i can share the code later today when i get home. @Ashley_M_Kirchner_No thats actually how its set up right now Color1, Color2, Color3, off. What i want to do is have 2 different switch cases 1 which changes the color value, and the other takes that color value and in case 1 wipes the color on to the strip and in case 2 wipes the color off the strip in the opposite direction. My problem is getting the color off. It works if it wipes from 0 to NUM_LEDS but if i reverse it, lets say -
for (int i = NUM_LEDS; i > 0; i–)
It results in all the LEDs turning off except the last one. I dont understand why…
@Cristian_Martinez Is FastLED.show() inside of that for loop?
@Cristian_Martinez Actually. I know why. It should be for (int i = NUM_LEDS-1; i > 0; i–) You are addressing outside of the array of LEDs so it is causing funky issues.
@Brian_Lewis huh… didnt think about that… let me try that when i get home. My bro’s light saber is due for an upgrade to a stronger tube anyways so i wanna make sure the strip behaves right when i add that second button lol
@Cristian_Martinez , can still be done with one switch. I have a project where I use one switch to turn on/off the LEDs, as well as changing modes. What I did was configure the button to detect a short, single click, and long (press and hold) click. It can also be configured to detect a double click. Look for the OneButton library.
In your case, you can use the long-press function for the on/off with the single clicks as color changes.
