From bec8025f0ab1cea55fc58039baa98cf5d87e3790 Mon Sep 17 00:00:00 2001 From: Ashley Strahle Date: Tue, 23 Jun 2026 14:39:46 +0000 Subject: [PATCH] Add rawled bit-bang command, restore FastLED --- include/pixel_stomp_mux.h | 5 ++--- platformio.ini | 2 +- src/main.cpp | 28 ++++++++++++++++++++++++++++ src/pixel_stomp_mux.cpp | 32 +++++++++++++++----------------- 4 files changed, 46 insertions(+), 21 deletions(-) diff --git a/include/pixel_stomp_mux.h b/include/pixel_stomp_mux.h index d981028..1959f26 100644 --- a/include/pixel_stomp_mux.h +++ b/include/pixel_stomp_mux.h @@ -1,7 +1,7 @@ #pragma once #include -#include +#include class PixelStompMux { public: @@ -23,12 +23,11 @@ public: void dump(); void probe(); -private: uint8_t pin_dat; uint8_t pin_ld; uint8_t pin_clk; uint8_t pin_di; - Adafruit_NeoPixel strip; + CRGB leds[NUM_LEDS]; uint8_t last_button_state; }; diff --git a/platformio.ini b/platformio.ini index 55a86ec..9ea2aee 100644 --- a/platformio.ini +++ b/platformio.ini @@ -8,7 +8,7 @@ framework = arduino lib_deps = adafruit/Adafruit TinyUSB Library@^2.0.0 - adafruit/Adafruit NeoPixel@^1.12.0 + fastled/FastLED@^3.9.0 build_flags = -DARDUINO_USB_MODE=1 diff --git a/src/main.cpp b/src/main.cpp index 559fe40..67816ae 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -121,6 +121,34 @@ void handle_serial_command(const String& cmd) { Serial.println(" red/green/blue - solid colour"); Serial.println(" pixel0/pixel1 - single pixel test"); 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 { Serial.println("[CMD] Unknown command. Type 'help'"); } diff --git a/src/pixel_stomp_mux.cpp b/src/pixel_stomp_mux.cpp index ec62629..7c7ece7 100644 --- a/src/pixel_stomp_mux.cpp +++ b/src/pixel_stomp_mux.cpp @@ -5,7 +5,6 @@ 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), - strip(NUM_LEDS, dat, NEO_GRB + NEO_KHZ800), last_button_state(0) { } @@ -19,9 +18,10 @@ void PixelStompMux::begin() { delay(100); - strip.begin(); - strip.setBrightness(128); - strip.show(); + FastLED.addLeds(leds, NUM_LEDS); + FastLED.setBrightness(128); + fill_solid(leds, NUM_LEDS, CRGB::Black); + FastLED.show(); Serial.printf("[MUX] Init DAT=%d LD=%d CLK=%d DI=%d\n", 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) { 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) { - strip.setBrightness(brightness); + FastLED.setBrightness(brightness); } void PixelStompMux::clear_all() { - for (int i = 0; i < NUM_LEDS; i++) { - strip.setPixelColor(i, 0, 0, 0); - } - strip.show(); + fill_solid(leds, NUM_LEDS, CRGB::Black); + FastLED.show(); Serial.println("[MUX] LEDs cleared"); } void PixelStompMux::show() { - strip.show(); + FastLED.show(); } void PixelStompMux::dump() { @@ -92,7 +90,7 @@ void PixelStompMux::dump() { } void PixelStompMux::probe() { - Serial.println("[MUX] === Hardware Probe (NeoPixel) ==="); + Serial.println("[MUX] === Hardware Probe ==="); for (int round = 0; round < 5; round++) { Serial.printf("--- Round %d ---\n", round); @@ -123,12 +121,12 @@ void PixelStompMux::probe() { } Serial.println(" LED test: pixel 0 RED (max brightness)..."); - strip.setBrightness(255); - strip.setPixelColor(0, 255, 0, 0); - strip.show(); + leds[0] = CRGB(255, 0, 0); + FastLED.setBrightness(255); + FastLED.show(); delay(2000); - strip.setPixelColor(0, 0, 0, 0); - strip.show(); + leds[0] = CRGB::Black; + FastLED.show(); Serial.println("[MUX] === Probe Complete ==="); }