byte ledPin = LED_BUILTIN;
int ledON = 200, ledOFF = 5000; // LED state intervals
unsigned long timer;
unsigned long timerUS, timeoutUS = 250000; // configure variable type and assign value
void setup() {
pinMode (ledPin, OUTPUT);
}
void loop() {
// asymetricBlink();
microsBlink();
}
void asymetricBlink() {
if (millis() - timer >= (digitalRead(ledPin) == 0 ? ledOFF : ledON)) { // read pin state, set interval
timer = millis(); // reset timer for next interval
digitalWrite(ledPin, !digitalRead(ledPin)); // change pin state to opposite current pin state
}
}
void microsBlink() {
if (micros() - timerUS > timeoutUS) {
// micros() - this function reads the system counter running since power was applied
// timerUS - variable of type "unsigned long" with maximum value of 4,294,967,295 (0xffff ffff)
// timeoutUS - variable of type "unsigned long" with the blink "duration" value
timerUS = micros(); // assign a new value from micros() to "timerUS" (set a new "zero" time)
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN)); // change the built-in LED
// 1. read the state of LED_BUILTIN pin: digitalRead(LED_BUILTIN);
// 2. negate the state of the pin reading: "!" preceeding digitalRead();
// 3. set LED_BUILTIN to that state: digitalWrite();
}
}