- if (flash_led_time_ == 0 || new_flash_led_brightness > flash_led_brightness_)
- flash_led_brightness_=new_flash_led_brightness;
- if (flash_led_time_ == 0 || new_flash_led_delay < flash_led_delay_)
- flash_led_delay_=new_flash_led_delay;
- flash_led_time_ += 314*times;
+ if (flash_led_time_[id] == 0 || new_flash_led_brightness > flash_led_brightness_[id])
+ flash_led_brightness_[id]=new_flash_led_brightness;
+ if (flash_led_time_[id] == 0 || new_flash_led_delay < flash_led_delay_[id])
+ flash_led_delay_[id]=new_flash_led_delay;
+ flash_led_time_[id] += 314*times;
+ flash_led_initial_delay_[id] = flash_led_delay_[id]*314*phase_divisor/8;
+}
+
+//********************************************************************//
+
+int save_tcnt2=0;
+int save_tccr2a=0;
+int save_tccr2b=0;
+void reset_timer2()
+{
+ TCNT2 = save_tcnt2;
+ TCCR2A = save_tccr2a; // normal mode
+ TCCR2B = save_tccr2b;
+ //TCNT2 = 256 - (50*(16000000/8/1000000)) + 5;
+ //TCCR2A = 0; // normal mode
+ //TCCR2B = 0;
+}
+
+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
+ //analogWrite(BLUELED_PWM_PIN,255); // switch led off
+
+ irsend.sendNEC(code,YAMAHA_CODE_BITS);
+
+ reset_timer2();
+ analogWrite(BLUELED_PWM_PIN,255); // switch off led again to be sure
+ //is actually not necessary, since we are not multitasking/using interrupts, but just to be sure in case this might change
+
+ Serial.println("Ok");