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:
+9
-9
@@ -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
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user