CHANGE LOOP - IR REMOTE

Hello, I am using an IR sensor to light up LED's. The code is not complete, but I am trying to make it so a red LED will light up until another button is pressed on the remote, then the a green LED will turn on and the red one will turn off, and visa versa. My long term goal is to implement this with an LED strip (WS2812B) and have the strip change its cycle mode when a button on the remote is pressed, but I'm not sure how to make the sensor check for input during a cycle. Thanks in advance!

/* YourDuino.com Example Software Sketch Brick Starter Set IR Remote Kit Test http://yourduino.com/sunshop2/index.php?l=product_detail&p=364 based on code by Ken Shirriff - http://arcfn.com Get Library at: https://github.com/shirriff/Arduino-IRremote Unzip folder into Libraries. RENAME folder IRremote terry@yourduino.com */

/-----( Import needed libraries )-----/

include "IRremote.h"

/-----( Declare Constants )-----/ int receiver = 11; // pin 1 of IR receiver to Arduino digital pin 11

/-----( Declare objects )-----/ IRrecv irrecv(receiver); // create instance of 'irrecv' decode_results results; // create instance of 'decode_results' /-----( Declare Variables )-----/

void setup() /----( SETUP: RUNS ONCE )----/ { Serial.begin(9600); Serial.println("YourDuino IR Receiver Button Decode Test"); Serial.println("Questions: terry@yourduino.com"); irrecv.enableIRIn(); // Start the receiver

}/--(end setup )---/

void loop() /----( LOOP: RUNS CONSTANTLY )----/ { if (irrecv.decode(&results)) // have we received an IR signal?

{ // Serial.println(results.value, HEX); UN Comment to see raw values translateIR(); irrecv.resume(); // receive the next value } }/* --(end main loop )-- */

/-----( Declare User-written Functions )-----/ void translateIR() // takes action based on IR code received

// describing KEYES Remote IR codes

{

switch(results.value)

{

case 0x20DF8877: Serial.println(" -"); digitalWrite(6, HIGH); break; case 0x20DF48B7: Serial.println(" +"); digitalWrite(7, HIGH); break;

default: Serial.println(" other button ");

}// End Case

delay(100); // Do not get immediate repeat

}

I can only assume your red LED is connected to Pin 6 and your green LED is connected to Pin 7 based on your switch statement in the translateIR() function.

With the further assumption that digitalWrite(6,HIGH) does indeed turn on the red LED, then digitalWrite(6,LOW) should turn it off. And likewise digitalWrite(7,LOW) should turn off the green LED.

Try adding changing your switch statement to…

  case 0x20DF8877: Serial.println(" -");
  digitalWrite(6, HIGH);  //Turn Red LED On
  digitalWrite(7, LOW);   //Turn Green LED Off
  break;
  case 0x20DF48B7: Serial.println(" +");
  digitalWrite(7, HIGH);  //Turn Green LED On
  digitalWrite(6,LOW);    //Turn Red LED Off
  break;

Eventually add code to change strip cycle mode in addition to or in place of changing LED states. If these cycles are also programmed to repeat until the next change you will want to set a state variable to define the cycle here and then implement the cycle pattern inside of the Loop function based on the value of the variable.

Hope I interpreted your intentions correctly.

BTW
Keep this in mind:
When using neopixel software, you don’t/won’t get good reaction as pixel software is blocking.

.