Infrared remote library for Arduino: send and receive infrared signals with multiple protocols Port from Arduino-IRremote https://github.com/z3t0/Arduino-IRremote

Dependents:   mbed-os-example-FinalReal_copy

Revision:
3:17440cf7ab90
Parent:
0:70c8e56bac45
Child:
6:ee990cddff48
--- a/irSend.cpp	Sat Jan 23 15:36:14 2016 +0900
+++ b/irSend.cpp	Sat Jan 23 15:09:34 2016 +0000
@@ -21,7 +21,7 @@
 //
 void  IRsend::mark (unsigned int time)
 {
-	TIMER_ENABLE_PWM; // Enable pin 3 PWM output
+	_pwm.write(0.5); // Enable PWM output
 	if (time > 0) custom_delay_usec(time);
 }
 
@@ -32,14 +32,10 @@
 //
 void  IRsend::space (unsigned int time)
 {
-	TIMER_DISABLE_PWM; // Disable pin 3 PWM output
+	_pwm.write(0.0); // Disable PWM output
 	if (time > 0) IRsend::custom_delay_usec(time);
 }
 
-
-
-
-
 //+=============================================================================
 // Enables IR output.  The khz value controls the modulation frequency in kilohertz.
 // The IR output will be on pin 3 (OC2B).
@@ -54,18 +50,8 @@
 //
 void  IRsend::enableIROut (int khz)
 {
-	// Disable the Timer2 Interrupt (which is used for receiving IR)
-	TIMER_DISABLE_INTR; //Timer2 Overflow Interrupt
-
-	pinMode(TIMER_PWM_PIN, OUTPUT);
-	digitalWrite(TIMER_PWM_PIN, LOW); // When not sending PWM, we want it low
-
-	// COM2A = 00: disconnect OC2A
-	// COM2B = 00: disconnect OC2B; to send signal set to 10: OC2B non-inverted
-	// WGM2 = 101: phase-correct PWM with OCRA as top
-	// CS2  = 000: no prescaling
-	// The top value for the timer.  The modulation frequency will be SYSCLOCK / 2 / OCR2A.
-	TIMER_CONFIG_KHZ(khz);
+	_pwm.write(0.0);
+	_pwm.period_us(1 / khz * 1000);
 }
 
 //+=============================================================================
@@ -73,15 +59,14 @@
 
 void IRsend::custom_delay_usec(unsigned long uSecs) {
   if (uSecs > 4) {
-    unsigned long start = micros();
+    unsigned long start = us_ticker_read();
     unsigned long endMicros = start + uSecs - 4;
     if (endMicros < start) { // Check if overflow
-      while ( micros() > start ) {} // wait until overflow
+      while ( us_ticker_read() > start ) {} // wait until overflow
     }
-    while ( micros() < endMicros ) {} // normal wait
+    while ( us_ticker_read() < endMicros ) {} // normal wait
   } 
   //else {
   //  __asm__("nop\n\t"); // must have or compiler optimizes out
   //}
 }
-