mirror of
https://github.com/Theaninova/Arduino-IRremote.git
synced 2025-12-13 01:46:21 +00:00
Fixed delay method by replacing delayMicroseconds call with a loop if
it is too long.
This commit is contained in:
@@ -253,6 +253,7 @@ class IRsend
|
|||||||
public:
|
public:
|
||||||
IRsend () { }
|
IRsend () { }
|
||||||
|
|
||||||
|
void custom_delay_ms (unsigned int time);
|
||||||
void enableIROut (int khz) ;
|
void enableIROut (int khz) ;
|
||||||
void mark (int usec) ;
|
void mark (int usec) ;
|
||||||
void space (int usec) ;
|
void space (int usec) ;
|
||||||
|
|||||||
22
irSend.cpp
22
irSend.cpp
@@ -22,7 +22,7 @@ void IRsend::sendRaw (unsigned int buf[], unsigned char len, unsigned char hz
|
|||||||
void IRsend::mark (int time)
|
void IRsend::mark (int time)
|
||||||
{
|
{
|
||||||
TIMER_ENABLE_PWM; // Enable pin 3 PWM output
|
TIMER_ENABLE_PWM; // Enable pin 3 PWM output
|
||||||
if (time > 0) delayMicroseconds(time);
|
if (time > 0) custom_delay_ms(time);
|
||||||
}
|
}
|
||||||
|
|
||||||
//+=============================================================================
|
//+=============================================================================
|
||||||
@@ -33,9 +33,13 @@ void IRsend::mark (int time)
|
|||||||
void IRsend::space (int time)
|
void IRsend::space (int time)
|
||||||
{
|
{
|
||||||
TIMER_DISABLE_PWM; // Disable pin 3 PWM output
|
TIMER_DISABLE_PWM; // Disable pin 3 PWM output
|
||||||
if (time > 0) delayMicroseconds(time);
|
if (time > 0) IRsend::custom_delay_ms(time);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//+=============================================================================
|
//+=============================================================================
|
||||||
// Enables IR output. The khz value controls the modulation frequency in kilohertz.
|
// Enables IR output. The khz value controls the modulation frequency in kilohertz.
|
||||||
// The IR output will be on pin 3 (OC2B).
|
// The IR output will be on pin 3 (OC2B).
|
||||||
@@ -64,3 +68,17 @@ void IRsend::enableIROut (int khz)
|
|||||||
TIMER_CONFIG_KHZ(khz);
|
TIMER_CONFIG_KHZ(khz);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//+=============================================================================
|
||||||
|
// Custom delay function that circumvents Arduino's delayMicroseconds limit
|
||||||
|
|
||||||
|
void IRsend::custom_delay_ms(unsigned int time) {
|
||||||
|
if (time)
|
||||||
|
{
|
||||||
|
if (time > 16000)
|
||||||
|
{
|
||||||
|
delayMicroseconds(time % 1000);
|
||||||
|
delay(time / 1000);
|
||||||
|
}
|
||||||
|
else delayMicroseconds(time);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user