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