Hi Trace!
Haha, well, that's a bunch of messages, let's see what I can do ...
If you could explain in short, how the code keeps track of button change and why it executes the animation just once. In a post earlier, I was thinking about setting a bool with "true" and "false". But your code has a better approach.
Well, basically we start with setting the prevCoinColor and coinColor both to black. Since the color is already black, nothing changed.
Whenever check for what the color should be based on the inserted coin (buttons), we first copy the [current] coinColor to prevCoinColor.
After that we determine what the color should be based on the buttons.
If this new coinColor does not match the prevCoinColor (the color before we determined the new color) then we know that we need to run the effect. 😊
Hope that makes sense and I hope this is what you meant?
The reason for my trouble is, because there is no need to use any neopixel conversion, I dont know how to convert the existing animations to just fastled.
There are 3 functions that need to be changed ... (note that you can use CRGB::Black or CRGB(0,0,0) - which would be the same)
Using the native FastLED functions are potentially faster and more efficient.
But I see (now) that you already figured that one out 😁
setAll - fill the strip with one color
setAll(red, green, blue);
now becomes (should be faster and more efficient)
fill_solid(leds, NUM_LEDS, CRGB(red,green,blue));
FastLED.show(); // not sure if this line is needed
setPixel - set the color of one LED pixel
setPixel(Pixel, red, green, blue);
becomes
leds[Pixel] = CRGB(red, green, blue);
showStrip - Make changes visible
showStrip();
becomes
FastLED.show();
The delay for button press causes the problem with sparkle. I know I can handle this with currentMillis and prevMillis, but I have not done that before
And this is where the Arduino shows some limitations since it doesn't do multi tasking. At all.
Ideally you'd want an effect to keep running, while another "task" checks the state of the buttons.
We have a few options here;
You could remove the delay, and call "coinColorSelection" frequent in the effect code.
In my opinion not an elegant solution, but there will be scenario's where this could work just fine and it would be the simplest to implement.
Downside is that the effect may run slower.
To speed things up, I'd do the button comparison differently. We could use a color array with predefined colors in an array.
I haven't tested this, but as far as I recall, a boolean (one bit) doesn't really exist in Arduino C. Instead they use a byte for this.
Zero means False, anything not zero mean True. (reference)
Now, the code below is not entirely "perfect" but it will probably work (and hopefully makes sense).
As you can see in the void loop, we do not need a bunch of if-statements. Instead we pull the color from a so called multi-dimensional array.
Silly way of putting it: an array with 3 lines, and each line can have 2 values (true or false, or better: 1 or 0).
I have not been able to test this, but the compiler seems to be OK with it.
#include "FastLED.h"
CRGB CoinColors[2][2][2];
void setup() {
// put your setup code here, to run once:
CoinColors[0][0][1]=CRGB::Red; // Button 1 and 2 LOW, button 3 HIGH
CoinColors[0][1][0]=CRGB::Yellow; // Button 1 and 3 LOW, button 2 HIGH
CoinColors[0][1][1]=CRGB::Blue;
CoinColors[1][0][0]=CRGB::Green;
CoinColors[0][1][0]=CRGB::Pink;
CoinColors[0][0][1]=CRGB::Aqua;
CoinColors[1][1][1]=CRGB::Black;
}
void loop() {
// put your main code here, to run repeatedly:
bool Button1 = true;
bool Button2 = true;
bool Button3 = true;
coinColor = CoinColors[Button1][Button2][Button3];
}
Let's start with that, since no matter what the outcome will be, this will be useful 😊