Add rawled bit-bang command, restore FastLED
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <Adafruit_NeoPixel.h>
|
#include <FastLED.h>
|
||||||
|
|
||||||
class PixelStompMux {
|
class PixelStompMux {
|
||||||
public:
|
public:
|
||||||
@@ -23,12 +23,11 @@ public:
|
|||||||
void dump();
|
void dump();
|
||||||
void probe();
|
void probe();
|
||||||
|
|
||||||
private:
|
|
||||||
uint8_t pin_dat;
|
uint8_t pin_dat;
|
||||||
uint8_t pin_ld;
|
uint8_t pin_ld;
|
||||||
uint8_t pin_clk;
|
uint8_t pin_clk;
|
||||||
uint8_t pin_di;
|
uint8_t pin_di;
|
||||||
|
|
||||||
Adafruit_NeoPixel strip;
|
CRGB leds[NUM_LEDS];
|
||||||
uint8_t last_button_state;
|
uint8_t last_button_state;
|
||||||
};
|
};
|
||||||
|
|||||||
+1
-1
@@ -8,7 +8,7 @@ framework = arduino
|
|||||||
|
|
||||||
lib_deps =
|
lib_deps =
|
||||||
adafruit/Adafruit TinyUSB Library@^2.0.0
|
adafruit/Adafruit TinyUSB Library@^2.0.0
|
||||||
adafruit/Adafruit NeoPixel@^1.12.0
|
fastled/FastLED@^3.9.0
|
||||||
|
|
||||||
build_flags =
|
build_flags =
|
||||||
-DARDUINO_USB_MODE=1
|
-DARDUINO_USB_MODE=1
|
||||||
|
|||||||
@@ -121,6 +121,34 @@ void handle_serial_command(const String& cmd) {
|
|||||||
Serial.println(" red/green/blue - solid colour");
|
Serial.println(" red/green/blue - solid colour");
|
||||||
Serial.println(" pixel0/pixel1 - single pixel test");
|
Serial.println(" pixel0/pixel1 - single pixel test");
|
||||||
Serial.println(" gpiotest - raw GPIO pin diagnostic");
|
Serial.println(" gpiotest - raw GPIO pin diagnostic");
|
||||||
|
Serial.println(" rawled - bit-bang WS2812 (no library)");
|
||||||
|
} else if (cmd == "rawled") {
|
||||||
|
uint8_t pin = 9;
|
||||||
|
Serial.println("[CMD] Bit-bang WS2812: pixel 0 = RED on GPIO 9");
|
||||||
|
uint32_t colour = 0x00FF00;
|
||||||
|
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 i = 0; i < 7; i++) {
|
||||||
|
digitalWrite(pin, LOW);
|
||||||
|
esp_rom_delay_us(50);
|
||||||
|
}
|
||||||
|
interrupts();
|
||||||
|
Serial.println("[CMD] Sent. Wait 2 sec...");
|
||||||
|
delay(2000);
|
||||||
|
digitalWrite(pin, LOW);
|
||||||
|
Serial.println("[CMD] Done");
|
||||||
} else {
|
} else {
|
||||||
Serial.println("[CMD] Unknown command. Type 'help'");
|
Serial.println("[CMD] Unknown command. Type 'help'");
|
||||||
}
|
}
|
||||||
|
|||||||
+15
-17
@@ -5,7 +5,6 @@
|
|||||||
|
|
||||||
PixelStompMux::PixelStompMux(uint8_t dat, uint8_t ld, uint8_t clk, uint8_t di)
|
PixelStompMux::PixelStompMux(uint8_t dat, uint8_t ld, uint8_t clk, uint8_t di)
|
||||||
: pin_dat(dat), pin_ld(ld), pin_clk(clk), pin_di(di),
|
: pin_dat(dat), pin_ld(ld), pin_clk(clk), pin_di(di),
|
||||||
strip(NUM_LEDS, dat, NEO_GRB + NEO_KHZ800),
|
|
||||||
last_button_state(0) {
|
last_button_state(0) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -19,9 +18,10 @@ void PixelStompMux::begin() {
|
|||||||
|
|
||||||
delay(100);
|
delay(100);
|
||||||
|
|
||||||
strip.begin();
|
FastLED.addLeds<WS2812, 9, GRB>(leds, NUM_LEDS);
|
||||||
strip.setBrightness(128);
|
FastLED.setBrightness(128);
|
||||||
strip.show();
|
fill_solid(leds, NUM_LEDS, CRGB::Black);
|
||||||
|
FastLED.show();
|
||||||
|
|
||||||
Serial.printf("[MUX] Init DAT=%d LD=%d CLK=%d DI=%d\n",
|
Serial.printf("[MUX] Init DAT=%d LD=%d CLK=%d DI=%d\n",
|
||||||
pin_dat, pin_ld, pin_clk, pin_di);
|
pin_dat, pin_ld, pin_clk, pin_di);
|
||||||
@@ -58,23 +58,21 @@ bool PixelStompMux::is_button_pressed(uint8_t index) {
|
|||||||
|
|
||||||
void PixelStompMux::set_led_color(uint8_t index, uint8_t r, uint8_t g, uint8_t b) {
|
void PixelStompMux::set_led_color(uint8_t index, uint8_t r, uint8_t g, uint8_t b) {
|
||||||
if (index >= NUM_LEDS) return;
|
if (index >= NUM_LEDS) return;
|
||||||
strip.setPixelColor(index, r, g, b);
|
leds[index] = CRGB(r, g, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PixelStompMux::set_led_brightness(uint8_t brightness) {
|
void PixelStompMux::set_led_brightness(uint8_t brightness) {
|
||||||
strip.setBrightness(brightness);
|
FastLED.setBrightness(brightness);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PixelStompMux::clear_all() {
|
void PixelStompMux::clear_all() {
|
||||||
for (int i = 0; i < NUM_LEDS; i++) {
|
fill_solid(leds, NUM_LEDS, CRGB::Black);
|
||||||
strip.setPixelColor(i, 0, 0, 0);
|
FastLED.show();
|
||||||
}
|
|
||||||
strip.show();
|
|
||||||
Serial.println("[MUX] LEDs cleared");
|
Serial.println("[MUX] LEDs cleared");
|
||||||
}
|
}
|
||||||
|
|
||||||
void PixelStompMux::show() {
|
void PixelStompMux::show() {
|
||||||
strip.show();
|
FastLED.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PixelStompMux::dump() {
|
void PixelStompMux::dump() {
|
||||||
@@ -92,7 +90,7 @@ void PixelStompMux::dump() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PixelStompMux::probe() {
|
void PixelStompMux::probe() {
|
||||||
Serial.println("[MUX] === Hardware Probe (NeoPixel) ===");
|
Serial.println("[MUX] === Hardware Probe ===");
|
||||||
|
|
||||||
for (int round = 0; round < 5; round++) {
|
for (int round = 0; round < 5; round++) {
|
||||||
Serial.printf("--- Round %d ---\n", round);
|
Serial.printf("--- Round %d ---\n", round);
|
||||||
@@ -123,12 +121,12 @@ void PixelStompMux::probe() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Serial.println(" LED test: pixel 0 RED (max brightness)...");
|
Serial.println(" LED test: pixel 0 RED (max brightness)...");
|
||||||
strip.setBrightness(255);
|
leds[0] = CRGB(255, 0, 0);
|
||||||
strip.setPixelColor(0, 255, 0, 0);
|
FastLED.setBrightness(255);
|
||||||
strip.show();
|
FastLED.show();
|
||||||
delay(2000);
|
delay(2000);
|
||||||
strip.setPixelColor(0, 0, 0, 0);
|
leds[0] = CRGB::Black;
|
||||||
strip.show();
|
FastLED.show();
|
||||||
|
|
||||||
Serial.println("[MUX] === Probe Complete ===");
|
Serial.println("[MUX] === Probe Complete ===");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user