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

#define LED_PIN 7 // define the LED strip data pin
#define LED_COUNT 150 // define the number of LEDs in the strip

Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);

int RECV_PIN = 2; // define the IR receiver pin

IRrecv irrecv(RECV_PIN);




int brightness = 100;

void setup() {
 Serial.begin(9600); // initialize serial communication
strip.begin(); // initialize LED strip
strip.show(); // turn off all LEDs
irrecv.enableIRIn(); // start the receiver
}

void loop() {
case 0xE916FF00: // 0
    Serial.println("0");
      
      for (int i = 0; i<LED_COUNT; i++) {
      strip.setPixelColor(i, 0, 0, 0); // set all LEDs to off
      strip.show(); // turn off all LEDs
      Serial.println(irrecv.decodedIRData.decodedRawData);
      }
      
    break;
  case 0xF30CFF00: // 1
    Serial.println("1");

      for (int i = 0; i<LED_COUNT; i++) {
      strip.setPixelColor(i, 255, 255, 255); // set all LEDs to white
      strip.setBrightness(brightness); // set maximum brightness
      strip.show(); // display the color on the LED strip
      }          

    break;
  case 0xE718FF00: // 2
    Serial.println("2");
    while (true) {

      for (int i = 0; i < LED_COUNT; i++) {
        strip.setPixelColor(i, random(256), random(256), random(256));
      }
      strip.show();
       delay(1000);
       if(irrecv.decode()){
         break;
       }
      
    }
    break;  
  
  default:
    break;
}
irrecv.resume(); // receive the next code
  }
}

I have trouble to get out of the loop after i press button 3. When button 1 or 0 is pressed everything works perfectly but when i tried to add animation to my led strip (randomly changing colors) it stops to recieving. I dont know what to do. I expect that after i press button 3 on my controller LED strip will be continously changing colors until another button is pressed (In my case button 0 or 1) Can someone help me please?

5
  • you don't have any code for button 3 ... this is a question and answer site ... just ask a question that you would like answered ... Can someone help me please? is not a question about the problem ... besides, what is the point of asking a question that always has a yes answer
    – jsotola
    Mar 7 at 22:14
  • your code is missing parts... please read arduino.cc/reference/en/language/structure/control-structure/…
    – jsotola
    Mar 8 at 5:48
  • @jsotola so could you please help me? What is wrong in my code? Yeah i made a mistake it's button 2 not a button 3.
    – Martin
    Apr 5 at 9:00
  • Basically I need to jump off the loop after I press another button on IR controller and I can't figure it out.
    – Martin
    Apr 5 at 9:01
  • I told you what's wrong with your code on Mar 8 ... it's button 2 not a button 3 ... don't explain in a comment, edit your question and make the correction there ... When button 1 or 0 is pressed everything works perfectly ... how can it work perfectly when the code does not even compile without an error?
    – jsotola
    Apr 5 at 15:32

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.