cpldcpu/light_ws2812

LED Strip turns off automatically after some time

Opened this issue · 0 comments

Hi folks,

I have been using the light_ws2812 library along with IRRemote library for controlling the led patterns as per the IR remote input. When doing so everything works fine until after an hour (approximately) the leds turn off on their own. Below is my code. I am using Atmega328p chip btw.

#define USE_HSV
#define DECODE_NEC
#include <IRremote.hpp>
#include <WS2812.h>

#define IR_RECEIVE_PIN 2
#define LEDCount 120
WS2812 LED1(LEDCount);
cRGB value;
cRGB value1;
uint16_t val;
int h = 10; //stores 0 to 614
byte steps = 5; //number of hues we skip in a 360 range per update
byte sat = 255;
byte val1 = 127; //Brightness control
int Index = 0;

void pattern1();
void pattern2();
void pattern3();
void Cycle();
void pattern4();
void pattern5();
void pattern6();
void pattern7();
void pattern8();
void TheaterChaseUpdate();
void color1();
void color2();
void ScannerUpdate();
uint8_t col_val(uint8_t col);

void setup()
{
LED1.setOutput(9);
IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK); // Start the receiver
Serial.begin(115200);
value.b = 0; value.g = 0; value.r = 0;
for(int j = 0; j < LEDCount; j++)
{
LED1.set_crgb_at(j, value);
}
LED1.sync(); // Sends the value to the LED
delay(10); // Wait 500 ms

//sign = 0;
}

void loop() {
if (IrReceiver.decode()) {
val = IrReceiver.decodedIRData.command; // Print "old" raw data
//Serial.println(val);
if(val == 69)
{
pattern1();
}
else if(val == 70)
{
pattern2();
}
else if(val == 71)
{
pattern3();
}
else if(val == 68)
{
pattern4();
}
else if(val == 9)
{
pattern5();
}
else if(val == 64)
{
pattern6();
}
else if(val == 67)
{
pattern7();
}
else if(val == 7)
{
pattern8();
}
else if(val == 21)
{
pattern9();
}
else
{
value.b = 0; value.g = 0; value.r = 0;
for(int n = 0; n < LEDCount; n++)
{
LED1.set_crgb_at(n, value);
}
LED1.sync(); // Sends the value to the LED
delay(50);
}
IrReceiver.resume(); // Enable receiving of the next value
}
}

void pattern1()
{
uint8_t c = 0;
value.b = 0; value.g = 0; value.r = 0;
for(int k = 0; k < LEDCount; k++)
{
LED1.set_crgb_at(k, value);
}
LED1.sync(); // Sends the value to the LED
delay(10); // Wait 500 ms
while(1)
{
c = col_val(c);
value.b = 120; value.g = 255 - c; value.r = c; // RGB Value -> Blue
for(int k = 0; k < LEDCount; k++)
{
LED1.set_crgb_at(k, value); // Set value at LED found at index 0
}
LED1.sync(); // Sends the value to the LED
delay(100); // Wait 500 ms
if (IrReceiver.decode())
{
val = IrReceiver.decodedIRData.command; // Print "old" raw data
if(val != 69)
{
value.b = 0; value.g = 0; value.r = 0;
for(int m = 0; m < LEDCount; m++)
{
LED1.set_crgb_at(m, value);
}
// Sends the data to the LEDs
LED1.sync();
break;
}
IrReceiver.resume(); // Enable receiving of the next value
}
}
}

void pattern2()
{
uint8_t c = 0;
value.b = 0; value.g = 0; value.r = 0;
for(int l = 0; l < LEDCount; l++)
{
LED1.set_crgb_at(l, value);
}
LED1.sync(); // Sends the value to the LED
delay(10); // Wait 500 ms
while(1)
{
c = col_val(c);
value.b = c; value.g = 255 - c; value.r = 120; // RGB Value -> Blue
for(int k = 0; k < LEDCount; k++)
{
LED1.set_crgb_at(k, value); // Set value at LED found at index 0
}
LED1.sync(); // Sends the value to the LED
delay(100); // Wait 500 ms
if (IrReceiver.decode())
{
val = IrReceiver.decodedIRData.command; // Print "old" raw data
if(val != 70)
{
value.b = 0; value.g = 0; value.r = 0;
for(int m = 0; m < LEDCount; m++)
{
LED1.set_crgb_at(m, value);
}
// Sends the data to the LEDs
LED1.sync();
break;
}
IrReceiver.resume(); // Enable receiving of the next value
}
}
}

void pattern3()
{
value.b = 0; value.g = 0; value.r = 0;
for(int m = 0; m < LEDCount; m++)
{
LED1.set_crgb_at(m, value);
}
LED1.sync(); // Sends the value to the LED
delay(50);
while(1)
{
Cycle();
for(int i = 1; i < LEDCount; i=i+2)
{
LED1.set_crgb_at(i, value);
}
// Sends the data to the LEDs
/for(int i = 8; i < LEDCount/4; i=i+2)
{
//value.b = 0; value.g = 0; value.r = 0; // RGB Value -> Blue
LED1.set_crgb_at(i, value);
}
for(int i = 17; i < 24; i=i+2)
{
LED1.set_crgb_at(i, value);
}
for(int i = 24; i < 32; i=i+2)
{
LED1.set_crgb_at(i, value);
}
for(int i = 33; i < 40; i=i+2)
{
LED1.set_crgb_at(i, value);
}
for(int i = 40; i < 48; i=i+2)
{
LED1.set_crgb_at(i, value);
}
for(int i = 49; i < 56; i=i+2)
{
LED1.set_crgb_at(i, value);
}
for(int i = 56; i < 64; i=i+2)
{
LED1.set_crgb_at(i, value);
}
/
LED1.sync();
delay(100);
if (IrReceiver.decode()) {
val = IrReceiver.decodedIRData.command; // Print "old" raw data
if(val != 71)
{
value.b = 0; value.g = 0; value.r = 0;
for(int m = 0; m < LEDCount; m++)
{
LED1.set_crgb_at(m, value);
}
// Sends the data to the LEDs
LED1.sync();
break;
}
IrReceiver.resume(); // Enable receiving of the next value
}
}
}

void Cycle()
{
value.SetHSV(h, sat, val1);
h += steps;
if(h > 360)
{
h %= 360;
}
}

void pattern4()
{
value.b = 0; value.g = 0; value.r = 0;
for(int m = 0; m < LEDCount; m++)
{
LED1.set_crgb_at(m, value);
}
LED1.sync(); // Sends the value to the LED
delay(50); // Wait 500 ms
value.b = 0; value.g = 255; value.r = 0; // RGB Value -> Blue
for(int m = 0; m < LEDCount; m=m+3)
{
LED1.set_crgb_at(m, value); // Set value at LED found at index 0
}
value.b = 130; value.g = 200; value.r = 65; // RGB Value -> Blue
for(int m = 1; m < LEDCount; m=m+3)
{
LED1.set_crgb_at(m, value); // Set value at LED found at index 0
}
value.b = 75; value.g = 75; value.r = 255; // RGB Value -> Blue
for(int m = 2; m < LEDCount; m=m+3)
{
LED1.set_crgb_at(m, value); // Set value at LED found at index 0
}
LED1.sync(); // Sends the value to the LED
delay(50); // Wait 500 ms
}

void pattern5()
{
value.b = 0; value.g = 0; value.r = 0;
for(int m = 0; m < LEDCount; m++)
{
LED1.set_crgb_at(m, value);
}
LED1.sync(); // Sends the value to the LED
delay(50); // Wait 500 ms
while(1)
{
//value.b = 0; value.g = 255; value.r = 0; // RGB Value -> Blue
for(int p = 0; p < 255; p=p+10)
{
value.b = p; value.g = 120; value.r = 240; // RGB Value -> Blue
for(int n = 0; n < LEDCount; n++)
{
LED1.set_crgb_at(n, value); // Set value at LED found at index 0
LED1.sync(); // Sends the value to the LED
delay(10);
if(p == 250)
{
if(n == (LEDCount - 1))
{
p = 0;
n = 0;
}
}
}
//LED1.set_subpixel_at(m, 2, 255);
if (IrReceiver.decode())
{
val = IrReceiver.decodedIRData.command; // Print "old" raw data
if(val != 9)
{
value.b = 0; value.g = 0; value.r = 0;
for(int m = 0; m < LEDCount; m++)
{
LED1.set_crgb_at(m, value);
}
// Sends the data to the LEDs
LED1.sync();
val = 200;
break;
}
IrReceiver.resume(); // Enable receiving of the next value
}
}
//LED1.sync(); // Sends the value to the LED
if(val = 200)
{
break;
}
}
}

void pattern6()
{
value.b = 0; value.g = 0; value.r = 0;
for(int m = 0; m < LEDCount; m++)
{
LED1.set_crgb_at(m, value);
}
LED1.sync(); // Sends the value to the LED
delay(50);
while(1)
{
Cycle();
/for(int i = 1; i < LEDCount; i=i+2)
{
LED1.set_crgb_at(i, value);
}
LED1.sync();
delay(sleep);
for(int i = 1; i < LEDCount; i=i+2)
{
value.b = 0; value.g = 0; value.r = 0;
LED1.set_crgb_at(i, value);
}
LED1.sync();
delay(sleep);
/
for(int i = 0; i < LEDCount; i=i+2)
{
LED1.set_crgb_at(i, value);
}
LED1.sync();
delay(200);
for(int i = 0; i < LEDCount; i=i+2)
{
value.b = 0; value.g = 0; value.r = 0;
LED1.set_crgb_at(i, value);
}
LED1.sync();
delay(10);
Cycle();
for(int i = 1; i <= LEDCount; i=i+2)
{
LED1.set_crgb_at(i, value);
}
LED1.sync();
delay(200);
for(int i = 1; i <= LEDCount; i=i+2)
{
value.b = 0; value.g = 0; value.r = 0;
LED1.set_crgb_at(i, value);
}
LED1.sync();
delay(10);
if (IrReceiver.decode())
{
val = IrReceiver.decodedIRData.command; // Print "old" raw data
if(val != 64)
{
value.b = 0; value.g = 0; value.r = 0;
for(int m = 0; m < LEDCount; m++)
{
LED1.set_crgb_at(m, value);
}
// Sends the data to the LEDs
LED1.sync();
break;
}
IrReceiver.resume(); // Enable receiving of the next value
}
}
}

void pattern7()
{
int j = 0;
while(1)
{
//randomSeed(analogRead(0));
j = random(0, (LEDCount - 1));
value.b = 190; value.g = 150; value.r = 120;
LED1.set_crgb_at(j, value);
LED1.sync();
delay(100);
value.b = 0; value.g = 0; value.r = 0;
LED1.set_crgb_at(j, value);
LED1.sync();
delay(100);
if (IrReceiver.decode())
{
val = IrReceiver.decodedIRData.command; // Print "old" raw data
if(val != 67)
{
value.b = 0; value.g = 0; value.r = 0;
for(int m = 0; m < LEDCount; m++)
{
LED1.set_crgb_at(m, value);
}
// Sends the data to the LEDs
LED1.sync();
break;
}
IrReceiver.resume(); // Enable receiving of the next value
}
}
}

void pattern8()
{
while(1)
{
// Update the Theater Chase Pattern
TheaterChaseUpdate();
if (IrReceiver.decode())
{
val = IrReceiver.decodedIRData.command; // Print "old" raw data
if(val != 7)
{
value.b = 0; value.g = 0; value.r = 0;
for(int m = 0; m < LEDCount; m++)
{
LED1.set_crgb_at(m, value);
}
// Sends the data to the LEDs
LED1.sync();
break;
}
IrReceiver.resume(); // Enable receiving of the next value
}
//delay(10);
}
}

void TheaterChaseUpdate()
{
color1(255,0,255);
color2(10,10,10);
for(int i=0; i< LEDCount; i++)
{
if ((i + Index) % 3 == 0)
{
LED1.set_crgb_at(i, value);
}
else
{
LED1.set_crgb_at(i, value1);
}
if (IrReceiver.decode())
{
val = IrReceiver.decodedIRData.command; // Print "old" raw data
if(val != 7)
{
value.b = 0; value.g = 0; value.r = 0;
for(int m = 0; m < LEDCount; m++)
{
LED1.set_crgb_at(m, value);
}
// Sends the data to the LEDs
LED1.sync();
break;
}
IrReceiver.resume(); // Enable receiving of the next value
}
}
LED1.sync();
delay(200);
Index++;
}

uint32_t color1(uint8_t blue,uint8_t green,uint8_t red)
{
value.b = blue; value.g = green; value.r = red;
}

uint32_t color2(uint8_t blue1,uint8_t green1,uint8_t red1)
{
value1.b = blue1; value1.g = green1; value1.r = red1;
}

uint32_t Wheel(uint8_t WheelPos)
{
WheelPos = 255 - WheelPos;
if(WheelPos < 85)
{
return color1(255 - WheelPos * 3, 0, WheelPos * 3);
}
else if(WheelPos < 170)
{
WheelPos -= 85;
return color1(0, WheelPos * 3, 255 - WheelPos * 3);
}
else
{
WheelPos -= 170;
return color1(WheelPos * 3, 255 - WheelPos * 3, 0);
}
}

// Update the Rainbow Cycle Pattern
void RainbowCycleUpdate()
{
for(int i=0; i< LEDCount; i++)
{
Wheel(((i * 256 / LEDCount) + Index) & 255);
LED1.set_crgb_at(i, value);
if (IrReceiver.decode())
{
val = IrReceiver.decodedIRData.command; // Print "old" raw data
if(val != 21)
{
value.b = 0; value.g = 0; value.r = 0;
for(int m = 0; m < LEDCount; m++)
{
LED1.set_crgb_at(m, value);
}
// Sends the data to the LEDs
LED1.sync();
break;
}
IrReceiver.resume(); // Enable receiving of the next value
}
//LED1.sync();
//delay(50);
//Index++;
}
LED1.sync();
//delay(50);
Index++;
}

void pattern9()
{
while(1)
{
RainbowCycleUpdate();
if (IrReceiver.decode())
{
val = IrReceiver.decodedIRData.command; // Print "old" raw data
if(val != 21)
{
value.b = 0; value.g = 0; value.r = 0;
for(int m = 0; m < LEDCount; m++)
{
LED1.set_crgb_at(m, value);
}
// Sends the data to the LEDs
LED1.sync();
break;
}
IrReceiver.resume(); // Enable receiving of the next value
}
}
}

uint8_t col_val(uint8_t col)
{
if((col < 255) && (col >= 0))
{
col = col + 1;
}
else
{
col = 0;
}
return col;
}