@hans Hi Hans, first of all, if you dont have the time or mind to work on this right now,you dont have to. It is just for a toy and family is much more important than anything else. I hope it is nothing to much of concern with your mom at the hospital?!
As for the sparkle effect and the brightness. Yes, I have already tried using CRGB values to control the brightness of the glitter. Finally I have done it with CHSV, cause it is easier to change the color and brightness independently.
void MorphAnimation(fract8 chanceOfGlitter) {
bool button4 = digitalRead(Morph_Button) == LOW;
if (button4) {
fill_solid(leds, NUM_LEDS, coinColor);
if (random8() < chanceOfGlitter) {
leds[random16(NUM_LEDS)] += CHSV(0, 0, 255);
}
FastLED.show();
} else {
fill_solid(leds, NUM_LEDS, CRGB::Black);
FastLED.show();
}
}
I have also replaced int with bool, like you have said. But....can you tell me why? Is it because of memory and we only need 1 and 0 here? So I could replace it everywhere?
The compiler error: Yes, it was just a typo. But I have also found out, that the compiler makes some errors like "there is no such directory", when copy and paste code to an unsaved new sketch. It took a while to find that out.
My solution to wait for the coin buttons to get pressed, to prevent actions for not simultanously pressed coin buttons, does not work that well:
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
// Check for button combinations and assign the corresponding colors to coinColor
if (button1 && button2) {
coinColor = CRGB(20, 0, 0); //Tyranosaurus - red
if (prevcoinColor != coinColor) {
myDFPlayer.playMp3Folder(1);
}
The problem is, sometimes it works fine, sometimes it does not "wait" for the button presses. I think there is a better solution for this, right? My goal was to have a lil delay before the code recognize the button presses, in case one button gets pressed just a few millis after the other. Using delay at this point influences the sparkle animation (dont know why).
Also this would eliminate another problem: When releasing the coin buttons, without any sort of "delay" the code also recognizes when one button is already released, while the other is still pressed and then plays the animation. Even the releasing happens in a few milliseconds.
For the mp3: Thats right. I want the mp3 to playback when I click the button and stop when I click the button again. And I got it working already (still without debouncing):
void PlayThemeSong() {
int button5 = digitalRead(Activate_Button) == LOW;
if (button5) {
if (isPlayingTheme) {
myDFPlayer.stop();
delay(50);
isPlayingTheme = false;
} else {
isPlayingTheme = true;
myDFPlayer.playMp3Folder(10);
delay(50);
}
}
}
Lets talk about the rainbow effect. I thought you could know this function, cause it is part of the fastLED library. I dont know if it needs to be called over and over again to get it moving, but your solution works (how can you not knowing something, but still figure out a solution? Thats crazy man 🤣 )
Can you explain, why your added "else" part works, but mine without the second else did not? Programming logic is still not my friend.
As you can see, I have also deleted the variables and wrote it directly into the function. That was necessary for a later idea (see below).
void rainbow_Test() {
int button9 = digitalRead(Rainbow_Button) == LOW;
if (button9) {
if (isRainbow) {
fill_solid(leds, NUM_LEDS, CRGB::Black);
FastLED.show();
isRainbow = false;
} else {
isRainbow = true;
uint8_t thisHue = beat8(50, 255);
uint8_t deltaHue = 255/NUM_LEDS;
fill_rainbow(leds, NUM_LEDS, thisHue, deltaHue);
FastLED.show();
}
} else {
if(isRainbow) {
uint8_t thisHue = beat8(50, 255);
uint8_t deltaHue = 255/NUM_LEDS;
fill_rainbow(leds, NUM_LEDS, thisHue, deltaHue);
FastLED.show();
}
}
}
And now comes the most tricky part (I guess): What if I tell you, that I would like to have this rainbow effect executed after the button was held for 2 seconds? To get it right: I hold the button for 2 seconds, the rainbow starts and works as intended, I release the button and when I press the button again, the rainbow stops.
I have tried the OneButton Library. And while it works for other parts (like the mp3 on/off toggle), it did not for the rainbow (thats why I had to delete the variable, cause the button library uses voids without variables). And while your rainbow code works fine, I would not know how to "delete" the button part, to get it handled by the button library.
To have you not jumping up and down to read everything, here is the summary:
brightness for sparkle - works
mp3 toggle on/off - works
Rainbow effect toggle on/off - works
CoinButton recognition delay for not exact simultanously pressed or released CoinButtons - not working (my millis attempt, seems to be faulty)
Button click/hold/release function - needs to be worked on (any ideas about a button library?)