Fix rawled: GRB RED={0x00,0xFF,0x00}, differentiate 0/1 bit timing
This commit is contained in:
+13
-16
@@ -125,29 +125,26 @@ void handle_serial_command(const String& cmd) {
|
||||
} else if (cmd == "rawled") {
|
||||
uint8_t pin = 9;
|
||||
Serial.println("[CMD] Bit-bang WS2812: pixel 0 = RED on GPIO 9");
|
||||
uint32_t colour = 0x00FF00;
|
||||
uint8_t colour[] = {0x00, 0xFF, 0x00};
|
||||
noInterrupts();
|
||||
for (int i = 0; i < 24; i++) {
|
||||
if (colour & (1 << (23 - i))) {
|
||||
digitalWrite(pin, HIGH);
|
||||
esp_rom_delay_us(800);
|
||||
digitalWrite(pin, LOW);
|
||||
esp_rom_delay_us(450);
|
||||
} else {
|
||||
digitalWrite(pin, HIGH);
|
||||
esp_rom_delay_us(400);
|
||||
digitalWrite(pin, LOW);
|
||||
esp_rom_delay_us(850);
|
||||
for (int byte_idx = 0; byte_idx < 3; byte_idx++) {
|
||||
uint8_t val = colour[byte_idx];
|
||||
for (int bit = 7; bit >= 0; bit--) {
|
||||
gpio_set_level((gpio_num_t)pin, 1);
|
||||
if (val & (1 << bit)) {
|
||||
esp_rom_delay_us(1);
|
||||
}
|
||||
gpio_set_level((gpio_num_t)pin, 0);
|
||||
if (!(val & (1 << bit))) {
|
||||
esp_rom_delay_us(1);
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < 7; i++) {
|
||||
digitalWrite(pin, LOW);
|
||||
}
|
||||
gpio_set_level((gpio_num_t)pin, 0);
|
||||
esp_rom_delay_us(50);
|
||||
}
|
||||
interrupts();
|
||||
Serial.println("[CMD] Sent. Wait 2 sec...");
|
||||
delay(2000);
|
||||
digitalWrite(pin, LOW);
|
||||
Serial.println("[CMD] Done");
|
||||
} else {
|
||||
Serial.println("[CMD] Unknown command. Type 'help'");
|
||||
|
||||
Reference in New Issue
Block a user