#include <MTobjects.h> // https://github.com/OlivierPcheux/MTobjects
const byte buttonPin = 9;
const byte ledPins[] = {2, 3, 4, 5};
const byte ledCnt = sizeof ledPins / sizeof * ledPins;
const byte pot1Pin = A0;
const byte pot2Pin = A1;
volatile bool blinkMode = true; // modified through button ISR
void onPress() {blinkMode = !blinkMode;}
MTbutton Bouton(buttonPin, onPress, nullptr); // no need for an onRelease callback
void setup() {
for (byte aPin : ledPins)pinMode(aPin, OUTPUT);
pinMode(buttonPin, INPUT_PULLUP);
}
void loop() {
int pot1 = analogRead(pot1Pin);
int pot2 = analogRead(pot2Pin);
if (blinkMode) { // atomic read for a byte size flag
for (byte aPin : ledPins) digitalWrite(aPin, HIGH);
delay(pot1);
for (byte aPin : ledPins) digitalWrite(aPin, LOW);
delay(pot2);
} else {
for (byte i = 0; i < ledCnt; i++) {
digitalWrite(ledPins[i], HIGH);
delay(pot1 + pot2);
digitalWrite(ledPins[i], LOW);
}
}
}