Hello
I have written following code for my Status Display!
I can control every single led via Serial command:
sr 0 // static red on led "0"
sg 1 // static green on led "1"
bb 5 // blinking blue on led "5"
br 6 // blinking red on led "6"
bg 7 // blinking red on led "7"
off 5 // set led 5 to BLACK...and so on...
Led are synchronized in Blinking mode.
My Problem is, that the first LED begins to flickering, when i switch on one of the other LED!
All other functions and LEDs are ok - please can somebody test my CODE, to understand my problem!
thanks in advance ![]()
In the WS2812FX.h library i have changed following:
/* each segment uses 36 bytes of SRAM memory, so if you're application fails because of
insufficient memory, decreasing MAX_NUM_SEGMENTS may help /
#define MAX_NUM_SEGMENTS 16
#define NUM_COLORS 3 / number of colors per segment */
#define MAX_CUSTOM_MODES 4
#define SEGMENT _segments[_segment_index]
#define SEGMENT_RUNTIME _segment_runtimes[_segment_index]
#define SEGMENT_LENGTH 1
/*
Status_Display V5.0
CHANGELOG
2019-12-02 Version 5.0 (by XXX)
*/
#define REDUCED_MODES // sketch too big for Arduino Leonardo flash, so invoke reduced modes
#include <WS2812FX.h>
#define LED_COUNT 16
#define LED_PIN 5
#define MAX_NUM_CHARS 16 // maximum number of characters read from the Serial Monitor
WS2812FX ws2812fx = WS2812FX(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
char cmd[MAX_NUM_CHARS]; // char[] to store incoming serial commands
boolean cmd_complete = false; // whether the command string is complete
void setup() {
Serial.begin(115200);
ws2812fx.init();
ws2812fx.setBrightness(20);
ws2812fx.setSpeed(1000);
ws2812fx.setColor(0x000000);
ws2812fx.setMode(FX_MODE_STATIC);
ws2812fx.start();
//printUsage();
}
void loop() {
ws2812fx.service();
recvChar(); // read serial comm
if(cmd_complete) {
process_command();
}
}
/*
* Checks received command and calls corresponding functions.
*/
void process_command() {
if (strncmp(cmd,"sr ",3) == 0) { //Set "sr" Static Red to LED Number "a"
uint8_t a = (uint8_t)atoi(cmd + 3);
ws2812fx.setSegment((a), (a), (a), FX_MODE_STATIC, RED, 1000, false);
Serial.print(F("ROT LEUCHTEN Led: "));
Serial.println((a));
}
if (strncmp(cmd,"sg ",3) == 0) {
uint8_t b = (uint8_t)atoi(cmd + 3);
ws2812fx.setSegment((b), (b), (b), FX_MODE_STATIC, GREEN, 1000, false);
Serial.print(F("GRÜN LEUCHTEN Led: "));
Serial.println((b));
}
if (strncmp(cmd,"sb ",3) == 0) {
uint8_t c = (uint8_t)atoi(cmd + 3);
ws2812fx.setSegment((c), (c), (c), FX_MODE_STATIC, BLUE, 1000, false);
Serial.print(F("BLAU LEUCHTEN Led: "));
Serial.println((c));
}
if (strncmp(cmd,"sl ",3) == 0) {
uint8_t d = (uint8_t)atoi(cmd + 3);
ws2812fx.setSegment((d), (d), (d), FX_MODE_STATIC, YELLOW, 1000, false);
Serial.print(F("GELB LEUCHTEN Led: "));
Serial.println((d));
}
if (strncmp(cmd,"br ",3) == 0) {
uint8_t e = (uint8_t)atoi(cmd + 3);
ws2812fx.setSegment((e), (e), (e), FX_MODE_BLINK, RED, 1000, false);
Serial.print(F("ROT BLINKEN Led: "));
Serial.println((e));
}
if (strncmp(cmd,"bg ",3) == 0) {
uint8_t f = (uint8_t)atoi(cmd + 3);
ws2812fx.setSegment((f), (f), (f), FX_MODE_BLINK, GREEN, 1000, false);
Serial.print(F("GRÜN BLINKEN Led: "));
Serial.println((f));
}
if (strncmp(cmd,"bb ",3) == 0) {
uint8_t g = (uint8_t)atoi(cmd + 3);
ws2812fx.setSegment((g), (g), (g), FX_MODE_BLINK, BLUE, 1000, false);
Serial.print(F("BLAU BLINKEN Led: "));
Serial.println((g));
}
else if (strncmp(cmd,"off ",4) == 0) {
uint8_t h = (uint8_t)atoi(cmd + 4);
ws2812fx.setSegment((h), (h), (h), FX_MODE_STATIC, BLACK, 1000, false);
Serial.print(F("Clear Led: "));
Serial.println((h));
}
cmd[0] = '\0'; // reset the commandstring
cmd_complete = false; // reset command complete
}
/*
* Reads new input from serial to cmd string. Command is completed on \n
*/
void recvChar(void) {
static byte index = 0;
while (Serial.available() > 0 && cmd_complete == false) {
char rc = Serial.read();
if (rc != '\n') {
if(index < MAX_NUM_CHARS) cmd[index++] = rc;
} else {
cmd[index] = '\0'; // terminate the string
index = 0;
cmd_complete = true;
Serial.print("received '"); Serial.print(cmd); Serial.println("'");
}
}
}