This code is for a fading rainbow on an LED strip. The code should check the IR input during each pass of the for loop within the rainbow function. If the IR remote has received a signal from a specific button, it should turn off the LEDs.
Any feedback would be very helpful as I am very new to Arduino.
I am posting the whole code below but I believe the issue is likely in the rainbow function.
Code: Select all
#include <Adafruit_NeoPixel.h>
#include <IRremote.h>
#define IR_RECEIVER_PIN 6
IRrecv irreceive(IR_RECEIVER_PIN);
int inputPin = 3;
int pirState = LOW;
int val = 0;
decode_results results;
const int BorderRelay=4;
#define Border_PIXELPIN 2
#define Border_PIXELCOUNT 97 // Border
Adafruit_NeoPixel border(Border_PIXELCOUNT, Border_PIXELPIN, NEO_GRBW + NEO_KHZ800);
void setup()
{
Serial.begin(9600);
irreceive.enableIRIn();
pinMode(inputPin, INPUT);
border.begin();
border.show();
pinMode(BorderRelay, OUTPUT);
}
void loop()
{
digitalWrite (BorderRelay, HIGH);
val = digitalRead(inputPin);
while (val == HIGH)
{
rainbow(10);
}
digitalWrite (BorderRelay, LOW);
}
void rainbow(uint8_t wait)
{
uint16_t i, j;
for(j=0; j<256; j++)
{
for(i=0; i<97; i++)
{
border.setPixelColor(i, Wheel((i*1+j) & 255));
}
border.show();
delay(wait);
if(irreceive.decode(&results))
{
Serial.println(results.value, HEX);
irreceive.resume();
}
if (results.value == 0XFD58A7)
{
border.clear();
border.show();
break;
}
}
}
uint32_t Wheel(byte WheelPos)
{
if(WheelPos < 85)
{
return border.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}
else if(WheelPos < 170)
{
WheelPos -= 85;
return border.Color(255 - WheelPos * 3, 0, WheelPos * 3);
}
else
{
WheelPos -= 170;
return border.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
}