I've been piecing together various lighting effects. I am wanting to have each lighting effect loop until another button is pressed to trigger another lighting effect.
I've come to a bit of standstill at the moment. I've created a loop that doesn't seem to end. I've had a look around but I can't work out how to fix my code. Sorry in advanced, I'm new to using arduinos but if anyone could help out, it would be much appreciated. Thanks!
//www.elegoo.com
//2016.12.9
#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
// Remote = 0xFFA25D;
break;
case 0xFFE21D: Serial.println("FUNC/STOP");
ArrowLeft(strip.Color(25, 0, 0), 100); // Red
ArrowLeft(strip.Color(0, 0, 25), 100); // Blue
// Remote = 0xFFE21D;
break;
case 0xFF629D: Serial.println("VOL+"); break;
case 0xFF22DD: Serial.println("FAST BACK"); break;
case 0xFF02FD: Serial.println("PAUSE"); break;
case 0xFFC23D: Serial.println("FAST FORWARD"); break;
case 0xFFE01F: Serial.println("DOWN"); break;
case 0xFFA857: Serial.println("VOL-"); break;
case 0xFF906F: Serial.println("UP"); break;
case 0xFF9867: Serial.println("EQ"); break;
case 0xFFB04F: Serial.println("ST/REPT"); break;
case 0xFF6897: Serial.println("0"); break;
case 0xFF30CF: Serial.println("1"); break;
case 0xFF18E7: Serial.println("2"); break;
case 0xFF7A85: Serial.println("3"); break;
case 0xFF10EF: Serial.println("4"); break;
case 0xFF38C7: Serial.println("5"); break;
case 0xFF5AA5: Serial.println("6"); break;
case 0xFF42BD: Serial.println("7"); break;
case 0xFF4AB5: Serial.println("8"); break;
case 0xFF52AD: Serial.println("9"); break;
case 0xFFFFFFFF: Serial.println(" REPEAT");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) {
while (Remote = 0xFFA25D) {
for (uint16_t i = strip.numPixels()/2; i < strip.numPixels(); i++) {
strip.setPixelColor(i, c);
strip.show();
delay(wait);
}
for (uint16_t i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, 0);
}
strip.show();
delay(wait);
}
}
void ArrowLeft(uint32_t c, uint8_t wait) {
while (Remote = 0xFFE21D) { // 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(wait);
}
for (uint16_t i = strip.numPixels(); i + 1 > 0 ; i--) {
strip.setPixelColor(i, 0);
}
strip.show();
delay(wait);
}
}
while
loops -- you should take them out & turn them into one-shots and take the translateIR() out of the conditional inloop()
. Inside the conditional, if you do get a new message, copy it to from a temp variable into&result
instead of updating&result
eachloop()
while (Remote = 0xFFE21D)
You have to use==
here, or this will be an assignment