I have a set of strip leds that lights up when a certain serial value is received, and stay on for a certain number of loops determined by a counter.
What I'd like to happen is that if at any time while it's going through the loop, if it gets a different value from the serial input, the lights turn off - the problem is of course that while it's going through the loop, it's not looking for a change in the serial value. I'm assuming that I can have it look for a change of the serial input value while its going through the loop instructions to send it back to the top of the main loop if its sees a new value - just not sure if that's the right approach and how to do that. Any help would be appreciated.
In my code below, if the system reads a letter "V" from the serial value, it goes through the "solidred" loop, coloring all the leds red. I'd like it so that any time during the loop, it looks at the serial input and if it sees the letter "O" it will stop.
Code to look for the V in the main loop of the sketch:
if (val == 'V' and oldval != val) { //
solidred();
Loop for solid red lights:
//SOLID RED
void solidred() {
while (counter<1000){
for (int i=0;i<NUM_LEDS;i++){
leds[i] = CRGB::Red;
FastLED.show();
//Serial.print (counter);
counter++;
}