<?xml version="1.0" encoding="UTF-8"?>        <rss version="2.0"
             xmlns:atom="http://www.w3.org/2005/Atom"
             xmlns:dc="http://purl.org/dc/elements/1.1/"
             xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
             xmlns:admin="http://webns.net/mvcb/"
             xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
             xmlns:content="http://purl.org/rss/1.0/modules/content/">
        <channel>
            <title>
									FastLED Light effects for Power Rangers - Arduino				            </title>
            <link>https://www.tweaking4all.com/forum/arduino/fastled-light-effects-for-power-rangers/</link>
            <description>Tweaking4All.com Discussion Board</description>
            <language>en-US</language>
            <lastBuildDate>Wed, 15 Jul 2026 20:04:34 +0000</lastBuildDate>
            <generator>wpForo</generator>
            <ttl>60</ttl>
							                    <item>
                        <title>RE: FastLED Light effects for Power Rangers</title>
                        <link>https://www.tweaking4all.com/forum/arduino/fastled-light-effects-for-power-rangers/paged/5/#post-5313</link>
                        <pubDate>Thu, 25 Jan 2024 23:36:31 +0000</pubDate>
                        <description><![CDATA[@Hans Here is already a little improvement: I was thinking about a much simpler solution for a breathing led effect. So why not using a sinewave with beatsin8 function.So this part within th...]]></description>
                        <content:encoded><![CDATA[<p>@Hans Here is already a little improvement: I was thinking about a much simpler solution for a breathing led effect. So why not using a sinewave with beatsin8 function.<br /><br />So this part within the NoCoinMorph void:<br /><br /></p>
<pre contenteditable="false">      while (digitalRead(Busy_Pin) == LOW) {

        fill_solid(leds, NUM_LEDS, CHSV(0, 255, 30));
        float breath = (exp(sin(millis() / 430.0 * PI)) - 0.36787944) * 108.0;
        FastLED.setBrightness(breath);
        FastLED.show();
      }</pre>
<p>Becomes this:<br /><br /></p>
<pre contenteditable="false">      while (digitalRead(Busy_Pin) == LOW) {

        uint8_t sinBeat  = beatsin8(80, 0, 5, 0, 0);
        FastLED.setBrightness(sinBeat);
        fill_solid(leds, NUM_LEDS, CRGB::Red);
        FastLED.show();
      }</pre>
<p>Here is an explanation for everyone:<br /><br />The first number is beats per minute, second is lowest value of the sinewave (0-255), third is highest value (0-255), fourth is timebase in milliseconds and the fifth is phase offset (0-255).<br /><br />The soundfile has a 80 BPM (alarm sound), I want the sinewave with the lowest value at 0 (leds off) and the highest value at 5 (brightness) and no timebase or phase offset.<br /><br />This sinewave is then used to control the brightness of the LEDs.<br /><br />Feel free to further improve or discuss about the whole program.<br /><br /></p>]]></content:encoded>
						                            <category domain="https://www.tweaking4all.com/forum/arduino/">Arduino</category>                        <dc:creator>Trace</dc:creator>
                        <guid isPermaLink="true">https://www.tweaking4all.com/forum/arduino/fastled-light-effects-for-power-rangers/paged/5/#post-5313</guid>
                    </item>
				                    <item>
                        <title>RE: FastLED Light effects for Power Rangers</title>
                        <link>https://www.tweaking4all.com/forum/arduino/fastled-light-effects-for-power-rangers/paged/5/#post-5312</link>
                        <pubDate>Wed, 24 Jan 2024 17:31:04 +0000</pubDate>
                        <description><![CDATA[@Hans Hi Hans, how are you? And are there news (hopefully good) about your mother?I kept working on the Power Rangers code and utilized parts of the code we have already done, to make some p...]]></description>
                        <content:encoded><![CDATA[<p>@Hans Hi Hans, how are you? And are there news (hopefully good) about your mother?<br /><br />I kept working on the Power Rangers code and utilized parts of the code we have already done, to make some progress.</p>
<p>There was still the task to have a button release function and I just realized that the "click and hold button"- function has some kind of button release function in it. Because the click function recognize the button release, not the button press.</p>
<p>This way I was able to set some timers to have a function getting executed after the button is pressed for a moment and not right when I press it. And with this I was able to use it just like a button release function for different animations and sounds.<br /><br />Using the DFPlayer mini busy pin was also usefull to start/stop some animations. So the animation is only be executed as long as the mp3 is playing.</p>
<p>The only problem left is the non blocking delay part for the button recognition. Maybe it is good enough as it is, but I need to test it in real life conditions first.<br /><br />Also I was able to make a blink pattern with different on off timings, so I can sync a simple blinking animation for a simple mp3 by looking at the timings within the mp3 and set them in code by hand. The way I did it seems to be more complicated than necessary. But it was possible to implement it to the coin release void.<br /><br />Feel free to tell me what you think. Maybe some other ideas for too complicated parts or any flaws?<br />Here is the full code:</p>
<pre contenteditable="false">#define FASTLED_INTERNAL  // just used to mute the Pragma messages when compiling
#include "FastLED.h"
#include &lt;EEPROM.h&gt;

#define PIN 6
#define NUM_LEDS 26

CRGB leds;

#define Coin_Button_1 3    // Coin button 1
#define Coin_Button_2 4    // Coin button 2
#define Coin_Button_3 5    // Coin button 3
#define Morph_Button 7     // Morph open button
#define Activate_Button 8  // Activate button

#define Busy_Pin 9

CRGB prevcoinColor = CRGB::Black;
CRGB coinColor = CRGB::Black;

boolean isPlayingMorph = false;
boolean isPlayingTheme = false;
boolean isRainbow = false;
boolean isPlayingNoCoin = false;

//↓↓=============== Button Selection Delay (not working correctly but maybe good enough) ===============↓↓//
unsigned long previousMillis = 0;
const long interval = 1500;
//↑↑=============== Button Selection Delay (not working correctly but maybe good enough) ===============↑↑//

//↓↓=============== Theme_Short_Rainbow_Long ===============↓↓//
long buttonTimer = 0;
long longPressTime = 3000;  //activate functions when button hold for 3 seconds

boolean buttonActive = false;
boolean longPressActive = false;
//↑↑=============== Theme_Short_Rainbow_Long ===============↑↑//

//↓↓=============== Morpher Jammed ===============↓↓//
long buttonTimer2 = 0;
long longPressTime2 = 1500;  // activate functions when button hold for 1,5 seconds

boolean buttonActive2 = false;
boolean longPressActive2 = false;
//↑↑=============== Morpher Jammed ===============↑↑//

//↓↓=============== Coin Release ===============↓↓//
long buttonTimer3 = 0;
long longPressTime3 = 3000;  //Pseudo-time, necessary for button release function to work

boolean buttonActive3 = false;
boolean longPressActive3 = false;
//↑↑=============== Coin Release ===============↑↑//

//↓↓=============== Morpher Close ===============↓↓//
long buttonTimer4 = 50;      //standard is 0, 50 for testing
long longPressTime4 = 3000;  //Pseudo-time, necessary for button release function to work

boolean buttonActive4 = false;
boolean longPressActive4 = false;
//↑↑=============== Morpher Close ===============↑↑//

//↓↓=============== No Coin Morph ===============↓↓//
long buttonTimer5 = 0;
long longPressTime5 = 1000;  //activate functions when button hold for 1 second

boolean buttonActive5 = false;
boolean longPressActive5 = false;
//↑↑=============== No Coin Morph ===============↑↑//

//↓↓=============== Coin Release Animation Timings ===============↓↓//
// Define the on and off timings
const double onTime1 = 100;
const double offTime1 = 160;
const double onTime2 = 100;
const double offTime2 = 170;
const double onTime3 = 100;
const double offTime3 = 40;
const double onTime4 = 100;
const double offTime4 = 160;
const double onTime5 = 70;
const double offTime5 = 215;
const double onTime6 = 80;
const double offTime6 = 500;

int state = 0;  // Define the current state of the state machine
//↑↑=============== Coin Release Animation Timings ===============↑↑//

//↓↓=============== DFPlayer mini initiation ===============↓↓//
#include "Arduino.h"
#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"

SoftwareSerial mySoftwareSerial(10, 11);  // RX, TX
DFRobotDFPlayerMini myDFPlayer;
void printDetail(uint8_t type, int value);
//↑↑=============== DFPlayer mini initiation ===============↑↑//

void setup() {
  FastLED.addLeds&lt;WS2811, PIN, GRB&gt;(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
  //FastLED.setBrightness(30);   //set global brightness -&gt; is off due to brightness settings for each void
  fill_solid(leds, NUM_LEDS, CRGB::Black);  //probably not needed
  FastLED.show();

  pinMode(Coin_Button_1, INPUT_PULLUP);    //button for Coin recognition
  pinMode(Coin_Button_2, INPUT_PULLUP);    //button for Coin recognition
  pinMode(Coin_Button_3, INPUT_PULLUP);    //button for Coin recognition
  pinMode(Morph_Button, INPUT_PULLUP);     //button for when Morpher is opened
  pinMode(Activate_Button, INPUT_PULLUP);  //button for click and hold functions (red button at the toy)


  //↓↓=============== DFPlayer mini setup ===============↓↓/
  mySoftwareSerial.begin(9600);
  Serial.begin(115200);
  if (!myDFPlayer.begin(mySoftwareSerial, true, false)) {  //Use softwareSerial to communicate with mp3. true, false added removes popping sound
    while (true)
      ;
  }
  myDFPlayer.setTimeOut(500);       //Set serial communictaion time out 500ms
  myDFPlayer.volume(1);             //Set volume value (0~30).
  myDFPlayer.EQ(DFPLAYER_EQ_BASS);  //Set equalizer NORMAL, POP, ROCK, JAZZ, CLASSIC, BASS
  myDFPlayer.outputDevice(DFPLAYER_DEVICE_SD);
}
//↑↑=============== DFPlayer mini setup ===============↑↑//

void loop() {

  coinColorSelection();              //Coin Insert Color Recognition function
  CoinInsertAnimation(1, 50);        //Coin Insert Animation (3 times for longer animation)
  CoinInsertAnimation(1, 50);        //Coin Insert Animation (3 times for longer animation)
  CoinInsertAnimation(1, 50);        //Coin Insert Animation (3 times for longer animation)
  MorphAnimation(100);               //Sparkle with CoinColor and PlayMorph Sound (higher number = more sparkle)
  PlayMorph();                       //Morph Sound for MorphAnimation
  Morph_Theme_Short_Rainbow_Long();  //Short press plays and stops Theme Song, long press shows Rainbow
  NoCoinSparkle(1000);               //sparkle animation when no coin is inserted but Morpher gets open (higher number = more sparkle)
  NoCoinSound();                     //Sound when no coin is inserted
  Morpher_Jammed();                  //Animation and Sound when Morpher is jammed but activate button is pressed (hold)
  Coin_Release();                    //Sound when the coin gets released
  Morpher_Closing();                 //Animation and Sound when Morpher gets closed
  NoCoinMorph();                     //Animation and Sound when no coin is inserted, Morpher gets open and activate button is pressed (hold)

  //CoinReleaseAnimation(); // TEST
}

//↓↓=============== Coin Color Selection ===============↓↓//
void coinColorSelection() {

  bool button1 = digitalRead(Coin_Button_1) == LOW;
  bool button2 = digitalRead(Coin_Button_2) == LOW;
  bool button3 = digitalRead(Coin_Button_3) == LOW;

  prevcoinColor = coinColor;  // assign old color before determining new color

  unsigned long currentMillis = millis();
  if (currentMillis - previousMillis &gt;= interval) {
    previousMillis = currentMillis;

    // Check for button combinations and assign the corresponding colors to coinColor
    if (button1 &amp;&amp; button2) {
      coinColor = CRGB(20, 0, 0);  //Tyranosaurus - red
      if (prevcoinColor != coinColor) {
        myDFPlayer.playMp3Folder(1);
      }
    } else if (button1 &amp;&amp; button3) {
      coinColor = CRGB(0, 20, 0);  //Dragonzord - green
      if (prevcoinColor != coinColor) {
        myDFPlayer.playMp3Folder(4);
      }
    } else if (button2 &amp;&amp; button3) {
      coinColor = CRGB(20, 0, 10);  //Pterodactyl - pink
      if (prevcoinColor != coinColor) {
        myDFPlayer.playMp3Folder(5);
      }
    } else if (button1) {
      coinColor = CRGB(20, 20, 0);  //Sabertoothtiger - yellow
      if (prevcoinColor != coinColor) {
        myDFPlayer.playMp3Folder(2);
      }
    } else if (button2) {
      coinColor = CRGB(0, 5, 5);  //Mastodon - "black" (skyblue)
      if (prevcoinColor != coinColor) {
        myDFPlayer.playMp3Folder(6);
      }
    } else if (button3) {
      coinColor = CRGB(0, 0, 20);  //Triceratops - blue
      if (prevcoinColor != coinColor) {
        myDFPlayer.playMp3Folder(3);
      }
    } else {
      coinColor = CRGB::Black;
    }
  }
}
//↑↑=============== Coin Color Selection ===============↑↑//

//↓↓=============== Coin insert LED Animation ===============↓↓//
void CoinInsertAnimation(int EyeSize, int SpeedDelay) {
  FastLED.setBrightness(255);
  if (prevcoinColor != coinColor) {

    byte red = coinColor.red;
    byte green = coinColor.green;
    byte blue = coinColor.blue;

    for (int i = 0; i &lt;= ((NUM_LEDS - EyeSize) / 2); i++) {
      fill_solid(leds, NUM_LEDS, CRGB::Black);
      FastLED.show();

      leds = CRGB(red / 10, green / 10, blue / 10);

      for (int j = 1; j &lt;= EyeSize; j++) {
        leds = CRGB(red, green, blue);
      }
      leds = CRGB(red / 10, green / 10, blue / 10);

      leds = CRGB(red / 10, green / 10, blue / 10);
      for (int j = 1; j &lt;= EyeSize; j++) {
        leds = CRGB(red, green, blue);
      }
      leds = CRGB(red / 10, green / 10, blue / 10);

      FastLED.show();
      delay(SpeedDelay);
    }

    for (int i = ((NUM_LEDS - EyeSize) / 2); i &gt;= 0; i--) {
      fill_solid(leds, NUM_LEDS, CRGB::Black);
      FastLED.show();

      leds = CRGB(red / 10, green / 10, blue / 10);
      for (int j = 1; j &lt;= EyeSize; j++) {
        leds = CRGB(red, green, blue);
      }
      leds = CRGB(red / 10, green / 10, blue / 10);

      leds = CRGB(red / 10, green / 10, blue / 10);
      for (int j = 1; j &lt;= EyeSize; j++) {
        leds = CRGB(red, green, blue);
      }
      leds = CRGB(red / 10, green / 10, blue / 10);

      FastLED.show();
      delay(SpeedDelay);

      fill_solid(leds, NUM_LEDS, CRGB::Black);
      FastLED.show();
    }
  }
}
//↑↑=============== Coin insert LED Animation ===============↑↑//

//↓↓=============== Morphing LED Animation ===============↓↓//

void MorphAnimation(fract8 chanceOfGlitter) {
  FastLED.setBrightness(255);

  bool button4 = digitalRead(Morph_Button) == LOW;
  bool button1 = digitalRead(Coin_Button_1) == LOW;
  bool button2 = digitalRead(Coin_Button_2) == LOW;
  bool button3 = digitalRead(Coin_Button_3) == LOW;

  if ((button4) &amp;&amp; (button1 | button2 | button3)) {

    if (!isRainbow) {
      fill_solid(leds, NUM_LEDS, CRGB::Black);
      FastLED.show();

      fill_solid(leds, NUM_LEDS, coinColor);
      if (random8() &lt; chanceOfGlitter) {
        leds += CHSV(0, 0, 255);
      }
      FastLED.show();


      //fill_solid(leds, NUM_LEDS, CRGB::Black); // probably not needed
      //FastLED.show();
    }
  }
}
//↑↑=============== Morphing LED Animation ===============↑↑//

//↓↓=============== Morphing Sound ===============↓↓//
void PlayMorph() {
  FastLED.setBrightness(40);

  bool button4 = digitalRead(Morph_Button) == LOW;
  bool button1 = digitalRead(Coin_Button_1) == LOW;
  bool button2 = digitalRead(Coin_Button_2) == LOW;
  bool button3 = digitalRead(Coin_Button_3) == LOW;

  if ((button4) &amp;&amp; (button1 | button2 | button3)) {
    if (!isPlayingMorph) {
      fill_solid(leds, NUM_LEDS, coinColor);
      FastLED.show();
      myDFPlayer.playMp3Folder(14);  // Morpher opens Sound
      delay(800);
      myDFPlayer.loopFolder(2);  // Morphing Sound
      delay(50);
      isPlayingMorph = true;
    }
  } else {
    if (isPlayingMorph) {
      myDFPlayer.stop();
      delay(50);
      isPlayingMorph = false;
    }
  }
}
//↑↑=============== Morphing Sound ===============↑↑//


//↓↓=============== Theme Song and Rainbow Test ===============↓↓//
void Morph_Theme_Short_Rainbow_Long() {
  FastLED.setBrightness(10);

  bool button1 = digitalRead(Coin_Button_1) == LOW;
  bool button2 = digitalRead(Coin_Button_2) == LOW;
  bool button3 = digitalRead(Coin_Button_3) == LOW;
  bool button4 = digitalRead(Morph_Button) == LOW;

  if ((digitalRead(Activate_Button) == LOW) &amp;&amp; (button1 | button2 | button3) &amp;&amp; button4) {
    if (buttonActive == false) {
      buttonActive = true;
      buttonTimer = millis();
    }

    if ((millis() - buttonTimer &gt; longPressTime) &amp;&amp; (longPressActive == false)) {
      longPressActive = true;
      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 (buttonActive == true) {
      if (longPressActive == true) {
        longPressActive = false;

      } else {
        if (millis() - buttonTimer &gt;= 500) {
          if (isPlayingTheme) {
            myDFPlayer.stop();
            delay(50);
            isPlayingTheme = false;
          } else {
            isPlayingTheme = true;
            myDFPlayer.playMp3Folder(10);  // ThemeSong
            delay(50);
          }
        }
      }
      buttonActive = false;
    }
  }
  if (button4 == LOW) {
    fill_solid(leds, NUM_LEDS, CRGB::Black);
    FastLED.show();
    isRainbow = false;
  } else if (isRainbow) {
    uint8_t thisHue = beat8(50, 255);
    uint8_t deltaHue = 255 / NUM_LEDS;
    fill_rainbow(leds, NUM_LEDS, thisHue, deltaHue);
    FastLED.show();
  }
}
//↑↑=============== Theme Song and Rainbow Test ===============↑↑//

//↓↓=============== NoCoin Animation Test ===============↓↓//

void NoCoinSparkle(fract8 chanceOfGlitter) {
  FastLED.setBrightness(255);

  bool button4 = digitalRead(Morph_Button) == LOW;
  bool button1 = digitalRead(Coin_Button_1) == HIGH;
  bool button2 = digitalRead(Coin_Button_2) == HIGH;
  bool button3 = digitalRead(Coin_Button_3) == HIGH;

  if ((button4) &amp;&amp; (button1 &amp;&amp; button2 &amp;&amp; button3)) {
    while (digitalRead(Busy_Pin) == LOW) {
      if (random8() &lt; chanceOfGlitter) {
        leds += CHSV(random8(), 255, 255);
      }
      FastLED.show();

      fill_solid(leds, NUM_LEDS, CRGB::Black);
      FastLED.show();
    }
  }
}
//↑↑=============== NoCoin Animation Test ===============↑↑//

//↓↓=============== NoCoin Sound ===============↓↓//
void NoCoinSound() {

  bool button4 = digitalRead(Morph_Button) == LOW;
  bool button1 = digitalRead(Coin_Button_1) == HIGH;
  bool button2 = digitalRead(Coin_Button_2) == HIGH;
  bool button3 = digitalRead(Coin_Button_3) == HIGH;

  if ((button4) &amp;&amp; (button1 &amp;&amp; button2 &amp;&amp; button3)) {
    if (!isPlayingNoCoin) {
      myDFPlayer.playMp3Folder(11);  // crackle Sound
      delay(50);
      isPlayingNoCoin = true;
    }
  } else {
    if (isPlayingNoCoin) {
      myDFPlayer.stop();
      delay(50);
      isPlayingNoCoin = false;
    }
  }
}
//↑↑=============== NoCoin Sound ===============↑↑//

//↓↓=============== Morpher Jammed ===============↓↓//
void Morpher_Jammed() {
  FastLED.setBrightness(10);

  bool button4 = digitalRead(Morph_Button) == HIGH;

  if ((digitalRead(Activate_Button) == LOW) &amp;&amp; button4) {
    if (buttonActive2 == false) {
      buttonActive2 = true;
      buttonTimer2 = millis();
    }
    if ((millis() - buttonTimer2 &gt; longPressTime2) &amp;&amp; (longPressActive2 == false)) {
      longPressActive2 = true;
      myDFPlayer.playMp3Folder(8);  // Zordon Speech
      delay(50);
      while (digitalRead(Busy_Pin) == LOW) {
        uint8_t thisHue = beat8(100, 255);
        uint8_t deltaHue = 255 / NUM_LEDS;
        fill_rainbow(leds, NUM_LEDS, thisHue, deltaHue);
        FastLED.show();
      }
    }
  } else {
    fill_solid(leds, NUM_LEDS, CRGB::Black);
    FastLED.show();
    if (buttonActive2 == true) {
      if (longPressActive2 == true) {
        longPressActive2 = false;
      }
      buttonActive2 = false;
    }
  }
}
//↑↑=============== Morpher Jammed ===============↑↑//

//↓↓=============== Coin Release Test ===============↓↓//
void Coin_Release() {
  FastLED.setBrightness(40);

  bool button1 = digitalRead(Coin_Button_1) == LOW;
  bool button2 = digitalRead(Coin_Button_2) == LOW;
  bool button3 = digitalRead(Coin_Button_3) == LOW;

  if (button1 | button2 | button3) {
    if (buttonActive3 == false) {
      buttonActive3 = true;
      buttonTimer3 = millis();
    }
  } else {
    if (buttonActive3 == true) {
      if (longPressActive3 == true) {
        longPressActive3 = false;
      } else {
        myDFPlayer.playMp3Folder(12);  // Power Rangers Beep
        delay(50);

        while (digitalRead(Busy_Pin) == LOW) {
          switch (state) {
            case 0:  // On state 1
              for (int i = 0; i &lt; NUM_LEDS; i++) {
                leds = coinColor;  // Set all LEDs to white
              }
              FastLED.show();  // Update LEDs
              delay(onTime1);
              state = 1;  // Transition to next state
              break;

            case 1:  // Off state 1
              for (int i = 0; i &lt; NUM_LEDS; i++) {
                leds = CRGB::Black;  // Set all LEDs to black
              }
              FastLED.show();  // Update LEDs
              delay(offTime1);
              state = 2;  // Transition to next state
              break;

            case 2:  // On state 2
              for (int i = 0; i &lt; NUM_LEDS; i++) {
                leds = coinColor;  // Set all LEDs to blue
              }
              FastLED.show();  // Update LEDs
              delay(onTime2);
              state = 3;  // Transition to next state
              break;

            case 3:  // Off state 2
              for (int i = 0; i &lt; NUM_LEDS; i++) {
                leds = CRGB::Black;  // Set all LEDs to black
              }
              FastLED.show();  // Update LEDs
              delay(offTime2);
              state = 4;  // Transition to the first state (on state)
              break;

            case 4:  // On state 3
              for (int i = 0; i &lt; NUM_LEDS; i++) {
                leds = coinColor;  // Set all LEDs to blue
              }
              FastLED.show();  // Update LEDs
              delay(onTime3);
              state = 5;  // Transition to next state
              break;

            case 5:  // Off state 3
              for (int i = 0; i &lt; NUM_LEDS; i++) {
                leds = CRGB::Black;  // Set all LEDs to black
              }
              FastLED.show();  // Update LEDs
              delay(offTime3);
              state = 6;  // Transition to the first state (on state)
              break;

            case 6:  // On state 4
              for (int i = 0; i &lt; NUM_LEDS; i++) {
                leds = coinColor;  // Set all LEDs to blue
              }
              FastLED.show();  // Update LEDs
              delay(onTime4);
              state = 7;  // Transition to next state
              break;

            case 7:  // Off state 4
              for (int i = 0; i &lt; NUM_LEDS; i++) {
                leds = CRGB::Black;  // Set all LEDs to black
              }
              FastLED.show();  // Update LEDs
              delay(offTime4);
              state = 8;  // Transition to the first state (on state)
              break;

            case 8:  // On state 5
              for (int i = 0; i &lt; NUM_LEDS; i++) {
                leds = coinColor;  // Set all LEDs to blue
              }
              FastLED.show();  // Update LEDs
              delay(onTime5);
              state = 9;  // Transition to next state
              break;

            case 9:  // Off state 5
              for (int i = 0; i &lt; NUM_LEDS; i++) {
                leds = CRGB::Black;  // Set all LEDs to black
              }
              FastLED.show();  // Update LEDs
              delay(offTime5);
              state = 10;  // Transition to the first state (on state)
              break;

            case 10:  // On state 6
              for (int i = 0; i &lt; NUM_LEDS; i++) {
                leds = coinColor;  // Set all LEDs to blue
              }
              FastLED.show();  // Update LEDs
              delay(onTime6);
              state = 11;  // Transition to next state
              break;

            case 11:  // Off state 6
              for (int i = 0; i &lt; NUM_LEDS; i++) {
                leds = CRGB::Black;  // Set all LEDs to black
              }
              FastLED.show();  // Update LEDs
              delay(offTime6);
              state = 0;  // Transition to the first state (on state)
              break;
          }
        }
      }
      buttonActive3 = false;
    }
  }
}
//↑↑=============== Coin Release Test ===============↑↑//

//↓↓=============== Morpher Closing Test ===============↓↓//

void Morpher_Closing() {
  FastLED.setBrightness(60);

  bool button4 = digitalRead(Morph_Button) == LOW;

  if (button4) {
    if (buttonActive4 == false) {
      buttonActive4 = true;
      buttonTimer4 = millis();
    }
  } else {
    if (buttonActive4 == true) {
      if (longPressActive4 == true) {
        longPressActive4 = false;
      } else {
        myDFPlayer.playMp3Folder(7);  // Morpher Closing Sound
        delay(50);
        while (digitalRead(Busy_Pin) == LOW) {
          fill_solid(leds, NUM_LEDS, coinColor);
          FastLED.show();
        }
      }
      buttonActive4 = false;
    }
  }
}
//↑↑=============== Morpher Closing Test ===============↑↑//

//↓↓=============== No Coin Morph ===============↓↓//
void NoCoinMorph() {

  bool button1 = digitalRead(Coin_Button_1) == HIGH;
  bool button2 = digitalRead(Coin_Button_2) == HIGH;
  bool button3 = digitalRead(Coin_Button_3) == HIGH;
  bool button4 = digitalRead(Morph_Button) == LOW;

  if ((digitalRead(Activate_Button) == LOW) &amp;&amp; (button1 &amp;&amp; button2 &amp;&amp; button3) &amp;&amp; button4) {
    if (buttonActive5 == false) {
      buttonActive5 = true;
      buttonTimer5 = millis();
    }
    if ((millis() - buttonTimer5 &gt; longPressTime5) &amp;&amp; (longPressActive5 == false)) {
      longPressActive5 = true;
      myDFPlayer.playMp3Folder(13);  // Alarm Alpha 5
      delay(50);
      while (digitalRead(Busy_Pin) == LOW) {

        fill_solid(leds, NUM_LEDS, CHSV(0, 255, 30));
        float breath = (exp(sin(millis() / 430.0 * PI)) - 0.36787944) * 108.0;
        FastLED.setBrightness(breath);
        FastLED.show();
      }
    }
  } else {
    fill_solid(leds, NUM_LEDS, CRGB::Black);
    FastLED.show();
    if (buttonActive5 == true) {
      if (longPressActive5 == true) {
        longPressActive5 = false;
      }
      buttonActive5 = false;
    }
  }
}
//↑↑=============== No Coin Morph ===============↑↑//
</pre>
<p><br /><br /></p>]]></content:encoded>
						                            <category domain="https://www.tweaking4all.com/forum/arduino/">Arduino</category>                        <dc:creator>Trace</dc:creator>
                        <guid isPermaLink="true">https://www.tweaking4all.com/forum/arduino/fastled-light-effects-for-power-rangers/paged/5/#post-5312</guid>
                    </item>
				                    <item>
                        <title>RE: FastLED Light effects for Power Rangers</title>
                        <link>https://www.tweaking4all.com/forum/arduino/fastled-light-effects-for-power-rangers/paged/5/#post-5310</link>
                        <pubDate>Tue, 09 Jan 2024 21:17:05 +0000</pubDate>
                        <description><![CDATA[@Hans Hi there Hans, how are you? I hope everything is good?Sometimes, solutions can be very easy and you cant see the forest for the trees. My problem was the need to have the Activate_Butt...]]></description>
                        <content:encoded><![CDATA[<p>@Hans Hi there Hans, how are you? I hope everything is good?<br /><br />Sometimes, solutions can be very easy and you cant see the forest for the trees. My problem was the need to have the Activate_Button being pressed for a moment before executing anything. The code as it was, just played the mp3 as soon as you have clicke the button.<br /><br />The obvious solution was to put in a second very easy line. So this part:</p>
<pre contenteditable="false">else {
        if (isPlayingTheme) {
          myDFPlayer.stop();
          delay(50);
          isPlayingTheme = false;
        } else {
          isPlayingTheme = true;
          myDFPlayer.playMp3Folder(10);  // ThemeSong
          delay(50);
        }
      }</pre>
<p>Becomes this:</p>
<pre contenteditable="false">else {
        if (millis() - buttonTimer &gt; 500) {
        if (isPlayingTheme) {
          myDFPlayer.stop();
          delay(50);
          isPlayingTheme = false;
        } else {
          isPlayingTheme = true;
          myDFPlayer.playMp3Folder(10);  // ThemeSong
          delay(50);
        }
      }
      }</pre>
<p> </p>
<p>So just adding a if statement with millis - buttonTimer was all I had to do to be able to push the button shortly (for a mechanical action) without having the mp3 start playing. And pushing it a bit longer for the mp3 to play. The longHold function is still working.<br /><br />I hope I havent made any mistakes and the timer works fine (it looks good so far).<br /><br />So there are only two or three problems left.<br /><br />The first one is still the delay thing for the coinColorSelection. Just having some kind of delay (non blocking) to have some time to push the color buttons, before InsertAnimation gets started. As it is right now, its not the best solution. Sometimes the millis-function dont get recognized and the color gets selected as soon as I hit the button, no matter if I hit another button just a few milliseconds after (which is the problem of course).<br /><br />The second one is the problem in reverse. As soon as two buttons are pressed (button1 &amp;&amp; button2 for example) and I release both, but slightly after each other, then for a blink of an eye, a single button is still pressed and the code recognizes it as a color choice.<br /><br />And the third problem is still a button release function. For example: releasing button1 &amp;&amp; button2 should trigger something. Just a mp3 or maybe another animation. But for this, problem 1 and 2 needs to be solved, obviously.<br />Thats why this is just an option.</p>]]></content:encoded>
						                            <category domain="https://www.tweaking4all.com/forum/arduino/">Arduino</category>                        <dc:creator>Trace</dc:creator>
                        <guid isPermaLink="true">https://www.tweaking4all.com/forum/arduino/fastled-light-effects-for-power-rangers/paged/5/#post-5310</guid>
                    </item>
				                    <item>
                        <title>RE: FastLED Light effects for Power Rangers</title>
                        <link>https://www.tweaking4all.com/forum/arduino/fastled-light-effects-for-power-rangers/paged/5/#post-5304</link>
                        <pubDate>Sat, 06 Jan 2024 16:47:07 +0000</pubDate>
                        <description><![CDATA[Thanks Hans for letting me know. But please dont feel rushed.]]></description>
                        <content:encoded><![CDATA[
<p></p>
<p>Hi there Hans, how are you doing?</p>
<p></p>
<p>Haven't forgotten about you &#x1f609; - just a little busy these last few days.<br />Will try to get back as soon possible! </p>
<p></p>
<p> </p>
<p>Thanks Hans for letting me know. But please dont feel rushed.</p>
<p> </p>]]></content:encoded>
						                            <category domain="https://www.tweaking4all.com/forum/arduino/">Arduino</category>                        <dc:creator>Trace</dc:creator>
                        <guid isPermaLink="true">https://www.tweaking4all.com/forum/arduino/fastled-light-effects-for-power-rangers/paged/5/#post-5304</guid>
                    </item>
				                    <item>
                        <title>RE: FastLED Light effects for Power Rangers</title>
                        <link>https://www.tweaking4all.com/forum/arduino/fastled-light-effects-for-power-rangers/paged/5/#post-5302</link>
                        <pubDate>Sat, 06 Jan 2024 13:19:03 +0000</pubDate>
                        <description><![CDATA[Haven&#039;t forgotten about you &#x1f609; - just a little busy these last few days.Will try to get back as soon possible!]]></description>
                        <content:encoded><![CDATA[<p></p>
<p>Hi there Hans, how are you doing?</p>
<p></p>
<p>Haven't forgotten about you &#x1f609; - just a little busy these last few days.<br />Will try to get back as soon possible! </p>]]></content:encoded>
						                            <category domain="https://www.tweaking4all.com/forum/arduino/">Arduino</category>                        <dc:creator>Hans</dc:creator>
                        <guid isPermaLink="true">https://www.tweaking4all.com/forum/arduino/fastled-light-effects-for-power-rangers/paged/5/#post-5302</guid>
                    </item>
				                    <item>
                        <title>RE: FastLED Light effects for Power Rangers</title>
                        <link>https://www.tweaking4all.com/forum/arduino/fastled-light-effects-for-power-rangers/paged/5/#post-5289</link>
                        <pubDate>Wed, 03 Jan 2024 23:15:08 +0000</pubDate>
                        <description><![CDATA[@hans Hi there Hans, how are you doing? I did not look up about the delay thing and button release detection. Because I have another task, which I can probably solve mechanically, but would ...]]></description>
                        <content:encoded><![CDATA[<p>@hans Hi there Hans, how are you doing? <br /><br />I did not look up about the delay thing and button release detection. Because I have another task, which I can probably solve mechanically, but would prefer it within the code.<br /><br />It´s about the short button and hold button press function. I have implemented the little function I have found earlier which detects both, short presses and long presses. It works fine. <br /><br />The function detects short button presses by the release of the button. Therefore it will get executed immediately by the shortest press.</p>
<p>But I would like to have it so that even the short press events needs the button to be pressed for a moment before executing. Im sure it is possible by changing some logic within the code but you know how bad I am at this kind of logic :D</p>
<p>I will post both codes, the original one and mine.</p>
<p>Here is the original code:<br /><br /></p>
<pre contenteditable="false">int LED1 = 12;
int LED2 = 13;
int button = 3;

boolean LED1State = false;
boolean LED2State = false;

long buttonTimer = 0;
long longPressTime = 250;

boolean buttonActive = false;
boolean longPressActive = false;

void setup() {

	pinMode(LED1, OUTPUT);
	pinMode(LED2, OUTPUT);
	pinMode(button, INPUT);

}

void loop() {

	if (digitalRead(button) == HIGH) {
		if (buttonActive == false) {
			buttonActive = true;
			buttonTimer = millis();
		}
		if ((millis() - buttonTimer &gt; longPressTime) &amp;&amp; (longPressActive == false)) {
			longPressActive = true;
			LED1State = !LED1State;
			digitalWrite(LED1, LED1State);
		}
	} else {

		if (buttonActive == true) {
			if (longPressActive == true) {
				longPressActive = false;
			} else {
				LED2State = !LED2State;
				digitalWrite(LED2, LED2State);
			}
			buttonActive = false;
		}
	}
}</pre>
<p> </p>
<p>And here is mine with led animation and sound:</p>
<pre contenteditable="false">long buttonTimer = 0;
long longPressTime = 3000;

boolean buttonActive = false;
boolean longPressActive = false;

//--&gt;setup and void loop&lt;--//

void Morph_Theme_Short_Rainbow_Long() {
  FastLED.setBrightness(10);

  int button1 = digitalRead(Coin_Button_1) == LOW;
  int button2 = digitalRead(Coin_Button_2) == LOW;
  int button3 = digitalRead(Coin_Button_3) == LOW;

  if ((digitalRead(Activate_Button) == LOW) &amp;&amp; (button1 | button2 | button3)) {
    if (buttonActive == false) {
      buttonActive = true;
      buttonTimer = millis();
    }

    if ((millis() - buttonTimer &gt; longPressTime) &amp;&amp; (longPressActive == false)) {
      longPressActive = true;
      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 (buttonActive == true) {
      if (longPressActive == true) {
        longPressActive = false;

      } else {
        if (isPlayingTheme) {
          myDFPlayer.stop();
          delay(50);
          isPlayingTheme = false;
        } else {
          isPlayingTheme = true;
          myDFPlayer.playMp3Folder(10);  // ThemeSong
          delay(50);
        }
      }
      buttonActive = false;
    }
  }
  if (isRainbow) {
    uint8_t thisHue = beat8(50, 255);
    uint8_t deltaHue = 255 / NUM_LEDS;
    fill_rainbow(leds, NUM_LEDS, thisHue, deltaHue);
    FastLED.show();
  }
}</pre>
<p> </p>]]></content:encoded>
						                            <category domain="https://www.tweaking4all.com/forum/arduino/">Arduino</category>                        <dc:creator>Trace</dc:creator>
                        <guid isPermaLink="true">https://www.tweaking4all.com/forum/arduino/fastled-light-effects-for-power-rangers/paged/5/#post-5289</guid>
                    </item>
				                    <item>
                        <title>RE: FastLED Light effects for Power Rangers</title>
                        <link>https://www.tweaking4all.com/forum/arduino/fastled-light-effects-for-power-rangers/paged/5/#post-5283</link>
                        <pubDate>Mon, 01 Jan 2024 22:41:43 +0000</pubDate>
                        <description><![CDATA[@hans Hi Hans, I also wish you a happy new year and I hope everything will go well for you and your family!For the two challanges. I think I can find a way for button release detection like ...]]></description>
                        <content:encoded><![CDATA[@hans Hi Hans, I also wish you a happy new year and I hope everything will go well for you and your family!<br /><br />For the two challanges. I think I can find a way for button release detection like the way we detect quick button presses and button hold. Or using a library for this specific action may be the easiest way?!<br /><br />And for the delay problem, the arduino-timer looks interesting but I also need to read about it and play around for some time. It sounds like an easy task. All we need is to wait a lil moment (non blocking) after buttons are pressed, before executing a void. But like it is with reality, sounding easy does not mean it is easy.<br /><br />Plus I try to find a way to have something being executed for as long as a mp3 file is being played (while loop?).]]></content:encoded>
						                            <category domain="https://www.tweaking4all.com/forum/arduino/">Arduino</category>                        <dc:creator>Trace</dc:creator>
                        <guid isPermaLink="true">https://www.tweaking4all.com/forum/arduino/fastled-light-effects-for-power-rangers/paged/5/#post-5283</guid>
                    </item>
				                    <item>
                        <title>RE: FastLED Light effects for Power Rangers</title>
                        <link>https://www.tweaking4all.com/forum/arduino/fastled-light-effects-for-power-rangers/paged/4/#post-5282</link>
                        <pubDate>Sun, 31 Dec 2023 13:07:56 +0000</pubDate>
                        <description><![CDATA[Just a quick:
 &#x1f378; &#x1f942; Happy New Year! &#x1f44d; &#x1f37e; 
... for you and your family!]]></description>
                        <content:encoded><![CDATA[<div style="text-align: center">Just a quick:</div>
<div style="text-align: center"><span style="font-size: 18pt"> &#x1f378; &#x1f942; <span style="color: #339966">Happy</span> <span style="color: #ff0000">New</span> <span style="color: #0000ff">Year</span>! &#x1f44d; &#x1f37e; </span></div>
<div style="text-align: center">... for you and your family!</div>]]></content:encoded>
						                            <category domain="https://www.tweaking4all.com/forum/arduino/">Arduino</category>                        <dc:creator>Hans</dc:creator>
                        <guid isPermaLink="true">https://www.tweaking4all.com/forum/arduino/fastled-light-effects-for-power-rangers/paged/4/#post-5282</guid>
                    </item>
				                    <item>
                        <title>RE: FastLED Light effects for Power Rangers</title>
                        <link>https://www.tweaking4all.com/forum/arduino/fastled-light-effects-for-power-rangers/paged/4/#post-5266</link>
                        <pubDate>Wed, 27 Dec 2023 10:55:07 +0000</pubDate>
                        <description><![CDATA[Hi Trace!
Hope you had a good Christmas - as you can imagine, it was a little busy overhere now with moms situation.I see that you have resolved some challenges: well done! &#x1f44d; 
As f...]]></description>
                        <content:encoded><![CDATA[<p>Hi Trace!</p>
<p>Hope you had a good Christmas - as you can imagine, it was a little busy overhere now with moms situation.<br />I see that you have resolved some challenges: well done! &#x1f44d; </p>
<p>As for the two challenges;</p>
<p>Bot these issues, are something where we will probably need to work around the lack of multitasking on an Arduino. <br />I assume you're using an Arduino Uno. (correct?)</p>
<p>Doing two things at the same time can be done in several ways:<br />Either we have two cores (which we don't), or we have to figure a way to switch back and forth often (feels sloppy) or we try to utilize interrupts (tricky).</p>
<p>If I think about interrupts: An interrupt can be fired under several conditions. (see "<a href="https://www.tweaking4all.com/hardware/arduino/arduino-all-ledstrip-effects-in-one/#Challenge3Interruptaneffectandcatchthatbutton" target="_blank" rel="noopener">All LED Effects project - Catching the button</a>" or the <a href="https://www.arduino.cc/reference/en/language/functions/external-interrupts/attachinterrupt/" target="_blank" rel="noopener">Arduino Interrupt documentation</a>).</p>
<p>There are several modi we can use:</p>
<ul>
<li>LOW to trigger the interrupt whenever the pin is low,</li>
<li>CHANGE to trigger the interrupt whenever the pin changes value,</li>
<li>RISING to trigger when the pin goes from low to high,</li>
<li>FALLING for when the pin goes from high to low.</li>
</ul>
<p>Newer or more advanced Arduinos, like the Due, Zero and MKR1000 boards allow also:</p>
<ul>
<li>HIGH to trigger the interrupt whenever the pin is high.</li>
</ul>
<p>So in our case, we can consider using "CHANGE" to register button state changes (being pressed, or released, and measure the time between the changes). Worth thinking about and experimenting with I would say.</p>
<p>For example, when we press a button, we log the time it has been pressed, etc etc.<br />We could consider looking at the <a href="https://www.arduino.cc/reference/en/libraries/arduino-timer/" target="_blank" rel="noopener">Arduino Timer library</a>, which waits for the delay you have in mind and see if the state of the button still matches what you're looking for.</p>
<p>I can imagine this taking a bit of reading and experimenting - I'd have to do the same thing to get a feel for it.</p>]]></content:encoded>
						                            <category domain="https://www.tweaking4all.com/forum/arduino/">Arduino</category>                        <dc:creator>Hans</dc:creator>
                        <guid isPermaLink="true">https://www.tweaking4all.com/forum/arduino/fastled-light-effects-for-power-rangers/paged/4/#post-5266</guid>
                    </item>
				                    <item>
                        <title>RE: FastLED Light effects for Power Rangers</title>
                        <link>https://www.tweaking4all.com/forum/arduino/fastled-light-effects-for-power-rangers/paged/4/#post-5264</link>
                        <pubDate>Sat, 23 Dec 2023 23:29:18 +0000</pubDate>
                        <description><![CDATA[@hans Hi Hans, sorry for &quot;spamming&quot;! You got more importent things on your mind. And I dont want to take more time from you than &quot;needed&quot;. So thats why I try to figure stuff out by myself, b...]]></description>
                        <content:encoded><![CDATA[<p>@hans Hi Hans, sorry for "spamming"! You got more importent things on your mind. And I dont want to take more time from you than "needed". So thats why I try to figure stuff out by myself, but run into problems very often due to my basic programming skills.<br /><br />But I got some great (unimportant) news.</p>
<p>I found a way to make things working, with just some minor flaws. Here is the full working code so far (what do you think?):<br /><br /></p>
<pre contenteditable="false">#define FASTLED_INTERNAL  // just used to mute the Pragma messages when compiling
#include "FastLED.h"
#include &lt;EEPROM.h&gt;

#define PIN 6
#define NUM_LEDS 26

CRGB leds;

#define Coin_Button_1 3    // Coin button 1
#define Coin_Button_2 4    // Coin button 2
#define Coin_Button_3 5    // Coin button 3
#define Morph_Button 7     // Morph button
#define Activate_Button 8  // Activate button
//#define Test_Button 9

CRGB prevcoinColor = CRGB::Black;
CRGB coinColor = CRGB::Black;

boolean isPlayingMorph = false;
boolean isPlayingTheme = false;
boolean isRainbow = false;

//↓↓=============== Button Selection Delay (not working correctly) ===============↓↓//
unsigned long previousMillis = 0;
const long interval = 1000;
//↑↑=============== Button Selection Delay (not working correctly) ===============↑↑//


//↓↓=============== Theme_Short_Rainbow_Long ===============↓↓//
long buttonTimer = 0;
long longPressTime = 3000;

boolean buttonActive = false;
boolean longPressActive = false;
//↑↑=============== Theme_Short_Rainbow_Long ===============↑↑//


//↓↓=============== DFPlayer mini initiation ===============↓↓//
#include "Arduino.h"
#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"

SoftwareSerial mySoftwareSerial(10, 11);  // RX, TX
DFRobotDFPlayerMini myDFPlayer;
void printDetail(uint8_t type, int value);
//↑↑=============== DFPlayer mini initiation ===============↑↑//


void setup() {
  FastLED.addLeds&lt;WS2811, PIN, GRB&gt;(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
  //FastLED.setBrightness(30);   //set global brightness -&gt; is off due to brightness settings for each void
  fill_solid(leds, NUM_LEDS, CRGB::Black);
  FastLED.show();

  pinMode(Coin_Button_1, INPUT_PULLUP);     //button for Coin recognition
  pinMode(Coin_Button_2, INPUT_PULLUP);     //button for Coin recognition
  pinMode(Coin_Button_3, INPUT_PULLUP);     //button for Coin recognition
  pinMode(Morph_Button, INPUT_PULLUP);      //button for when Morpher is opened 
  pinMode(Activate_Button, INPUT_PULLUP);   //button for playing Theme Song (click) and rainbow animation (hold)
  //pinMode(Test_Button, INPUT_PULLUP);

  //↓↓=============== DFPlayer mini setup ===============↓↓/
  mySoftwareSerial.begin(9600);
  Serial.begin(115200);
  if (!myDFPlayer.begin(mySoftwareSerial)) {  //Use softwareSerial to communicate with mp3.
    while (true)
      ;
  }
  myDFPlayer.setTimeOut(500);  //Set serial communictaion time out 500ms
  myDFPlayer.volume(1);        //Set volume value (0~30).
  myDFPlayer.EQ(DFPLAYER_EQ_BASS);
  myDFPlayer.outputDevice(DFPLAYER_DEVICE_SD);
}
//↑↑=============== DFPlayer mini setup ===============↑↑//

void loop() {

  coinColorSelection();              //Coin Insert Color Recognition
  CoinInsertAnimation(1, 50);        //Coin Insert Animation (2 times for longer animation)
  CoinInsertAnimation(1, 50);        //Coin Insert Animation (2 times for longer animation)
  MorphAnimation(30);                //Sparkle with CoinColor and PlayMorph Sound
  PlayMorph();                       //Morph Sound for MorphAnimation
  Morph_Theme_Short_Rainbow_Long();  //Short press plays and stops Theme Song, long press shows Rainbow
}

//↓↓=============== Coin Color Selection ===============↓↓//
void coinColorSelection() {

  int button1 = digitalRead(Coin_Button_1) == LOW;
  int button2 = digitalRead(Coin_Button_2) == LOW;
  int button3 = digitalRead(Coin_Button_3) == LOW;

  prevcoinColor = coinColor;  // assign old color before determining new color

  unsigned long currentMillis = millis();
  if (currentMillis - previousMillis &gt;= interval) {
    previousMillis = currentMillis;

    // Check for button combinations and assign the corresponding colors to coinColor
    if (button1 &amp;&amp; button2) {
      coinColor = CRGB(20, 0, 0);           //Tyranosaurus - red
      if (prevcoinColor != coinColor) {
        myDFPlayer.playMp3Folder(1);
      }
    } else if (button1 &amp;&amp; button3) {
      coinColor = CRGB(0, 20, 0);           //Dragonzord - green
      if (prevcoinColor != coinColor) {
        myDFPlayer.playMp3Folder(4);
      }
    } else if (button2 &amp;&amp; button3) {
      coinColor = CRGB(20, 0, 10);          //Pterodactyl - pink
      if (prevcoinColor != coinColor) {
        myDFPlayer.playMp3Folder(5);
      }
    } else if (button1) {
      coinColor = CRGB(20, 20, 0);          //Sabertoothtiger - yellow
      if (prevcoinColor != coinColor) {
        myDFPlayer.playMp3Folder(2);
      }
    } else if (button2) {
      coinColor = CRGB(0, 5, 5);            //Mastodon - "black" (skyblue)
      if (prevcoinColor != coinColor) {
        myDFPlayer.playMp3Folder(6);
      }
    } else if (button3) {
      coinColor = CRGB(0, 0, 20);           //Triceratops
      if (prevcoinColor != coinColor) {
        myDFPlayer.playMp3Folder(3);
      }
    } else {
      coinColor = CRGB::Black;
    }
  }
}
//↑↑=============== Coin Color Selection ===============↑↑//

//↓↓=============== Coin insert LED Animation ===============↓↓//
void CoinInsertAnimation(int EyeSize, int SpeedDelay) {
FastLED.setBrightness(255);
  if (prevcoinColor != coinColor) {

    byte red = coinColor.red;
    byte green = coinColor.green;
    byte blue = coinColor.blue;

    for (int i = 0; i &lt;= ((NUM_LEDS - EyeSize) / 2); i++) {
      fill_solid(leds, NUM_LEDS, CRGB::Black);
      FastLED.show();

      leds = CRGB(red / 10, green / 10, blue / 10);

      for (int j = 1; j &lt;= EyeSize; j++) {
        leds = CRGB(red, green, blue);
      }
      leds = CRGB(red / 10, green / 10, blue / 10);

      leds = CRGB(red / 10, green / 10, blue / 10);
      for (int j = 1; j &lt;= EyeSize; j++) {
        leds = CRGB(red, green, blue);
      }
      leds = CRGB(red / 10, green / 10, blue / 10);

      FastLED.show();
      delay(SpeedDelay);
    }

    for (int i = ((NUM_LEDS - EyeSize) / 2); i &gt;= 0; i--) {
      fill_solid(leds, NUM_LEDS, CRGB::Black);
      FastLED.show();

      leds = CRGB(red / 10, green / 10, blue / 10);
      for (int j = 1; j &lt;= EyeSize; j++) {
        leds = CRGB(red, green, blue);
      }
      leds = CRGB(red / 10, green / 10, blue / 10);

      leds = CRGB(red / 10, green / 10, blue / 10);
      for (int j = 1; j &lt;= EyeSize; j++) {
        leds = CRGB(red, green, blue);
      }
      leds = CRGB(red / 10, green / 10, blue / 10);

      FastLED.show();
      delay(SpeedDelay);

      fill_solid(leds, NUM_LEDS, CRGB::Black);
      FastLED.show();
    }
  }
}
//↑↑=============== Coin insert LED Animation ===============↑↑//

//↓↓=============== Morphing LED Animation ===============↓↓//

void MorphAnimation(fract8 chanceOfGlitter) {
FastLED.setBrightness(255);
  int button4 = digitalRead(Morph_Button) == LOW;

  if (button4) {

    if (!isRainbow) {
      fill_solid(leds, NUM_LEDS, CRGB::Black);
      FastLED.show();

      fill_solid(leds, NUM_LEDS, coinColor);
      if (random8() &lt; chanceOfGlitter) {
        leds += CHSV(0, 0, 255);
      }
      FastLED.show();

      fill_solid(leds, NUM_LEDS, CRGB::Black);
      FastLED.show();
    }
  }
}
//↑↑=============== Morphing LED Animation ===============↑↑//

//↓↓=============== Morphing Sound ===============↓↓//
void PlayMorph() {

  int button4 = digitalRead(Morph_Button) == LOW;

  if (button4) {
    if (!isPlayingMorph) {       
      myDFPlayer.loopFolder(2);  // morphing Sound
      delay(50);
      isPlayingMorph = true;
    }
  } else {  
    if (isPlayingMorph) {
      myDFPlayer.stop();
      delay(50);
      isPlayingMorph = false;
    }
  }
}
//↑↑=============== Morphing Sound ===============↑↑//


//↓↓=============== Theme Song Test ===============↓↓//

void Morph_Theme_Short_Rainbow_Long() {
FastLED.setBrightness(10);
  if (digitalRead(Activate_Button) == LOW) {
    if (buttonActive == false) {
      buttonActive = true;
      buttonTimer = millis();
    }

    if ((millis() - buttonTimer &gt; longPressTime) &amp;&amp; (longPressActive == false)) {
      longPressActive = true;
      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 (buttonActive == true) {
      if (longPressActive == true) {
        longPressActive = false;

      } else {
        if (isPlayingTheme) {  
          myDFPlayer.stop();   
          delay(50);
          isPlayingTheme = false;
        } else {
          isPlayingTheme = true;  
          myDFPlayer.playMp3Folder(10);   // ThemeSong
          delay(50);
        }
      }
      buttonActive = false;
    }
  }
  if (isRainbow) {
    uint8_t thisHue = beat8(50, 255);
    uint8_t deltaHue = 255 / NUM_LEDS;
    fill_rainbow(leds, NUM_LEDS, thisHue, deltaHue);
    FastLED.show();
  }
}
</pre>
<p>I have replaced the button click and hold function with a "smaller" version. This version does not need millis in the loop, therefore it does not interfere with the morph animation (which has created the rainbow flicker issue).<br /><br />Also changed the morph animation void so that it turns off when rainbow is on, otherwise there was a overlaping of those two animations and it did not look good.<br /><br />One minor flaw is a very subtle flickering within the morph animation sparkle. But it is not visible under some diffuse material.<br /><br />The brightness problem is also solved. It was a misconception on my side. I just had set the brightness to a lower value for the coin and morph animation. But it needs to be set to 255 and is then handled by the CRGB values. This way I can set the brightness within every void and reducing the rainbow brightness without reducing any others effects brightness.<br /><br />There are just two things left:</p>
<p>First is, how to set a delay time for the button recognition for not simultaniously pushed coin buttons? (the existing one does not work well)</p>
<p>Second is, finding a implementable function for button release detection, so I can have an animation and sound for when a coin is released or the morpher gets closed and so on.<br /><br />But most important: I wish you, your mom and your family a blessed Christmas. Get some peaceful days.</p>]]></content:encoded>
						                            <category domain="https://www.tweaking4all.com/forum/arduino/">Arduino</category>                        <dc:creator>Trace</dc:creator>
                        <guid isPermaLink="true">https://www.tweaking4all.com/forum/arduino/fastled-light-effects-for-power-rangers/paged/4/#post-5264</guid>
                    </item>
							        </channel>
        </rss>
		