I have some code for an LED staff that I’m trying to get working and I could use a little help. What is the best way to do that? Just paste the code here, or put it somewhere else and link it? Thanks!
http://gist.github.com as mentioned on the ‘About Community’ section of the FastLED group homepage.
Got it, thanks!
So I am trying to adapt Jesus Climent’s LED staff code to run on my staff. I’m using an arduino nano instead of a teensy, so I can’t just run his outright. I’ve had to reduce it down quite a bit.
What I would like to do is be able to press, double press, or hold a button to change patterns. It seems to be working - when I do those things, the lights change, but then they freeze instead of looping, until I press the button again.
Note that if I comment out the buttons(); line and uncomment one of the pattern names below it, they work fine.
I’m using fastled 3.1.3 on arduino 1.6.12 in Windows 10. I’m using an arduino nano and 300 WS2812Bs. The code is here:
Please let me know if I did not do this right. Thanks in advance for any help!
Corrected link to code:
Thanks, Marc.
I dont’ know if it helps, but I’ve successfully used jsbutton from Jeff Saltzman in my own routines (on Nano’s):
https://github.com/atuline/FastLED-Demos/blob/master/seirlight/jsbutton.h
The above is my slightly modified version.
More ideas for you @Karl_Tinsley . I’ve used JChristensen’s button library multiple times. It can do presses and long presses, but not double presses. Here’s an example of DemoReel100 that changes pattern on button press.
@Andrew_Tuline Interesting. The jsbutton code looks almost identical to the code I’m trying to adapt. I’m guessing Jesus used that code too. I will try using it.
Check my seirlight.ino code (in that same git repository) to see how it’s used.
@Andrew_Tuline That is some truly elegant coding. Unfortunately, I’m not experienced enough to parse out the button part of it.
I’m pretty sure the buttons as I have them are working okay - when I click once, the serial monitor shows case1, case2, etc. The LEDs light up with the first frame of the selected pattern and do no more. If I click the button again, they appear to do another frame (there’s a slight change in the LEDs, anyway). So I’m thinking that something in my code is somehow blocking the loop function, or getting stuck in the button code somewhere.
I think I see what’s breaking my loop - it’s literally the “break” in the case statement. I think I need to set up an array listing the patterns, and then use the case statement to call the next pattern in the array.
How to do this is fairly clear in the DemoReel100 with button code that Marc mentioned.
So I added the array, but the sketch would not fit on the nano - too many variables for the RAM. Since I realized I would not need a double-click if I’m using the array, I switched over to using JChristensen’s code, since it has fewer variables. I added button.h to my sketch, and changed the code to use it, but now I’m getting many compile errors that mention button.h. In button.h I see these lines:
#if ARDUINO >= 100
#include <Arduino.h>
#else
#include <WProgram.h>
#endif
I’m not sure what these lines are for, or if I need to find arduino.h and wprogram.h to include? Any help?
Should I post the errors somewhere?
The errors are undefined references to Button::read() and Button::wasPressed().
Did you get the demoreel100 with button example to work? Confirm that first since it’s known to work.
Put your updated code to http://gist.github.com and share the link here. (And check the link works 
sounds like the lib was not properly installed.
Download, extract, remove “-master” from folder name, place it in “arduino/libraries”, then restart the IDE. The lib should appear in the list as “Button” when you do “File> Examples”, and now any of the examples should verify without errors.
@matt_p thanks! I did not realize that button was a library, not just a file to include. That took care of the compiling issue.
@marmil That was a good suggestion! After installing the button library correctly, I still couldn’t get my - admittedly butchered - code to load to the nano. Still too big. So I took your suggestion and got demoreel100 working. I realize that it will do everything I want, with a little tweaking, so I’m going to work with it, instead.
With everyone’s help, I’ve gotten my staff working pretty well, switching between five patterns at the press of a button - awesome! Special thanks to Marc Miller - I’m using your button version of demoreel100 as the basis.
Now I’m trying to incorporate a color palette. I’ve added the new palette in, using the DiscoStrobeWithPalette as an example, but I can’t figure out how to actually use the palette. Do I have to add something to each pattern that I want the palette used in? Any help is appreciated, as always!
My current code is here: https://gist.github.com/karltinsly/dd311e8379002a221339e85110b7d213
Looks like you’ve created the palette correctly, but you’ll need to add something like this to assign the colors to the pixels.
for( int i = 0; i < NUM_LEDS; i++) {
leds[i] = ColorFromPalette( currentPalette, colorIndex, brightness, currentBlending); colorIndex += 3;
}
Look at line 66 in the colorPalette FastLED example to see where this is used. You can make a new pattern that uses colorFromPalette and add to the pattern list, or you could modify some of the other patterns to use colorFromPalette in some fashion.
I’m looking forward to seeing your LED staff.
Here’s another example:
Look for the colorFromPalette line at the very bottom.