Hi, everyone
I'm attempting to make a pair of cyberpunk goggles for myself and want to light them up with 8 RGB LEDs set to orange color. My end goal is to have these LEDs switched on and off with a button switch and for them to fade up in brightness quickly and then fade back down to a medium brightness in order to replicated a "powering on" effect, then to fade between subtle changes in the hue from red to yellow and back on a slow loop.
Currently I've been able to write a program that, after pushing a button switch, will put the LEDs through the initial fade up/fade down sequence and then hold the luminescence stable until the button switch is pushed again.
The problem I'm having is that if I attempt to put them into a "for" loop beyond the "power up" sequence so that they pulse, I'm unable to get the LEDs to exit out of the loop when I press the button switch to turn the LEDs off. As it is I am unable to get the "power up" sequence to abort if I press the button switch again; I have to wait until it resolves.
Model used: Arduino MEGA 2560
Whatever help you offer is very much appreciated. Here is my code, minus the pulsing "for" loop because I can't exit it anyway:
int SWITCH = 3;
int redLED = 6;
int greenLED = 9;Â Â Â Â Â Â Â Â
bool cat = true;   //named cat because booleans remind me a little of Schrödinger's cat :P
void setup()
{
 pinMode(SWITCH, INPUT_PULLUP);
 pinMode(redLED, OUTPUT);
 pinMode(greenLED, OUTPUT);
}
void loop()
{
 power_on_effect();
}
void power_on_effect()
{
 if (digitalRead(SWITCH) == LOW && cat == true)
 {
  int redValue = 0;
  int greenValue = 0;
 Â
  for (int fadeValue = 0 ; fadeValue <= 249; fadeValue += 10)
  {
   redValue += 10;
   greenValue = (redValue * .12);
   analogWrite(redLED, redValue);
   analogWrite(greenLED, greenValue);
   delay(30);
  }
 Â
  for (int fadeValue = redValue ; fadeValue >= 120; fadeValue -= 10)
  {
   redValue -= 10;
   greenValue = (redValue * .12);
   analogWrite(redLED, redValue);
   analogWrite(greenLED, greenValue);
   delay(30);
  }
 Â
  cat = !cat;
  delay(0);
 }
 if (digitalRead(SWITCH) == LOW && cat == false)
 {
  analogWrite(redLED, 0);
  analogWrite(greenLED, 0);
  cat = !cat;
  delay(200);Â
 } Â
}