I've been working on an LED strip project. However, I've come to a stand still at the moment. Within the program I am wanting to assign different lighting effects to each button on my IR remote. I am wanting the program to work on the basis that each lighting effect will run, until another button is pressed, to start another effect.
Currently with my code I have made it so each effect will run, once, when the corresponding button on the IR remote is pressed.
I am fairly new to C++ / Arduino but from my understanding I need to have a variable which would hold the current value of the IR remote. I am unsure on how to actually implement this. I will post my code below and if anyone could give me tips or even amendments to my code it would be to a great help.
Thank you in advanced.
#include "IRremote.h"
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
#define PIN 6
Adafruit_NeoPixel strip = Adafruit_NeoPixel(20, PIN, NEO_GRB + NEO_KHZ800);
int receiver = 11; // Signal Pin 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'
int Remote = 0;
/*-----( Function )-----*/
void translateIR() // takes action based on IR code received
// describing Remote IR codes
{
switch(results.value)
{
case 0xFFA25D: Serial.println("POWER");
ArrowRight(strip.Color(25, 0, 0), 100); //Red
ArrowRight(strip.Color(0, 0, 25), 100); //Blue
break;
case 0xFFE21D: Serial.println("FUNC/STOP");
ArrowLeft(strip.Color(25, 0, 0), 100); // Red
ArrowLeft(strip.Color(0, 0, 25), 100); // Blue
break;
default:
Serial.println(" other button ");
}// End Case
delay(0); // Do not get immediate repeat
} //END translateIR
void setup() /*----( SETUP: RUNS ONCE )----*/
{
Serial.begin(9600);
Serial.println("IR Receiver Button Decode");
irrecv.enableIRIn(); // Start the receiver
strip.begin();
strip.show();
Remote = 0;
}/*--(end setup )---*/
void loop() /*----( LOOP: RUNS CONSTANTLY )----*/
{
if (irrecv.decode(&results)) // have we received an IR signal?
{
translateIR();
irrecv.resume(); // receive the next value
}
}/* --(end main loop )-- */
void ArrowRight(uint32_t c, uint8_t wait) {
for (int j = 0; j < 1; j++) { // The j<# determines how many cycles
for (uint16_t i = strip.numPixels()/2; i < strip.numPixels(); i++) {
strip.setPixelColor(i, c);
strip.show();
delay(50);
}
for (uint16_t i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, 0);
}
strip.show();
delay(50);
}
}
void ArrowLeft(uint32_t c, uint8_t wait) {
for (int j = 0; j < 1; j++) { // The j<# determines how many cycles
for (uint16_t i = strip.numPixels()/2-1; i + 1 > 0 ; i--) {
strip.setPixelColor(i, c);
strip.show();
delay(50);
}
for (uint16_t i = strip.numPixels(); i + 1 > 0 ; i--) {
strip.setPixelColor(i, 0);
}
strip.show();
delay(50);
}
}