mirror of
https://github.com/Theaninova/Arduino-IRremote.git
synced 2025-12-12 17:36:15 +00:00
Fixed delay method by replacing delayMicroseconds call with a loop if
it is too long.
This commit is contained in:
@@ -253,10 +253,11 @@ class IRsend
|
||||
public:
|
||||
IRsend () { }
|
||||
|
||||
void enableIROut (int khz) ;
|
||||
void mark (int usec) ;
|
||||
void space (int usec) ;
|
||||
void sendRaw (unsigned int buf[], unsigned char len, unsigned char hz) ;
|
||||
void custom_delay_ms (unsigned int time);
|
||||
void enableIROut (int khz) ;
|
||||
void mark (int usec) ;
|
||||
void space (int usec) ;
|
||||
void sendRaw (unsigned int buf[], unsigned char len, unsigned char hz) ;
|
||||
|
||||
//......................................................................
|
||||
# if SEND_RC5
|
||||
|
||||
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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user