The original problem is after selecting a LED light function, sometimes the loop would stop as if the IR remote had a button pressed which did not really happen. So the Boolean was added so that only the values of the array would be accepted and other random values would be ignored. All works well with using print statements inside each of the functions with the real functions commented out. However, removing the comments to allow the function to do it’s magic with the addressable LED lights created a new problem --- the running code will not accept a new key press entry with the exception of the colors. But the function for the colors is simply turning them on via RGB values. The complete code uses a 44 button remote with more LED activities.
Any and all comments welcomed.
#include <IRremote.h>
#include <Adafruit_NeoPixel.h>
#define PIN 6
Adafruit_NeoPixel strip = Adafruit_NeoPixel(150, PIN, NEO_GRB + NEO_KHZ800);
int TOTAL_LEDS = 150;
int a = 3;
int c = 0;
int d = 5;
int r = 0;
int x = (TOTAL_LEDS)-1;
int pos = 0, dir = 1;
int j = 0;
int direction=1;
int receiver = 3;
IRrecv irrecv(receiver);
decode_results results; // create instance of 'decode_results'
unsigned long aryHex[45]={
0xFF3AC5,0xFFBA45,0xFF827D,0xFF02FD,0xFF1AE5,0xFF9A65,0xFFA25D,0xFF22DD,0xFF2AD5,0xFFAA55,0xFF926D,0xFF12ED,0xFF0AF5,0xFF8A75,0xFFB24D,0xFF32CD,0xFF38C7,0xFFB847,0xFF7887,0xFFF807,0xFF18E7,0xFF9867,0xFF58A7,0xFFD827,0xFF28D7,0xFFA857,0xFF6897,0xFFE817,0xFF08F7,0xFF8877,0xFF48B7,0xFFC837,0xFF30CF,0xFFB04F,0xFF708F,0xFFF00F,0xFF10EF,0xFF906F,0xFF50AF,0xFFD02F,0xFF20DF,0xFFA05F,0xFF609F,0xFFE01F,0xDEAF};
boolean blGoodVal;
unsigned long newVal;
void setup(){
Serial.begin(9600);
irrecv.enableIRIn();
strip.begin();
strip.show();
Serial.println("IR Receiver Raw Data + Button Decode Test");
}
void loop() {
if (irrecv.decode(&results)) {
Serial.print("results0: ");
Serial.println(results.value, HEX);
irrecv.resume(); // Receive the next value
delay(100);
Serial.print("results1: ");
Serial.println(results.value, HEX);
}
if(goodVal(results.value)==true){
newVal=results.value;
Serial.print("newVal: ");
Serial.println(newVal,HEX);
delay(100);
}
switch(newVal){
delay(10);
case 0xFF1AE5:
Serial.println("Red");
doColors(128,0,0);
break;
case 0xFF9A65:
Serial.println("Green");
doColors(0,128,0);
break;
case 0xFFA25D:
Serial.println("Blue");
doColors(0,0,145);
break;
case 0xFF08F7:
Serial.println("Red_Zigs");
Red_Zigs();
break;
case 0xFF8877:
Serial.println("Green_Zigs");
Green_Zigs();
break;
case 0xFF30CF:
Serial.println("FlashingRWB");
FlashingRWB();
break;
case 0xFFB04F:
Serial.println("StreamingRWB");
StreamingRWB();
break;
case 0x0:
Serial.println("No Signal yet");
Serial.println(results.value,HEX);
break;
default:
Serial.println("Unrecgnized value");
Serial.println(results.value,HEX);
}
delay(d*40); // d = 5
}
boolean goodVal(unsigned long testVal){
// Serial.println("In goodVal");
boolean blVal;
blVal=false;
for (int i=0; i<45; i++){
// Serial.print(testVal,HEX);
// Serial.print(": ");
// Serial.println(aryHex[i],HEX);
if(testVal==aryHex[i]){
blVal=true;
break;
}
}
// Serial.println(blVal);
return blVal;
}
void doColors(int iRed,int iGrn,int iBlue){
strip.begin();
strip.show();
for (int ledNumber=0; ledNumber<TOTAL_LEDS; ledNumber++){
strip.setPixelColor(ledNumber, iRed, iGrn, iBlue);
}
}
void Red_Zigs(){
static int cnt = 0;
for (int z = (TOTAL_LEDS/2)-1, y = (TOTAL_LEDS/2); z<x, y>r; z++, y--) {
strip.setPixelColor(z+1, 100,0,0);
strip.setPixelColor(z+2, 100,0,0);
strip.setPixelColor(z+3, 200,0,0);
strip.setPixelColor(z+4, 100,0,0);
strip.setPixelColor(z+5, 100,0,0);
strip.setPixelColor(y-1, 100,0,0);
strip.setPixelColor(y-2, 100,0,0);
strip.setPixelColor(y-3, 200,0,0);
strip.setPixelColor(y-4, 100,0,0);
strip.setPixelColor(y-5, 100,0,0);
strip.show();
delay(d*6); // d=5
strip.setPixelColor(z, 0,0,0);
strip.setPixelColor(y, 0,0,0);
strip.show();
}
Serial.println(cnt);
cnt++;
}
void Green_Zigs(){
static int cnt = 0;
for (int z = (TOTAL_LEDS/2)-1, y = (TOTAL_LEDS/2); z<x, y>r; z++, y--) {
strip.setPixelColor(z+1, 0,100,0);
strip.setPixelColor(z+2, 0,100,0);
strip.setPixelColor(z+3, 0,200,0);
strip.setPixelColor(z+4, 0,100,0);
strip.setPixelColor(z+5, 0,100,0);
strip.setPixelColor(y-1, 0,100,0);
strip.setPixelColor(y-2, 0,100,0);
strip.setPixelColor(y-3, 0,200,0);
strip.setPixelColor(y-4, 0,100,0);
strip.setPixelColor(y-5, 0,100,0);
strip.show();
delay(d*6); // d=5
strip.setPixelColor(z, 0,0,0);
strip.setPixelColor(y, 0,0,0);
strip.show();
}
Serial.println(cnt);
cnt++;
}
void FlashingRWB(){
static int cnt = 0;
int z = TOTAL_LEDS/2-1;
int y = (TOTAL_LEDS/2);
strip.begin();
strip.show();
strip.setBrightness(100);
for (z = (TOTAL_LEDS/2)-1, y = TOTAL_LEDS/2; z<x, y>r; z++, y--)
{
strip.setPixelColor(z, 150, 150, 150);
strip.setPixelColor(z+1, 150, 150, 150);
strip.setPixelColor(y, 150, 150, 150);
strip.setPixelColor(y-1, 150, 150, 150);
strip.show();
delay(d*7);
strip.setPixelColor(z, 0, 0, 0);
strip.setPixelColor(y, 0, 0, 0);
strip.show();
}
strip.setPixelColor(r, 150, 0, 0);
strip.setPixelColor(x, 0, 0, 150);
strip.show();
x--;
r++;
if (x<(TOTAL_LEDS/2))
{
x=(TOTAL_LEDS)-1;
}
if (r>(TOTAL_LEDS/2)-1)
{
r=0;
}
delay(d*10);
Serial.println(cnt);
cnt++;
}
void StreamingRWB(){
static int cnt = 0;
strip.begin();
strip.show();
strip.setBrightness(100);
strip.setPixelColor(pos - 6, 0x110000);
strip.setPixelColor(pos - 5, 0x880000);
strip.setPixelColor(pos - 4, 0xFF0000);
strip.setPixelColor(pos - 3, 0xFF0000);
strip.setPixelColor(pos - 2, 0XFFFFFF);
strip.setPixelColor(pos - 1, 0XFFFFFF);
strip.setPixelColor(pos , 0xFFFFFF);
strip.setPixelColor(pos + 1, 0xFFFFFF);
strip.setPixelColor(pos + 2, 0xFFFFFF);
strip.setPixelColor(pos + 3, 0x0000FF);
strip.setPixelColor(pos + 4, 0x0000FF);
strip.setPixelColor(pos + 5, 0x000088);
strip.setPixelColor(pos + 6, 0x000011);
strip.show();
for(j=-2; j<= 2; j++) strip.setPixelColor(pos+j, 0);
pos += dir;
if(pos < 0) {
pos = 1;
dir = -dir;
}
else if(pos >= strip.numPixels())
{
pos = strip.numPixels() - 2;
dir = -dir;
}
Serial.println(cnt);
cnt++;
}]