Arduino micro midi problem

I created a 3 channel midi controller using Arduino micro. I got help from chatgpt in the code section. But there is a problem. The platform where I placed the Arduino is an old footswitch. The buttons of this pedal work as toggle. It is not momentary .

The problem is that when I press a button twice, I can only switch between channels. I could not solve this problem. Can you help me?

the clone i use

The code I use

#include <MIDIUSB.h>

// Buton ve LED Pinleri
const int buttonPins[3] = {2, 3, 4};
const int ledPins[3] = {5, 6, 7};  // LED pinlerini belirledik
bool lastButtonState[3] = {HIGH, HIGH, HIGH};
bool buttonPressed[3] = {false, false, false};

// MIDI Program Change Numaraları (Amplitube preset numaraları)
const byte presetNumbers[3] = {0, 1, 2};  // Amplitube Preset 1, 2 ve 3
int activePreset = -1;

void setup() {
    for (int i = 0; i < 3; i++) {
        pinMode(buttonPins[i], INPUT_PULLUP);
        pinMode(ledPins[i], OUTPUT);  // LED pinlerini çıkış olarak belirledik
        digitalWrite(ledPins[i], LOW);  // Başlangıçta tüm LED'leri söndürdük
    }
}

void loop() {
    for (int i = 0; i < 3; i++) {
        int buttonState = digitalRead(buttonPins[i]);

        // Butona basıldığında
        if (buttonState == LOW && lastButtonState[i] == HIGH && !buttonPressed[i]) {
            delay(50);  // Debounce zaman aralığı
            if (digitalRead(buttonPins[i]) == LOW) {
                changePreset(i);
                buttonPressed[i] = true;
            }
        }

        // Buton bırakıldığında
        if (buttonState == HIGH && lastButtonState[i] == LOW) {
            buttonPressed[i] = false;
        }

        lastButtonState[i] = buttonState;
    }
}

// MIDI Preset Değiştirme
void changePreset(int newPreset) {
    if (activePreset != newPreset) {
        if (activePreset != -1) {
            digitalWrite(ledPins[activePreset], LOW);  // Mevcut aktif LED'i söndür
        }
        sendMIDIProgramChange(presetNumbers[newPreset]);
        digitalWrite(ledPins[newPreset], HIGH);  // Yeni aktif LED'i yak
        activePreset = newPreset;
    }
}

// MIDI Program Change Mesajı Gönderme
void sendMIDIProgramChange(byte program) {
    midiEventPacket_t midiMessage = {0x0C, 0xC0, program, 0};
    MidiUSB.sendMIDI(midiMessage);
    MidiUSB.flush();
}

Why don't you ask chatGPT as long as it takes and as often as it takes
until chatGPT presents a code that works as you expect?

1 Like

I tried many times. (But if you are making fun of me for using chat gpt and editing code; I am a mechanic, not a programmer. I am doing it as a hobby)

The reason why human users don't like chatGPT is the fact that chatGPT will heavily modify again and again and again how the code looks like. And no user here wants to re-analyse and re-analyse and re-analyse code again and again and again.

So stay 100% with chatGPT
or
100% with humans that will assist you in writing code.

This is a forum. From professional to novice. Not everyone is a nerd like you. Your problem is not chatgpt or people. The source of the problem is your style. I read your profile and what you wrote. It's sad that you try to hide your inferiority in this way.

Not written by me. Written by a moderator.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.