Go Down

Topic: Control LED Strip Colors and Effects with IR Remote (Read 152 times) previous topic - next topic

cjr7315

Recently installed LED strips in my room (SK6812) and I'm trying to control them with a universal remote (GE). I tried to use a Raspberry Pi and Home Assistant to control the lights and could not get it to work. Anyways, the buttons of the remote are paired to their corresponding codes using the IRRemote - IRrevcDemo file, however there are problems with my code. The idea is to press a button (Ex Button 1) and get a color, press another button get a different color/effect. I've noticed that the IR receiver tends to display values outside the predefined list of IR codes, so I've included to only break the while loop if a value corresponds to the code array. This prevents the while loop to not be broken unless an intentional action is sent via the remote. This being said, once a button is pressed the color will not change even though the receiver is receiving new codes. It seems to be stuck in the first loop. I'm kinda stuck at this point and any help would be greatly appreciated. The code is listed below and the area of interest is highlighted:
*Note Under while Button_1, the code didn't translate to the forum very well, a screen capture is included below as well


#define POWER 0xE0E040BF
#define VOL_UP 0xE0E0E01F
#define VOL_DOW 0xE0E0D02F
#define CH_UP 0xE0E048B7
#define CH_DOW 0xE0E008F7
#define MUTE 0xE0E0F00F
#define CH_RETURN 0xE0E0C837
#define BUTTON_1 0xE0E020DF
#define BUTTON_2 0xE0E0A05F
#define BUTTON_3 0xE0E0609F
#define BUTTON_4 0xE0E010EF
#define BUTTON_5 0xE0E0906F
#define BUTTON_6 0xE0E050AF
#define BUTTON_7 0xE0E030CF
#define BUTTON_8 0xE0E0B04F
#define BUTTON_9 0xE0E0708F
#define BUTTON_DOT 0xE0E0C43B
#define BUTTON_0 0xE0E08877
#define BUTTON_INPUT 0xE0E0807F
#define EMPTY 0

#define LED_PIN 13
#define NUM_LEDS 450
int RECV_PIN = 2;//IR PIN
int array_Code[19] = {POWER, VOL_UP, VOL_DOW, CH_UP, CH_DOW, MUTE, CH_RETURN, BUTTON_1, BUTTON_2, BUTTON_3, BUTTON_4, BUTTON_5, BUTTON_6, BUTTON_7, BUTTON_8, BUTTON_9, BUTTON_DOT, BUTTON_0, BUTTON_INPUT};
int size_array_Code = 19;
int CHECK;

#include <Adafruit_NeoPixel.h>
#include <IRremote.h>

Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, LED_PIN, NEO_WRGB + NEO_KHZ800);
IRrecv irrecv(RECV_PIN);
decode_results results;

void setup() {
 Serial.begin(9600);
 strip.begin();
 strip.show();
 irrecv.enableIRIn(); // Start the receiver
 strip.setBrightness(255);
 Bootup();//Custom Effect When Power is Supplied to Strip
 strip.fill(strip.Color(0, 0, 0, 0));//Off
 strip.show();
}

void loop() {
 if (irrecv.decode(&results)) {

   Serial.println(results.value, HEX);

   while (results.value = BUTTON_1) {
      delay(20);
      strip.fill(strip.Color(0, 0, 255, 0));//white
      delay(20);
      strip.show();
      delay(20);
      //IR CODE CHECK
      if (irrecv.decode(&results)) {//second_if
        Serial.println(results.value, HEX);
        irrecv.resume(); // Receive the next value
        if (results.value != BUTTON_1) {
          //first_if
          for (int x = 0; x < size_array_Code; x++) { //for loop 1
            if (results.value == array_Code
  • ) {

              CHECK = 1;
              break;//break for loop 1
            }
            else {
              break;//break for loop 1
            }
          }//end of for loop
          if (CHECK = 1) {
            CHECK = 0;
            break;//break while loop
          }
        }//end of first_if
      }//end of second_if
      delay(100);
    }//end of while loop


   while (results.value = BUTTON_2) {
     delay(20);
     strip.fill(strip.Color(255, 0, 0, 0));//red
     delay(20);
     strip.show();
     delay(20);
     //IR CODE CHECK
     if (irrecv.decode(&results)) {//second_if
       Serial.println(results.value, HEX);
       irrecv.resume(); // Receive the next value
       if (results.value != BUTTON_2) {//first_if
         for (int x = 0; x < size_array_Code; x++) {
           if (results.value == array_Code
  • ) {

             CHECK = 1;
             break;//break for loop
           }
           else {
             break;//break for loop
           }
         }//end of for loop
         if (CHECK = 1) {
           CHECK = 0;
           break;
         }
       }//end of first_if
     }//end of second_if
     delay(100);
   }//end of while loop

   irrecv.resume();
   delay(100);
 }
}

void Brighten() {
 uint16_t i, j;
 for (j = 0; j < 255; j++) {
   for (i = 0; i < strip.numPixels(); i++) {
     strip.setPixelColor(i, 0, 0, 0, j);
   }
   strip.show();
   delay(10);
 }
}

void Bootup() {
 uint16_t i, j;
 for (j = 255; j > 0; j--) {
   for (i = 0; i < strip.numPixels(); i++) {
     strip.setPixelColor(i, 0, 0, j, 0);
   }
   strip.show();
   delay(0.1);
   if (j < 1) {
     break;
   }
 }
 for (j = 255; j > 0; j--) {
   for (i = 0; i < strip.numPixels(); i++) {
     strip.setPixelColor(i, 0, 0, j, 0);
   }
   strip.show();
   delay(2);
   if (j < 1) {
     break;
   }
 }
}

pert

Please use code tags when you post code or warning/error messages. To do this, click the </> button on the forum toolbar, then paste the text you want to be in the code tags. Finally, move the cursor out of the code tags before adding any additional text you don't want to be in the code tags. If your browser doesn't show the posting toolbar, then you can manually add the code tags like this:
[code]// your code is here[/code]

The reason for doing this is that, without code tags, the forum software can interpret parts of your code as markup (the bullets in your code above for example), leading to confusion, wasted time, and a reduced chance for you to get help with your problem. This will also make it easier for us to read your code and to copy it to the IDE or editor.

Using code tags and other important information is explained in the "How to use this forum" post. Please read it.




Code: [Select]
   while (results.value = BUTTON_1) {
Code: [Select]
          if (CHECK = 1) {
Please take some time to read up on the difference between the assignment operator (=) and the comparison operator (==):

Do you see the problem now?

sterretje

If you understand an example, use it.
If you don't understand an example, don't use it.

Electronics engineer by trade, software engineer by profession. Trying to get back into electronics after 15 years absence.

Go Up