Fixed delay method by replacing delayMicroseconds call with a loop if

it is too long.
This commit is contained in:
Rafi Khan
2015-08-13 16:54:59 -06:00
parent 25424cb5d8
commit 5ee3905157
2 changed files with 89 additions and 70 deletions

View File

@@ -253,6 +253,7 @@ class IRsend
public:
IRsend () { }
void custom_delay_ms (unsigned int time);
void enableIROut (int khz) ;
void mark (int usec) ;
void space (int usec) ;

View File

@@ -22,7 +22,7 @@ void IRsend::sendRaw (unsigned int buf[], unsigned char len, unsigned char hz
void IRsend::mark (int time)
{
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)
{
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.
// The IR output will be on pin 3 (OC2B).
@@ -64,3 +68,17 @@ void IRsend::enableIROut (int 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);
}
}