MCPcopy Create free account
hub / github.com/Arduino-IRremote/Arduino-IRremote / customDelayMicroseconds

Method customDelayMicroseconds

src/IRSend.hpp:1466–1490  ·  view source on GitHub ↗

* Custom delay function that circumvents Arduino's delayMicroseconds 16 bit limit * and is (mostly) not extended by the duration of interrupt codes like the millis() interrupt */

Source from the content-addressed store, hash-verified

1464 * and is (mostly) not extended by the duration of interrupt codes like the millis() interrupt
1465 */
1466void IRsend::customDelayMicroseconds(unsigned long aMicroseconds) {
1467#if defined(ESP32) || defined(ESP8266)
1468 // from https://github.com/crankyoldgit/IRremoteESP8266/blob/00b27cc7ea2e7ac1e48e91740723c805a38728e0/src/IRsend.cpp#L123
1469 // Invoke a delay(), where possible, to avoid triggering the WDT.
1470 // see https://github.com/Arduino-IRremote/Arduino-IRremote/issues/1114 for the reason of checking for > 16383)
1471 // delayMicroseconds() is only accurate to 16383 us. Ref: https://www.arduino.cc/en/Reference/delayMicroseconds
1472 if (aMicroseconds > 16383) {
1473 delay(aMicroseconds / 1000UL); // Delay for as many whole milliseconds as we can.
1474 // Delay the remaining sub-millisecond.
1475 delayMicroseconds(static_cast<uint16_t>(aMicroseconds % 1000UL));
1476 } else {
1477 delayMicroseconds(aMicroseconds);
1478 }
1479#else
1480
1481# if defined(__AVR__)
1482 unsigned long start = micros() - (64 / clockCyclesPerMicrosecond()); // - (64 / clockCyclesPerMicrosecond()) for reduced resolution and additional overhead
1483# else
1484 unsigned long start = micros();
1485# endif
1486// overflow invariant comparison :-)
1487 while (micros() - start < aMicroseconds) {
1488 }
1489#endif
1490}
1491
1492/**
1493 * Enables IR output. The kHz value controls the modulation frequency in kilohertz.

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected