/*
Forum:
Wokwi: https://wokwi.com/projects/393596177953871873
Overloads the yield function which is called during delay()
It can be used to do something during delay but influences the timing of delay.
Therefore it should not be used for time consuming functions if the delay timing is
critical.
ec2021
The empty yield function is declared in ... /cores/arduino/hooks.c
*/
const byte ledPin = 7;
boolean doBlink = false;
void setup() {
Serial.begin(115200);
pinMode(ledPin, OUTPUT);
Delay(5000);
Serial.println("Do not Blink while Delay");
delay(5000);
Delay(6000);
Serial.println("Do not Blink while Delay");
delay(5000);
Delay(6000);
Serial.println("Stop");
}
void loop() {
}
void yield() {
static byte state = HIGH;
static unsigned long lastChange = 0;
if (!doBlink) {
return;
}
if (millis() - lastChange > 200) {
lastChange = millis();
digitalWrite(ledPin, state);
state = !state;
}
}
void Delay(unsigned long dly) {
Serial.print("Blink while Delay\t");
Serial.print(dly);
Serial.print("\t");
doBlink = true;
unsigned long start = millis();
delay(dly);
unsigned long stop = millis();
doBlink = false;
Serial.print(start);
Serial.print("\t");
Serial.println(stop);
digitalWrite(ledPin, LOW);
}