Rewrite MUX: WS2812C LEDs (NeoPixel) + 74HC165 buttons
PixelStomp MUX uses: - WS2812C LEDs: one data line via DAT (GPIO 9), NeoPixel protocol - 74HC165 shift register: LD/CLK/DI for reading 8 button states Changes: - Use Adafruit NeoPixel library for LED control - Proper 74HC165 parallel-load shift-in for buttons - 8 switches + 8 LEDs (was incorrectly 10) - Diagnostic commands: dump, ledtest, red, green, blue, read
This commit is contained in:
+27
-27
@@ -31,45 +31,45 @@ void handle_serial_command(const String& cmd) {
|
||||
if (cmd == "dump" || cmd == "d") {
|
||||
mux.dump();
|
||||
} else if (cmd == "ledon") {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
mux.set_led(i, true);
|
||||
delay(50);
|
||||
for (int i = 0; i < 8; i++) {
|
||||
mux.set_led_color(i, 255, 255, 255);
|
||||
}
|
||||
mux.show();
|
||||
Serial.println("[CMD] All LEDs ON");
|
||||
} else if (cmd == "ledoff") {
|
||||
mux.clear_all();
|
||||
} else if (cmd == "ledtest") {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
mux.set_led(i, true);
|
||||
delay(200);
|
||||
mux.set_led(i, false);
|
||||
delay(100);
|
||||
uint32_t colors[] = {0xFF0000, 0x00FF00, 0x0000FF, 0xFFFF00, 0xFF00FF, 0x00FFFF};
|
||||
for (int c = 0; c < 6; c++) {
|
||||
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++) {
|
||||
mux.set_led_color(i, r, g, b);
|
||||
}
|
||||
mux.show();
|
||||
delay(300);
|
||||
}
|
||||
mux.clear_all();
|
||||
Serial.println("[CMD] LED test complete");
|
||||
} else if (cmd == "read") {
|
||||
uint16_t raw = mux.read_buttons();
|
||||
Serial.printf("[CMD] Raw button state: 0x%03X (binary: ", raw);
|
||||
for (int i = 9; i >= 0; i--) {
|
||||
uint8_t raw = mux.read_buttons();
|
||||
Serial.printf("[CMD] Raw: 0x%02X (", raw);
|
||||
for (int i = 7; i >= 0; i--) {
|
||||
Serial.print((raw >> i) & 1);
|
||||
}
|
||||
Serial.println(")");
|
||||
} else if (cmd == "probe") {
|
||||
Serial.println("[CMD] Probing MUX pins...");
|
||||
Serial.printf(" DAT (GPIO %d) = %d\n", 9, digitalRead(9));
|
||||
Serial.printf(" LD (GPIO %d) = %d\n", 10, digitalRead(10));
|
||||
Serial.printf(" CLK (GPIO %d) = %d\n", 11, digitalRead(11));
|
||||
Serial.printf(" DI (GPIO %d) = %d\n", 12, digitalRead(12));
|
||||
|
||||
Serial.println(" Toggling LD pin...");
|
||||
for (int i = 0; i < 5; i++) {
|
||||
digitalWrite(10, HIGH);
|
||||
delayMicroseconds(100);
|
||||
digitalWrite(10, LOW);
|
||||
delayMicroseconds(100);
|
||||
}
|
||||
Serial.printf(" DI after LD toggle: %d\n", digitalRead(12));
|
||||
} else if (cmd == "red") {
|
||||
for (int i = 0; i < 8; 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);
|
||||
mux.show();
|
||||
} else if (cmd == "blue") {
|
||||
for (int i = 0; i < 8; i++) mux.set_led_color(i, 0, 0, 255);
|
||||
mux.show();
|
||||
} else {
|
||||
Serial.println("[CMD] Commands: dump, ledon, ledoff, ledtest, read, probe");
|
||||
Serial.println("[CMD] Commands: dump, ledon, ledoff, ledtest, read, red, green, blue");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user