// BWD 60 the OOP way
constexpr uint8_t ledPinA {13}; // the GPIO used for a LED
class Blink {
protected:
const uint8_t ledPin; // the GPIO for the LED
uint16_t onInterval = 500; // the ON time
uint16_t offInterval = 500; // the OFF time
uint32_t previousMillis = 0; // stores current "time" for internal time management
bool ledState = false; // current state of LED
public:
Blink (uint8_t ledPin, uint32_t onInterval = 1000, uint32_t offInterval = 1000) :
ledPin(ledPin), onInterval(onInterval), offInterval(offInterval) {}
void begin() {
pinMode(ledPin, OUTPUT);
}
void update() {
uint32_t currentMillis = millis();
if (ledState) {
if (currentMillis - previousMillis > onInterval) {
previousMillis = currentMillis;
digitalWrite(ledPin, LOW);
ledState = false;
}
}
else {
if (currentMillis - previousMillis > offInterval) {
previousMillis = currentMillis;
digitalWrite(ledPin, HIGH);
ledState = true;
}
}
}
};
Blink blink {ledPinA, 200, 500}; // create a blink LED object
void setup() {
Serial.begin (115200); // Initialise the serial monitor
blink.begin();
}
void loop() {
blink.update(); // "run" the blink effect.
}