Fix USB MIDI, add GPIO for switches and LEDs

- Remove TinyUSBDevice.begin() conflict with Arduino core
- Switch stub now reads GPIO with debounce (pins 1-10)
- LED stub now drives GPIO pins (pins 11-20) with startup animation
- All pins printed to console on init
This commit is contained in:
2026-06-23 13:18:20 +00:00
parent 22572b9baa
commit bb32ec65d1
3 changed files with 56 additions and 32 deletions
+21 -26
View File
@@ -1,6 +1,10 @@
#include "led_stub.h"
#include <Arduino.h>
static const uint8_t LED_PINS[10] = {
11, 12, 13, 14, 15, 16, 17, 18, 19, 20
};
DefaultLedStub::DefaultLedStub() : initialized(false) {
for (int i = 0; i < NUM_LEDS; i++) {
led_states[i].active = false;
@@ -12,39 +16,25 @@ DefaultLedStub::DefaultLedStub() : initialized(false) {
}
void DefaultLedStub::begin() {
for (int i = 0; i < NUM_LEDS; i++) {
pinMode(LED_PINS[i], OUTPUT);
digitalWrite(LED_PINS[i], LOW);
}
initialized = true;
Serial.println("[LED] Startup colour cycle...");
uint16_t colours[] = {
0xF800, // Red
0x07E0, // Green
0x001F, // Blue
0xFFE0, // Yellow
0xF81F, // Magenta
0x07FF, // Cyan
0xFFFF, // White
};
int num_colours = sizeof(colours) / sizeof(colours[0]);
for (int c = 0; c < num_colours; c++) {
uint16_t colour = colours[c];
uint8_t r = (colour >> 11) & 0x1F;
uint8_t g = (colour >> 5) & 0x3F;
uint8_t b = colour & 0x1F;
for (int i = 0; i < NUM_LEDS; i++) {
led_states[i].note = i;
led_states[i].channel = 1;
led_states[i].velocity = 100;
led_states[i].active = true;
led_states[i].timestamp = millis();
}
Serial.printf("[LED] Colour %d: R=%d G=%d B=%d\n", c, r, g, b);
for (int i = 0; i < NUM_LEDS; i++) {
digitalWrite(LED_PINS[i], HIGH);
Serial.printf("[LED] LED %d ON (GPIO %d)\n", i, LED_PINS[i]);
delay(100);
}
for (int i = 0; i < NUM_LEDS; i++) {
digitalWrite(LED_PINS[i], LOW);
delay(50);
}
clear_all();
Serial.println("[LED] Startup cycle complete");
}
@@ -60,6 +50,8 @@ void DefaultLedStub::set_led_state(uint8_t note, uint8_t channel, uint8_t veloci
led_states[led_index].velocity = velocity;
led_states[led_index].active = (velocity > 0);
led_states[led_index].timestamp = millis();
digitalWrite(LED_PINS[led_index], velocity > 0 ? HIGH : LOW);
Serial.printf("[LED] Note %d -> LED %d Ch %d Vel %d (%s)\n",
note, led_index, channel, velocity,
@@ -73,6 +65,9 @@ void DefaultLedStub::clear_all() {
for (int i = 0; i < NUM_LEDS; i++) {
led_states[i].active = false;
led_states[i].velocity = 0;
if (initialized) {
digitalWrite(LED_PINS[i], LOW);
}
}
Serial.println("[LED] All LEDs cleared");
}