Hello
Here comes a very simple class-less BlinkWithOutDelay example that shows the usage of a struct and user definded datatypes.
struct BWOD { // make a data block containing
byte ledPin; // set LED pin
unsigned long duration; // set time to blink;
unsigned long stamp; // time stamp for timer
};
BWOD bwod {2, 1000, 0}; // initialize data block
void setup() {
pinMode (LED_BUILTIN, OUTPUT);
pinMode(bwod.ledPin, OUTPUT);
}
void loop () {
unsigned long currentTime = millis();
digitalWrite(LED_BUILTIN, (currentTime / 500) % 2);
if (currentTime - bwod.stamp >= bwod.duration) {
bwod.stamp = currentTime;
digitalWrite(bwod.ledPin, !digitalRead(bwod.ledPin));
}
}
Have a nice day and enjoy coding in C++.