Im trying to change my led colors with my IR controller. I already made the same project with a button and that works fine. Somehow the code doesn
t work when its in the loop of displaying the leds on my ledstrip.
#include <Adafruit_NeoPixel.h>
#include <IRremote.h>
//neopixel setup
#ifdef __AVR__
#include <avr/power.h> // Required for 16 MHz Adafruit Trinket
#endif
#define BUTTON_PIN 2
#define PIXEL_PIN 3 // Digital IO pin connected to the NeoPixels.
#define PIXEL_COUNT 300 // Number of NeoPixels
Adafruit_NeoPixel strip(PIXEL_COUNT, PIXEL_PIN, NEO_GRB + NEO_KHZ800);
//ir setup
const int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;
unsigned long key_value = 0;
//variabels
bool oldState = HIGH;
bool oldStatebool = HIGH;
int mode = 0;
unsigned long lastFire = 0;
unsigned long lastFire2 = 0;
void setup() {
irrecv.enableIRIn();
irrecv.blink13(true);
pinMode(BUTTON_PIN, INPUT_PULLUP);
strip.begin();
strip.show();
Serial.begin(9600);
}
void loop() {
check();
delay(5);
}
void check() {
//ir control
if (irrecv.decode(&results)){
//if (results.value == 0XFFFFFFFF)results.value = key_value;
irrecv.resume();
if (results.value == 0xFF18E7) { //2
Serial.println("2");
if(++mode > 9) mode = 0;
switch(mode) {
case 0:
colorWipe(strip.Color( 0, 0, 0), 50); // Black/off
break;
case 1:
colorWipe(strip.Color( 127, 127, 127), 50); // white
break;
case 2:
colorWipe(strip.Color(255, 0, 0), 50); // Red
break;
case 3:
colorWipe(strip.Color( 0, 255, 0), 50); // Green
break;
case 4:
colorWipe(strip.Color( 0, 0, 255), 50); // Blue
break;
case 5:
theaterChase(strip.Color(127, 127, 127), 50); // White
break;
case 6:
theaterChase(strip.Color(127, 0, 0), 50); // Red
break;
case 7:
theaterChase(strip.Color( 0, 0, 127), 50); // Blue
break;
case 8:
rainbow(10);
break;
case 9:
theaterChaseRainbow(50);
break;
}
}
}
}
void colorWipe(uint32_t color, int wait) {
while(true) {
for(int i=0; i<strip.numPixels(); i++) { // For each pixel in strip...
strip.setPixelColor(i, color); // Set pixel's color (in RAM)
strip.show(); // Update strip to match
check();
delay(wait); // Pause for a moment
}
}
}
void theaterChase(uint32_t color, int wait) {
while(true) {
for(int a=0; a<10; a++) { // Repeat 10 times...
for(int b=0; b<3; b++) { // 'b' counts from 0 to 2...
strip.clear(); // Set all pixels in RAM to 0 (off)
// 'c' counts up from 'b' to end of strip in steps of 3...
for(int c=b; c<strip.numPixels(); c += 3) {
strip.setPixelColor(c, color); // Set pixel 'c' to value 'color'
check();
}
strip.show(); // Update strip with new contents
delay(wait); // Pause for a moment
}
}
}
}
void rainbow(int wait) {
while(true) {
for(long firstPixelHue = 0; firstPixelHue < 3*65536; firstPixelHue += 256) {
for(int i=0; i<strip.numPixels(); i++) { // For each pixel in strip...
int pixelHue = firstPixelHue + (i * 65536L / strip.numPixels());
strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue)));
check();
}
strip.show(); // Update strip with new contents
delay(wait); // Pause for a moment
}
}
}
void theaterChaseRainbow(int wait) {
while(true) {
int firstPixelHue = 0; // First pixel starts at red (hue 0)
for(int a=0; a<30; a++) { // Repeat 30 times...
for(int b=0; b<3; b++) { // 'b' counts from 0 to 2...
strip.clear(); // Set all pixels in RAM to 0 (off)
// 'c' counts up from 'b' to end of strip in increments of 3...
for(int c=b; c<strip.numPixels(); c += 3) {
// hue of pixel 'c' is offset by an amount to make one full
// revolution of the color wheel (range 65536) along the length
// of the strip (strip.numPixels() steps):
int hue = firstPixelHue + c * 65536L / strip.numPixels();
uint32_t color = strip.gamma32(strip.ColorHSV(hue)); // hue -> RGB
strip.setPixelColor(c, color); // Set pixel 'c' to value 'color'
check();
}
strip.show(); // Update strip with new contents
delay(wait); // Pause for a moment
firstPixelHue += 65536 / 90; // One cycle of color wheel over 90 frames
}
}
}
}
I hope someone can help my and can tell me why it`s not working.