Hi guys,
I've made RGB lamp. It is working good, well at last as I wanted it to work
However I'm not satisfied how I did exit from the loop/function I have inside my code.
Well, first piece of code I have:
// --= fadeUP function - brigthen LED from 0 to fVal =-- //
void fadeUP(int led){
 if(RainbowActive){
  for(int fadeValue = 0 ; fadeValue <= fVal; fadeValue ++) {
  analogWrite(led, fadeValue);   Â
  delay(30);             Â
 }
 }
}
// --= fadeDOWN function - fade LED from fVal to 0Â =-- //
void fadeDOWN(int led){
 if(RainbowActive){
 for(int fadeValue = fVal ; fadeValue >= 0; fadeValue --) {
  analogWrite(led, fadeValue);   Â
  delay(30);             Â
 }
 }
}Â
// --= Interrupt routine =-- //
void serialInterrupt()
{
 RainbowActive = false;
 firstRun = true;
}
// --= rainbow function - rainbow color effect =-- //
void rainbow(){Â
 if(firstRun){Â
   analogWrite(RedLED, 0);
   analogWrite(GreenLED, 0);
   analogWrite(BlueLED, 0);
   fadeUP(RedLED);
  }
  fadeUP(GreenLED);
  fadeDOWN(RedLED);
  fadeUP(BlueLED);
  fadeDOWN(GreenLED);
  fadeUP(RedLED);
  fadeDOWN(BlueLED);
  firstRun = false;
}
What I do here is that I clear "RainbowActive" flag whenever interrupt occurs.
Then if that flag is cleared, I don't proceed function's code.
That works, but it might take a while before already started function will run till very end.
So my question is - how to make this better?
I don't expect ready solution - some thoughts which will lead me into correct direction would be more appreciate.
Here is my lamp project if anyone would be interested: