Olá pessoal,
Estou desenvolvendo um footswitch MIDI com Arduino Leonardo e USB Host Shield para controlar minha pedaleira Boss GT-1 via USB. O display I2C (LCD 1602 com PCF8574) funciona perfeitamente e o Arduino inicializa corretamente. No entanto, a GT-1 não responde às mensagens MIDI, incluindo mensagens SysEx como a de ativação do modo editor. Mesmo usando um codigo mais simples com envio automatico de patch somente para teste ele nao responde, a pedaleira nao troca o patch
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Usb.h>
#include <usbh_midi.h>
// ------------------- LCD I2C -------------------
LiquidCrystal_I2C lcd(0x27, 16, 2); // Endereço I2C pode ser 0x3F ou 0x27
// ------------------- MIDI USB ------------------
USB Usb;
USBH_MIDI Midi(&Usb);
// ------------------- Botões --------------------
const byte BTN_QTD = 6;
const byte btnPins[BTN_QTD] = {A0, A1, A2, A3, A4, A5};
bool btnState[BTN_QTD] = {0};
bool lastBtnState[BTN_QTD] = {0};
// ------------------- Setup ---------------------
void setup() {
lcd.init();
lcd.backlight();
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("GT-1 Footswitch");
Serial.begin(115200);
if (Usb.Init() == -1) {
lcd.setCursor(0, 1);
lcd.print("USB Error");
while (1); // trava
}
// Inicializar pinos dos botões
for (byte i = 0; i < BTN_QTD; i++) {
pinMode(btnPins[i], INPUT_PULLUP);
}
delay(3000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Modo Edit...");
enviarModoEdit();
}
// ------------------- Loop ---------------------
void loop() {
Usb.Task();
for (byte i = 0; i < BTN_QTD; i++) {
btnState[i] = !digitalRead(btnPins[i]); // Ativo em LOW
if (btnState[i] && !lastBtnState[i]) {
enviarSysExLeituraPatch(i); // Patches 0 a 5
lcd.setCursor(0, 1);
lcd.print("Patch: U");
lcd.print((i + 1) < 10 ? "0" : "");
lcd.print(i + 1);
lcd.print(" ");
}
lastBtnState[i] = btnState[i];
}
}
// ------------------- SysEx: Modo Editor ---------------------
void enviarModoEdit() {
byte editMode[] = {
0xF0, 0x41, 0x00, 0x00, 0x00, 0x00,
0x30, 0x12, 0x7F, 0x00, 0x00, 0x01, 0x01, 0x7F, 0xF7
};
Midi.SendSysEx(sizeof(editMode), editMode, true);
}
// ------------------- SysEx: Leitura Patch ---------------------
void enviarSysExLeituraPatch(byte patch) {
if (patch > 35) return; // Limite máximo: U36
byte sysexBase[] = {
0xF0, 0x41, 0x00, 0x00, 0x00, 0x00,
0x30, 0x12, 0x00, 0x01, 0x00, 0x00, 0x00, patch, 0x00, 0xF7
};
byte chk = 0;
for (byte i = 5; i <= 13; i++) chk += sysexBase[i];
chk = (128 - (chk % 128)) & 0x7F;
sysexBase[14] = chk;
Midi.SendSysEx(sizeof(sysexBase), sysexBase, true);
}