From: Bernhard Tittelbach Date: Thu, 12 Aug 2010 05:16:28 +0000 (+0000) Subject: led selctor; ^ flashes led X-Git-Url: https://git.realraum.at/?a=commitdiff_plain;h=c3553202389f044616f5625091d5bf6203d8884d;p=svn42.git led selctor; ^ flashes led --- diff --git a/rf433ctl/rf433ctl.pde b/rf433ctl/rf433ctl.pde index ca214f7..543bb1f 100644 --- a/rf433ctl/rf433ctl.pde +++ b/rf433ctl/rf433ctl.pde @@ -11,9 +11,8 @@ #define IR_MOVEMENT_PIN 9 #define ONE_WIRE_PIN 8 #define PANIC_BUTTON_PIN 7 -#define BLUELED_PWM_PIN 5 #define PANICLED_PWM_PIN 6 -#define BLUELED2_PWM_PIN 11 +#define BLUELED_PWM_PIN 11 #define PHOTO_ANALOGPIN 0 //movement is reported if during IR_SAMPLE_DURATION at least IR_TRESHOLD ir signals are detectd #define IR_SAMPLE_DURATION 12000 @@ -343,29 +342,46 @@ bool wait_millis(unsigned long ms) unsigned int flash_led_time_=0; unsigned int flash_led_brightness_=255; unsigned int flash_led_delay_=8; -void calculate_led_level(unsigned int pwm_pin) +unsigned int flash_led_selected_=0; +void calculate_led_level() { - if (flash_led_time_ == 0) + if (flash_led_time_ == 0 || flash_led_selected_ == 0) return; if (wait_millis(flash_led_delay_)) return; flash_led_time_--; int c = abs(sin(float(flash_led_time_) / 100.0)) * flash_led_brightness_; //int d = abs(sin(float(flash_led_time_) / 100.0)) * flash_led_brightness_; - analogWrite(BLUELED2_PWM_PIN, 255-c); - if (flash_led_brightness_ == 255) + if (flash_led_selected_ && (1 << BLUELED_PWM_PIN)) + analogWrite(BLUELED_PWM_PIN, 255-c); + else + analogWrite(BLUELED_PWM_PIN,255); //off + if (flash_led_selected_ && (1 << PANICLED_PWM_PIN)) { if (flash_led_time_) analogWrite(PANICLED_PWM_PIN, c); else analogWrite(PANICLED_PWM_PIN, 255-c); } + else + analogWrite(PANICLED_PWM_PIN,255); //off } -void flash_led(unsigned int times, unsigned int brightness_divisor, unsigned int delay_divisor) +void flash_led(unsigned int times, unsigned int brightness_divisor, unsigned int delay_divisor, unsigned int led_selector) { - unsigned int new_flash_led_brightness = 255 / brightness_divisor; - unsigned int new_flash_led_delay = 8 / delay_divisor; + unsigned int new_flash_led_brightness = 255; + unsigned int new_flash_led_delay = 8; + flash_led_selected_=led_selector; + if (times == 0 || led_selector == 0) + { + analogWrite(PANICLED_PWM_PIN,255); //off + analogWrite(BLUELED_PWM_PIN,255); //off + return; + } + if (brightness_divisor > 1) //guard against div by zero + new_flash_led_brightness /= brightness_divisor; + if (delay_divisor > 1) //guard against div by zero + new_flash_led_delay /= delay_divisor; 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_) @@ -383,9 +399,8 @@ void setup() digitalWrite(IR_MOVEMENT_PIN, LOW); // turn off pulldown resistors pinMode(PANIC_BUTTON_PIN, INPUT); // set pin to input digitalWrite(PANIC_BUTTON_PIN, LOW); // turn on pulldown resistors - analogWrite(BLUELED_PWM_PIN,255); analogWrite(PANICLED_PWM_PIN,255); - analogWrite(BLUELED2_PWM_PIN,255); //pwm sink(-) instead of pwm + (better for mosfets) + analogWrite(BLUELED_PWM_PIN,255); //pwm sink(-) instead of pwm + (better for mosfets) pinMode(IRREMOTE_SEND_PIN, OUTPUT); digitalWrite(IRREMOTE_SEND_PIN, HIGH); @@ -427,7 +442,7 @@ void loop() { if (ir_count >= IR_TRESHOLD) { - flash_led(1,8,1); + flash_led(1, 8, 1, (1<