I'm really new on this and I just want to make a cheap midi pedalboard, I thought that the arduino mega would work for me since it has many digital pins, and it would be perfect for all the buttons that I want to use, I saw a tutorial where they used it but when it came time to buy I didn't realize that I chose the arduino CH340g, which When it came time to do the DFU I realized that I didn't have the pins to do it, I saw that there is an alternative using hairless but I'm not really sure how to do it and I'm not sure if the code that chatGPT gave me works for it. use it, when using other codes that I find on the internet it gives me many errors
// Potenciómetros conectados a A0 a A9
const int potPins[] = {A0, A1, A2, A3, A4, A5, A6, A7, A8, A9};
// Interruptores DPDT conectados a pines 2 a 9
const int dpdtPins[] = {2, 3, 4, 5, 6, 7, 8, 9};
// Footswitches 3PDT conectados a pines 22 a 30
const int switchPins[] = {22, 23, 24, 25, 26, 27, 28, 29, 30};
// LEDs de los footswitches conectados a pines 31 a 39
const int ledPins[] = {31, 32, 33, 34, 35, 36, 37, 38, 39};
void setup() {
Serial.begin(115200); // Iniciar comunicación serial
// Configurar pines de los potenciómetros como entradas
for (int i = 0; i < 10; i++) {
pinMode(potPins[i], INPUT);
}
// Configurar pines de los interruptores DPDT como entradas
for (int i = 0; i < 8; i++) {
pinMode(dpdtPins[i], INPUT_PULLUP); // Usar resistencias pull-up internas
}
// Configurar pines de los footswitches 3PDT como entradas
for (int i = 0; i < 9; i++) {
pinMode(switchPins[i], INPUT_PULLUP); // Usar resistencias pull-up internas
pinMode(ledPins[i], OUTPUT); // Configurar los pines de los LEDs como salidas
digitalWrite(ledPins[i], LOW); // Apagar los LEDs al inicio
}
}
void loop() {
// Leer los valores de los potenciómetros y enviar como Control Change en MIDI
for (int i = 0; i < 10; i++) {
int potValue = analogRead(potPins[i]);
sendControlChange(i, potValue / 8); // Los valores de los potenciómetros van de 0 a 127 en MIDI
}
// Leer los interruptores DPDT y enviar mensajes MIDI de Control Change (ejemplo)
for (int i = 0; i < 8; i++) {
int dpdtState = digitalRead(dpdtPins[i]);
if (dpdtState == LOW) {
sendControlChange(i + 10, 127); // Activar el control MIDI
} else {
sendControlChange(i + 10, 0); // Desactivar el control MIDI
}
}
// Leer los footswitches 3PDT y controlar los LEDs
for (int i = 0; i < 9; i++) {
int switchState = digitalRead(switchPins[i]);
if (switchState == LOW) { // Footswitch presionado
digitalWrite(ledPins[i], HIGH); // Enciende el LED
sendControlChange(i + 18, 127); // Enviar señal MIDI de control
} else {
digitalWrite(ledPins[i], LOW); // Apaga el LED
sendControlChange(i + 18, 0); // Apagar el control MIDI
}
}
delay(10); // Pequeña pausa para evitar saturar el bus MIDI
}
// Función para enviar un mensaje MIDI de Control Change
void sendControlChange(int controlNumber, int value) {
Serial.write(0xB0); // Mensaje de Control Change en el canal 1
Serial.write(controlNumber);
Serial.write(value);
}