![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
For triple beacon
Fork of Programmable_IR_Beacon by
Diff: main.cpp
- Revision:
- 1:7093cc21a293
- Parent:
- 0:d88fd55a27a6
diff -r d88fd55a27a6 -r 7093cc21a293 main.cpp --- a/main.cpp Wed Mar 19 15:09:11 2014 +0000 +++ b/main.cpp Mon Aug 03 11:37:48 2015 +0000 @@ -1,34 +1,42 @@ /* University of York Robot Lab * - * Programmable IR Beacon with Display Example Code + * MSc ARE 2015 * - * This file is intended for use exclusively with the high-power IR Beacon with display + * Programmable Triple IR Beacon with Display + * + * This file is intended for use exclusively with the triple IR Beacon with display and RF transceiver * * * * (C) Dr James Hilder, Dept. Electronics & Computer Science, University of York + * * - * March 2014 + * July 2015 * */ #include "mbed.h" #include "display.h" //Display driver for the Midas 16x2 I2C Display -DigitalIn button1(p23); //"SET" Push-button -DigitalIn button2(p24); //"SELECT" Push-button -PwmOut out_narrow(p21); //PWM Output for the narrow (high intensity) LED driver -PwmOut out_wide(p22); //PWM Output for the wide-angle LED driver +DigitalIn button1(p24); //"SET" Push-button +DigitalIn button2(p25); //"SELECT" Push-button +PwmOut out_1(p21); //PWM Output for beacon 1 +PwmOut out_2(p22); //PWM Output for beacon 2 +PwmOut out_3(p23); //PWM Output for beacon 3 +DigitalOut led_1(LED1); +DigitalOut led_2(LED2); +DigitalOut led_3(LED3); Display display; + Timer system_timer; //System timer is used for timer the on-off periods for the LEDs Timer button_timer; //Button timer is used for debouncing the push buttons and pausing for entering 'SET' mode char adjust = 0; char mode = 0; -char power = 1; -char duty = 2; -char frequency = 2; +char power = 0; +char duty = 3; +char frequency = 1; int on_period; int off_period; @@ -62,11 +70,12 @@ { total_period = get_period(); switch(duty){ - case 0: on_period=total_period/10;break; - case 1: on_period=total_period/4;break; - case 2: on_period=total_period/2;break; - case 3: on_period=(total_period*3)/4;break; - case 4: on_period=total_period-(total_period/10);break; + case 0: on_period=total_period/20;break; + case 1: on_period=total_period/10;break; + case 2: on_period=total_period/4;break; + case 3: on_period=total_period/2;break; + case 4: on_period=(total_period*3)/4;break; + case 5: on_period=total_period-(total_period/10);break; } off_period = total_period - on_period; phase = 0; @@ -93,25 +102,29 @@ { switch(mode) { case 1: - return "WIDE "; + return "OUT 1"; case 2: - return "NARROW"; + return "OUT 2"; + case 3: + return "OUT 3"; } - return "BOTH "; + return "ALL "; } char * duty_string() { switch(duty) { case 0: - return " 10%"; + return " 5%"; case 1: - return " 25%"; + return " 10%"; case 2: - return " 50%"; + return " 25%"; case 3: + return " 50%"; + case 4: return " 75%"; - case 4: + case 5: return " 90%"; } return"???"; @@ -181,8 +194,12 @@ void change_settings() { //Switch off LEDs whilst in configuration mode - out_wide.pulsewidth_us(0); - out_narrow.pulsewidth_us(0); + out_1.pulsewidth_us(0); + out_2.pulsewidth_us(0); + out_3.pulsewidth_us(0); + led_1=0; + led_2=0; + led_3=0; display.clear_display(); display.set_position(0,0); display.write_string("CONFIGURATION",13); @@ -249,10 +266,10 @@ if(power == 4) power=0; break; case 2: duty++; - if(duty == 5) duty=0; + if(duty == 6) duty=0; break; case 3: mode++; - if(mode == 3) mode = 0; + if(mode == 4) mode = 0; break; case 4: active=0; break; } @@ -272,11 +289,12 @@ system_timer.start(); button_timer.start(); update_cycles(); - out_narrow.period_us(1000); - out_wide.period_us(1000); - out_narrow.pulsewidth_us(0); - out_wide.pulsewidth_us(0); - + out_1.period_us(1000); + out_2.period_us(1000); + out_3.period_us(1000); + out_1.pulsewidth_us(0); + out_2.pulsewidth_us(0); + out_3.pulsewidth_us(0); while(1) { if(phase==0){ @@ -286,20 +304,30 @@ if(power==1) pw=500; if(power==2) pw=750; if(power==3) pw=1000; - if(mode<2){ - out_wide.pulsewidth_us(pw); + if(mode==0 || mode==1){ + out_1.pulsewidth_us(pw); + led_1=1; } - if(mode!=1){ - out_narrow.pulsewidth_us(pw); - } + if(mode==0 || mode==2){ + out_2.pulsewidth_us(pw); + led_2=1; + } + if(mode==0 || mode==3){ + out_3.pulsewidth_us(pw); + led_3=1; + } phase = 1; } }else{ if(system_timer.read_us() > on_period){ system_timer.reset(); phase = 0; - out_wide.pulsewidth_us(0); - out_narrow.pulsewidth_us(0); + out_1.pulsewidth_us(0); + out_2.pulsewidth_us(0); + out_3.pulsewidth_us(0); + led_1=0; + led_2=0; + led_3=0; } }