I would like to make it so when a button is pressed on a TV remote the LED strip runs a loop until another button is pressed, then it runs a new one. This is what I have so far. However, this only loops the light function once, and then requires an input from the remote in order to continue to another LED loop. 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: GitHub - Arduino-IRremote/Arduino-IRremote: Infrared remote library for Arduino: send and receive infrared signals with multiple protocols
Unzip folder into Libraries. RENAME folder IRremote
terry@yourduino.com */
/-----( Import needed libraries )-----/
#include <Adafruit_NeoPixel.h>
#define PIN 13
#include "IRremote.h"
Adafruit_NeoPixel strip = Adafruit_NeoPixel(300, PIN, NEO_GRB + NEO_KHZ800);
/-----( 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
strip.begin();
strip.show();
}/--(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(results.value);
tbn();
stripoff();
break;
case 0x20DF48B7: Serial.println(results.value);
pfn();
stripoff();
break;
default:
Serial.println(" other button ");
}// End Case
delay(100); // Do not get immediate repeat
}
void tbn () {
for (int f = 299; f >= 0; f-- ) {
int g = f + 1;
strip.setPixelColor(f, strip.Color(50 , 0, 0));
strip.show();
delay(1);
}
}
//////////////////////////////////////////////////
void pff () {
for (int j = 0; j <= 299; j = j + 1 ) {
int x = j - 1;
strip.setPixelColor(j, strip.Color(100 , 0, 50));
strip.show();
strip.setPixelColor(x, strip.Color(0, 0 , 0));
strip.show();
delay(1);
}
}
//////////////////////////////////////////////////////
void pfn () {
for (int j = 0; j <= 299; j = j + 1 ) {
int x = j - 1;
strip.setPixelColor(j, strip.Color(0 , 50, 50));
strip.show();
delay(1);
}
}
/////////////////////////////////////////////////
void stripoff () {
for (int j = 0; j <= 299; j = j + 1 ) {
int x = j - 1;
strip.setPixelColor(j, strip.Color(0 , 0, 0));
strip.show();
delay(1);
}
}