/*
Forum: https://forum.arduino.cc/t/problem-sending-program-change-through-arduino-pro-micro/1405537
Wokwi: https://wokwi.com/projects/4414278985324093457
ec2021
2025/09/07
This version calls changeLed() with every loop while the
digitalRead state is LOW.
*/
constexpr byte buttonPin {2}; // pushbutton pin
constexpr byte ledPin {10}; // led pin
void setup() {
Serial.begin(115200);
pinMode(buttonPin, INPUT_PULLUP); // Configure button as Input
pinMode(ledPin, OUTPUT);
}
void loop() {
if (digitalRead(buttonPin) == LOW) {
changeLed();
}
}
void changeLed() {
static byte ledState = HIGH;
static unsigned long counter = 0;
counter++;
digitalWrite(ledPin, ledState);
Serial.print((ledState) ? "On\t" : "Off\t");
Serial.println(counter);
ledState = !ledState;
}