Hello, sorry for any grammar mistakes and crappy code, i found adalight project for WS2418 LED strip and slightly customized it for myself. All i did is deleted useless functions and added standby mode. Basically it looks like if (Serial.available()) = turn standby mode on, when no input from adalight detected, everything works fine, but as soon as i turn off my monitor, standby lighting just freezes and turns off. When using adalight everything fine. So, basically Serial.available becomes unavailable with monitor off, why?
//issa.raven
//WS2812b led strip controller
//2019
//Settings
#define NUM_LEDS 94 // Num of Leds
#define DI_PIN 13 // Signal pin
#define OFF_TIME 20 // Switching off timer
#define CURRENT_LIMIT 2000 // Current limit, 0 for off
//Settings
unsigned long off_timer;
#define serialRate 115200 // Baudrate
uint8_t prefix[] = {'A', 'd', 'a'}, hi, lo, chk, i;
#include <FastLED.h>
CRGB leds[NUM_LEDS]; // Create LED strip
boolean led_state = true; // LED state
void setup()
{
FastLED.addLeds<WS2812, DI_PIN, GRB>(leds, NUM_LEDS);
if (CURRENT_LIMIT > 0) FastLED.setMaxPowerInVoltsAndMilliamps(5, CURRENT_LIMIT);
Serial.begin(serialRate);
Serial.print("Ada\n"); // connect to ambilight
}
void check_connection() {
if (led_state) {
if (millis() - off_timer > (OFF_TIME * 1000)) {
led_state = false;
FastLED.clear();
FastLED.show();
}
}
}
void loop() {
if (Serial.available()){
LEDS.setBrightness(50);
int pr_r, pr_g, pr_b;
pr_r = 0;
pr_g = 0;
pr_b = 0;
while (pr_r < 255 and pr_b < 255) {
LEDS.showColor(CRGB(pr_r, pr_g, pr_b));
pr_r++;
pr_b++;
delay(10);
}
while (pr_r > 0 and pr_b > 0) {
LEDS.showColor(CRGB(pr_r, pr_g, pr_b));
pr_r--;
pr_b--;
delay(10);
}
} else {
if (!led_state) led_state = true;
off_timer = millis();
for (i = 0; i < sizeof prefix; ++i) {
waitLoop: while (!Serial.available()) check_connection();;
if (prefix[i] == Serial.read()) continue;
i = 0;
goto waitLoop;
}
while (!Serial.available()) check_connection();;
hi = Serial.read();
while (!Serial.available()) check_connection();;
lo = Serial.read();
while (!Serial.available()) check_connection();;
chk = Serial.read();
if (chk != (hi ^ lo ^ 0x55))
{
i = 0;
goto waitLoop;
}
memset(leds, 0, NUM_LEDS * sizeof(struct CRGB));
for (uint8_t i = 0; i < NUM_LEDS; i++) {
byte r, g, b;
while (!Serial.available()) check_connection();
r = Serial.read();
while (!Serial.available()) check_connection();
g = Serial.read();
while (!Serial.available()) check_connection();
b = Serial.read();
leds[i].r = r;
leds[i].g = g;
leds[i].b = b;
}
FastLED.show();
}
}