I've managed to replicate John Park's wonderful Trigger Effects Remote Control and receiver. It is excellent! Now I'm making some code modifications to fit needs, and I'm trying to find a way to break out of a loop.

Basically, once a receiver receives a Letter code which corresponds to a Menu and Button on the remote, it executes a particular part of code. In my case, it is going to be a brightness fade from low to full to low 5 times. I'd like to be able to stop it mid loop if I need to. I've tried adding in an additional if statement, but it doesn't seem to be doing it... I'm hoping someone might be able to see where I've gone wrong.

for(int k = 0; k < 5; k++){ //k is the number of cycles the lights should fade up and down for (j = 10; j < 255; j++){ //j is the color value. This for statement is what incrementally increases the color value by 1 in the setPixelColor below. for (i = 0; i < pixels.numPixels(); i++) { //i is the pixel number and this for statement increases by 1 in order to move on to the next pixel. pixels.setPixelColor(i, j, j, j); } pixels.show(); delay(15); if (buf[0]=='D'){// stop the loop pixels.show(); radiopacket[8] = 'A'; } } delay(500);

for (j = 255; j > 5; j--) { //j is the color value. This for statement is what incrementally decreases the color value by 1 in the setPixelColor below. for (i = 0; i < pixels.numPixels(); i++) { //i is the pixel number and this for statement increases by 1 in order to move on to the next pixel. pixels.setPixelColor(i, j, j, j); } pixels.show(); delay(15); } delay(0);

for(int k = 0; k < 5; k++){ //k is the number of cycles the lights should fade up and down for (j = 10; j < 255; j++){ //j is the color value. This for statement is what incrementally increases the color value by 1 in the setPixelColor below. for (i = 0; i < pixels.numPixels(); i++) { //i is the pixel number and this for statement increases by 1 in order to move on to the next pixel. pixels.setPixelColor(i, j, j, j); } pixels.show(); delay(15); if (buf[0]=='D'){// stop the loop pixels.show(); radiopacket[8] = 'A'; } } delay(500);

for (j = 255; j > 5; j--) { //j is the color value. This for statement is what incrementally decreases the color value by 1 in the setPixelColor below. for (i = 0; i < pixels.numPixels(); i++) { //i is the pixel number and this for statement increases by 1 in order to move on to the next pixel. pixels.setPixelColor(i, j, j, j); } pixels.show(); delay(15); } delay(0);

} pixels.show(); radiopacket[8] = 'A';

}if (buf[0]=='B'){ //crystal red fade for(int k = 0; k < 5; k++){ //k is the number of cycles the lights should fade up and down for (j = 10; j < 255; j++){ //j is the color value. This for statement is what incrementally increases the color value by 1 in the setPixelColor below. for (i = 0; i < pixels.numPixels(); i++) { //i is the pixel number and this for statement increases by 1 in order to move on to the next pixel. pixels.setPixelColor(i, j, 0, 0); } pixels.show(); delay(15); } delay(500);

for (j = 255; j > 10; j--) { //j is the color value. This for statement is what incrementally decreases the color value by 1 in the setPixelColor below. for (i = 0; i < pixels.numPixels(); i++) { //i is the pixel number and this for statement increases by 1 in order to move on to the next pixel. pixels.setPixelColor(i, j, 0, 0); } pixels.show(); delay(15); } delay(0);

Sorry, copied the wrong version of the code... The break comes as the neopixels are going through the for statement that increases the pixel brightness. The idea was to put an additional if statement that would check the buffer for a code (in this case, the letter D), and then break the loop if the code received was D.

for(int k = 0; k < 5; k++){ //k is the number of cycles the lights should fade up and down for (j = 10; j < 255; j++){ //j is the color value. This for statement is what incrementally increases the color value by 1 in the setPixelColor below. for (i = 0; i < pixels.numPixels(); i++) { //i is the pixel number and this for statement increases by 1 in order to move on to the next pixel. pixels.setPixelColor(i, j, j, j); } pixels.show(); delay(15); if (buf[0]=='D'){// stop the loop pixels.show(); radiopacket[8] = 'A'; break; } } delay(500);

for (j = 255; j > 5; j--) { //j is the color value. This for statement is what incrementally decreases the color value by 1 in the setPixelColor below. for (i = 0; i < pixels.numPixels(); i++) { //i is the pixel number and this for statement increases by 1 in order to move on to the next pixel. pixels.setPixelColor(i, j, j, j); } pixels.show(); delay(15); } delay(0);

} pixels.show(); radiopacket[8] = 'A';

}

Using the serial monitor, I can see the buffer code {A or B} received by the receiver before the neopixels begin fading, however the receiver doesn't recognize a change in the buffer while the fade for condition is being executed. Immediately after the fade completes, the serial monitor does show the first code received during the fade and executes it... I was thinking that if I added a check of the buffer

Sidetrack: I believe that the radiopacket[number] line is a return code which gets sent to the receiver, however this never seems to get sent or received, at least I never see it when connected to the serial monitor.

Bill, I will read the multitasking pages. Hopefully something there will tell me how to clear or check the buffer. Thank you for the suggestion!