Fix NUM_LEDS=10, NUM_BUTTONS=16 for 2 daisy-chained MUX boards. Fix pixel7 stuck blue (was only sending 8 LED data to 10-LED chain)

This commit is contained in:
2026-06-23 22:43:53 +00:00
parent be36ba9bf4
commit 9a56591453
5 changed files with 26 additions and 28 deletions
+1 -1
View File
@@ -27,7 +27,7 @@ class PixelStompMux;
class DefaultLedStub : public LedStub {
private:
static const uint8_t NUM_LEDS = 8;
static const uint8_t NUM_LEDS = 10;
LedState led_states[NUM_LEDS];
bool initialized;
+4 -4
View File
@@ -5,14 +5,14 @@
class PixelStompMux {
public:
static const uint8_t NUM_BUTTONS = 8;
static const uint8_t NUM_LEDS = 8;
static const uint8_t NUM_BUTTONS = 16;
static const uint8_t NUM_LEDS = 10;
PixelStompMux(uint8_t dat_pin, uint8_t ld_pin, uint8_t clk_pin, uint8_t di_pin);
void begin();
uint8_t read_buttons();
uint16_t read_buttons();
bool is_button_pressed(uint8_t index);
void set_led_color(uint8_t index, uint8_t r, uint8_t g, uint8_t b);
@@ -29,5 +29,5 @@ public:
uint8_t pin_di;
CRGB leds[NUM_LEDS];
uint8_t last_button_state;
uint16_t last_button_state;
};
+1 -1
View File
@@ -25,7 +25,7 @@ class PixelStompMux;
class DefaultSwitchStub : public SwitchStub {
private:
static const uint8_t NUM_SWITCHES = 8;
static const uint8_t NUM_SWITCHES = 16;
SwitchState switch_states[NUM_SWITCHES];
bool initialized;
+9 -9
View File
@@ -35,7 +35,7 @@ void handle_serial_command(const String& cmd) {
} else if (cmd == "probe" || cmd == "p") {
mux.probe();
} else if (cmd == "ledon") {
for (int i = 0; i < 8; i++) {
for (int i = 0; i < PixelStompMux::NUM_LEDS; i++) {
mux.set_led_color(i, 255, 255, 255);
}
mux.show();
@@ -48,7 +48,7 @@ void handle_serial_command(const String& cmd) {
uint8_t r = (colors[c] >> 16) & 0xFF;
uint8_t g = (colors[c] >> 8) & 0xFF;
uint8_t b = colors[c] & 0xFF;
for (int i = 0; i < 8; i++) {
for (int i = 0; i < PixelStompMux::NUM_LEDS; i++) {
mux.set_led_color(i, r, g, b);
}
mux.show();
@@ -57,20 +57,20 @@ void handle_serial_command(const String& cmd) {
mux.clear_all();
Serial.println("[CMD] LED test complete");
} else if (cmd == "read") {
uint8_t raw = mux.read_buttons();
Serial.printf("[CMD] Raw: 0x%02X (", raw);
for (int i = 7; i >= 0; i--) {
uint16_t raw = mux.read_buttons();
Serial.printf("[CMD] Raw: 0x%04X (", raw);
for (int i = 15; i >= 0; i--) {
Serial.print((raw >> i) & 1);
}
Serial.println(")");
} else if (cmd == "red") {
for (int i = 0; i < 8; i++) mux.set_led_color(i, 255, 0, 0);
for (int i = 0; i < PixelStompMux::NUM_LEDS; i++) mux.set_led_color(i, 255, 0, 0);
mux.show();
} else if (cmd == "green") {
for (int i = 0; i < 8; i++) mux.set_led_color(i, 0, 255, 0);
for (int i = 0; i < PixelStompMux::NUM_LEDS; i++) mux.set_led_color(i, 0, 255, 0);
mux.show();
} else if (cmd == "blue") {
for (int i = 0; i < 8; i++) mux.set_led_color(i, 0, 0, 255);
for (int i = 0; i < PixelStompMux::NUM_LEDS; i++) mux.set_led_color(i, 0, 0, 255);
mux.show();
} else if (cmd == "pixel0") {
mux.set_led_brightness(255);
@@ -133,7 +133,7 @@ void handle_serial_command(const String& cmd) {
uint8_t g = (colors[c] >> 8) & 0xFF;
uint8_t b = colors[c] & 0xFF;
Serial.printf(" Colour %d: #%06X\n", c, colors[c]);
for (int i = 0; i < 8; i++) mux.set_led_color(i, r, g, b);
for (int i = 0; i < PixelStompMux::NUM_LEDS; i++) mux.set_led_color(i, r, g, b);
mux.show();
delay(500);
}
+11 -13
View File
@@ -28,7 +28,7 @@ void PixelStompMux::begin() {
Serial.printf("[MUX] DI raw at init: %d\n", digitalRead(pin_di));
}
uint8_t PixelStompMux::read_buttons() {
uint16_t PixelStompMux::read_buttons() {
digitalWrite(pin_clk, LOW);
delayMicroseconds(BMC_MUX_74HC165_DELAY);
@@ -37,8 +37,8 @@ uint8_t PixelStompMux::read_buttons() {
digitalWrite(pin_ld, HIGH);
delayMicroseconds(BMC_MUX_74HC165_DELAY);
uint8_t data = 0;
for (int i = 7; i >= 0; i--) {
uint16_t data = 0;
for (int i = 15; i >= 0; i--) {
bitWrite(data, i, digitalRead(pin_di));
digitalWrite(pin_clk, HIGH);
delayMicroseconds(BMC_MUX_74HC165_DELAY);
@@ -52,7 +52,7 @@ uint8_t PixelStompMux::read_buttons() {
bool PixelStompMux::is_button_pressed(uint8_t index) {
if (index >= NUM_BUTTONS) return false;
uint8_t state = read_buttons();
uint16_t state = read_buttons();
return !(state & (1 << index));
}
@@ -76,9 +76,9 @@ void PixelStompMux::show() {
}
void PixelStompMux::dump() {
uint8_t buttons = read_buttons();
Serial.printf("[MUX] Buttons: 0x%02X (", buttons);
for (int i = 7; i >= 0; i--) {
uint16_t buttons = read_buttons();
Serial.printf("[MUX] Buttons: 0x%04X (", buttons);
for (int i = 15; i >= 0; i--) {
Serial.print((buttons >> i) & 1);
}
Serial.println(")");
@@ -99,23 +99,21 @@ void PixelStompMux::probe() {
digitalWrite(pin_ld, HIGH);
delayMicroseconds(BMC_MUX_74HC165_DELAY);
Serial.printf(" Before latch: DI=%d\n", digitalRead(pin_di));
digitalWrite(pin_ld, LOW);
delayMicroseconds(BMC_MUX_74HC165_DELAY);
digitalWrite(pin_ld, HIGH);
delayMicroseconds(BMC_MUX_74HC165_DELAY);
Serial.printf(" After latch: DI=%d\n", digitalRead(pin_di));
for (int i = 0; i < 16; i++) {
uint16_t data = 0;
for (int i = 15; i >= 0; i--) {
bool bit_val = digitalRead(pin_di);
bitWrite(data, i, bit_val);
digitalWrite(pin_clk, HIGH);
delayMicroseconds(BMC_MUX_74HC165_DELAY);
digitalWrite(pin_clk, LOW);
delayMicroseconds(BMC_MUX_74HC165_DELAY);
Serial.printf(" CLK %2d: DI=%d\n", i, bit_val);
}
Serial.printf(" Round %d: 0x%04X\n", round, data);
delay(500);
}