From 1b475c3656ae87f9f9d6cc9420b6c80f53eb00ef Mon Sep 17 00:00:00 2001 From: Bernhard Tittelbach Date: Thu, 12 Aug 2010 06:36:57 +0000 Subject: [PATCH] try to fix irsend blueled timer/pwm mess --- rf433ctl/IRremote/IRremote.cpp | 2 +- rf433ctl/rf433ctl.pde | 36 +++++++++++++++++++++++++----------- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/rf433ctl/IRremote/IRremote.cpp b/rf433ctl/IRremote/IRremote.cpp index 00ccebf..b632723 100644 --- a/rf433ctl/IRremote/IRremote.cpp +++ b/rf433ctl/IRremote/IRremote.cpp @@ -198,7 +198,7 @@ void IRsend::enableIROut(int khz) { TIMSK2 &= ~_BV(TOIE2); //Timer2 Overflow Interrupt pinMode(3, OUTPUT); - digitalWrite(3, HIGH); // When not sending PWM, we want it low + digitalWrite(3, HIGH); // When not sending PWM, we want it low (invertiert angeschlossen) // COM2A = 00: disconnect OC2A // COM2B = 00: disconnect OC2B; to send signal set to 10: OC2B non-inverted diff --git a/rf433ctl/rf433ctl.pde b/rf433ctl/rf433ctl.pde index 05ff60a..68d9f08 100644 --- a/rf433ctl/rf433ctl.pde +++ b/rf433ctl/rf433ctl.pde @@ -80,17 +80,6 @@ const char YAMAHA_EFFECT5 =0x91; //Effect Toggle 70mm Sci-Fi / 70mm Spectacle const char YAMAHA_EFFECT6 =0x51; //Effect Toggle 70mm General / 70mm Adventure const char YAMAHA_P5 =0xFB; //P5 PRT (1 Main Bypass)? (1587674115) - -void send_yamaha_ir_signal(char codebyte) -{ - unsigned long int code = codebyte & 0xFF; - code <<= 8; - code |= (0xff ^ codebyte) & 0xFF; - code |= YAMAHA_CODE_BASE; - irsend.sendNEC(code,YAMAHA_CODE_BITS); - Serial.println("Ok"); -} - //********************************************************************// typedef struct { @@ -393,6 +382,31 @@ void flash_led(unsigned int times, unsigned int brightness_divisor, unsigned int //********************************************************************// +void send_yamaha_ir_signal(char codebyte) +{ + unsigned long int code = codebyte & 0xFF; + code <<= 8; + code |= (0xff ^ codebyte) & 0xFF; + code |= YAMAHA_CODE_BASE; + + //irsend changes PWM Timer Frequency among other things + //.. doesn't go well with PWM output using the same timer + //.. thus we just set output to 255 so whatever frequency is used, led is off for the duration + unsigned int flash_prev_selected = flash_led_selected_; //save prev. selected leds + flash_led_selected_ &= !(1 << BLUELED_PWM_PIN); //prevent calculate_led_level() from setting blueled + analogWrite(BLUELED_PWM_PIN,255); // switch led off + + irsend.sendNEC(code,YAMAHA_CODE_BITS); + + analogWrite(BLUELED_PWM_PIN,255); // switch off led again to be sure + flash_led_selected_ = flash_prev_selected; //restore led settings for calculate_led_level() + //is actually not necessary, since we are not multitasking/using interrupts, but just to be sure in case this might change + + Serial.println("Ok"); +} + +//********************************************************************// + void setup() { pinMode(RF_DATA_OUT_PIN, OUTPUT); -- 1.7.10.4