Stops working after some time
Opened this issue · 0 comments
Ae-Mc commented
I'm using ATmega32 with ws2812 LED strip with 100 physical leds (150 in programm) on 11059200 frequency.
Program works correctly until some random moment. After that moment, blutooth continues working, but library doesn't.
Posting code below (I slightly changed your library — replaced private
with protected
):
#include <WS2812.h>
#include "Arduino.h"
#include "consts.hpp"
class ExtendedWS2812 : public WS2812 {
public:
ExtendedWS2812() = delete;
ExtendedWS2812(uint16_t leds_count, uint8_t *pixels, uint8_t pin)
: WS2812(0) {
this->pixels = pixels;
this->count_led = leds_count;
setOutput(pin);
#ifdef RGB_ORDER_ON_RUNTIME
offsetGreen = 0;
offsetRed = 1;
offsetBlue = 2;
#endif
}
void clear() {
for (uint16_t i = 0; i < count_led; i++) {
pixels[i] = uint8_t(0);
pixels[i + 1] = uint8_t(0);
pixels[i + 2] = uint8_t(0);
}
}
};
uint8_t pixels_per_bank[BANKS_COUNT][LEDS_PER_BANK * 3];
// cRGB bank_leds[4][LEDS_PER_BANK];
ExtendedWS2812 banks[BANKS_COUNT] = {
ExtendedWS2812(LEDS_PER_BANK, pixels_per_bank[0], bank_pins[0]),
ExtendedWS2812(LEDS_PER_BANK, pixels_per_bank[1], bank_pins[1]),
ExtendedWS2812(LEDS_PER_BANK, pixels_per_bank[2], bank_pins[2]),
ExtendedWS2812(LEDS_PER_BANK, pixels_per_bank[3], bank_pins[3]),
};
auto &uart = Serial;
uint8_t buffer[6], buf_counter = 0;
unsigned long last_byte_millis = millis();
void proceed_command(uint8_t command[6]);
void setup() {
uart.begin(BT_BAUD);
for (auto i = 0; i < BANKS_COUNT; i++) {
banks[i].setColorOrderRGB();
}
}
void loop() {
// if (last_byte_millis > millis()) {
// last_byte_millis = millis();
// }
// if (buf_counter > 0 &&
// millis() - last_byte_millis > COMMAND_WAIT_TIMEOUT_MS) {
// buf_counter = 0;
// uart.write('r');
// }
if (uart.available()) {
last_byte_millis = millis();
buffer[buf_counter] = uart.read();
buf_counter = (buf_counter + 1) % 6;
if (buf_counter == 0) {
proceed_command(buffer);
uart.write('k');
}
}
}
void proceed_command(uint8_t command[6]) {
switch (command[0]) {
case 0x6C: // Set one led
if (command[1] < 1 || command[1] > 4 ||
command[2] >= LEDS_PER_BANK) {
return;
}
banks[command[1] - 1].set_crgb_at(
command[2], cRGB{command[3], command[4], command[5]});
break;
case 0x6E: // Clear
for (auto i = 0; i < BANKS_COUNT; i++) {
banks[i].clear();
}
break;
case 0x73: // Apply
for (auto i = 0; i < BANKS_COUNT; i++) {
banks[i].sync();
}
break;
}
}
So, after some time I still receive k
on phone, but LED stops working and doesn't change at all.
Can you help me?