James Hilder
/
MSc-2015-ProgrammableBeacon
For triple beacon
Fork of Programmable_IR_Beacon by
main.cpp@1:7093cc21a293, 2015-08-03 (annotated)
- Committer:
- jah128
- Date:
- Mon Aug 03 11:37:48 2015 +0000
- Revision:
- 1:7093cc21a293
- Parent:
- 0:d88fd55a27a6
Jah
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jah128 | 0:d88fd55a27a6 | 1 | /* University of York Robot Lab |
jah128 | 0:d88fd55a27a6 | 2 | * |
jah128 | 1:7093cc21a293 | 3 | * MSc ARE 2015 |
jah128 | 0:d88fd55a27a6 | 4 | * |
jah128 | 1:7093cc21a293 | 5 | * Programmable Triple IR Beacon with Display |
jah128 | 1:7093cc21a293 | 6 | * |
jah128 | 1:7093cc21a293 | 7 | * This file is intended for use exclusively with the triple IR Beacon with display and RF transceiver |
jah128 | 0:d88fd55a27a6 | 8 | * |
jah128 | 0:d88fd55a27a6 | 9 | * |
jah128 | 0:d88fd55a27a6 | 10 | * |
jah128 | 0:d88fd55a27a6 | 11 | * (C) Dr James Hilder, Dept. Electronics & Computer Science, University of York |
jah128 | 1:7093cc21a293 | 12 | * |
jah128 | 0:d88fd55a27a6 | 13 | * |
jah128 | 1:7093cc21a293 | 14 | * July 2015 |
jah128 | 0:d88fd55a27a6 | 15 | * |
jah128 | 0:d88fd55a27a6 | 16 | */ |
jah128 | 0:d88fd55a27a6 | 17 | |
jah128 | 0:d88fd55a27a6 | 18 | #include "mbed.h" |
jah128 | 0:d88fd55a27a6 | 19 | #include "display.h" //Display driver for the Midas 16x2 I2C Display |
jah128 | 0:d88fd55a27a6 | 20 | |
jah128 | 1:7093cc21a293 | 21 | DigitalIn button1(p24); //"SET" Push-button |
jah128 | 1:7093cc21a293 | 22 | DigitalIn button2(p25); //"SELECT" Push-button |
jah128 | 1:7093cc21a293 | 23 | PwmOut out_1(p21); //PWM Output for beacon 1 |
jah128 | 1:7093cc21a293 | 24 | PwmOut out_2(p22); //PWM Output for beacon 2 |
jah128 | 1:7093cc21a293 | 25 | PwmOut out_3(p23); //PWM Output for beacon 3 |
jah128 | 1:7093cc21a293 | 26 | DigitalOut led_1(LED1); |
jah128 | 1:7093cc21a293 | 27 | DigitalOut led_2(LED2); |
jah128 | 1:7093cc21a293 | 28 | DigitalOut led_3(LED3); |
jah128 | 0:d88fd55a27a6 | 29 | |
jah128 | 0:d88fd55a27a6 | 30 | Display display; |
jah128 | 1:7093cc21a293 | 31 | |
jah128 | 0:d88fd55a27a6 | 32 | Timer system_timer; //System timer is used for timer the on-off periods for the LEDs |
jah128 | 0:d88fd55a27a6 | 33 | Timer button_timer; //Button timer is used for debouncing the push buttons and pausing for entering 'SET' mode |
jah128 | 0:d88fd55a27a6 | 34 | |
jah128 | 0:d88fd55a27a6 | 35 | char adjust = 0; |
jah128 | 0:d88fd55a27a6 | 36 | char mode = 0; |
jah128 | 1:7093cc21a293 | 37 | char power = 0; |
jah128 | 1:7093cc21a293 | 38 | char duty = 3; |
jah128 | 1:7093cc21a293 | 39 | char frequency = 1; |
jah128 | 0:d88fd55a27a6 | 40 | |
jah128 | 0:d88fd55a27a6 | 41 | int on_period; |
jah128 | 0:d88fd55a27a6 | 42 | int off_period; |
jah128 | 0:d88fd55a27a6 | 43 | int total_period; |
jah128 | 0:d88fd55a27a6 | 44 | char phase; |
jah128 | 0:d88fd55a27a6 | 45 | |
jah128 | 0:d88fd55a27a6 | 46 | int get_period() |
jah128 | 0:d88fd55a27a6 | 47 | { |
jah128 | 0:d88fd55a27a6 | 48 | switch(frequency) { |
jah128 | 0:d88fd55a27a6 | 49 | case 0: |
jah128 | 0:d88fd55a27a6 | 50 | return 1000000; |
jah128 | 0:d88fd55a27a6 | 51 | case 1: |
jah128 | 0:d88fd55a27a6 | 52 | return 500000; |
jah128 | 0:d88fd55a27a6 | 53 | case 2: |
jah128 | 0:d88fd55a27a6 | 54 | return 200000; |
jah128 | 0:d88fd55a27a6 | 55 | case 3: |
jah128 | 0:d88fd55a27a6 | 56 | return 100000; |
jah128 | 0:d88fd55a27a6 | 57 | case 4: |
jah128 | 0:d88fd55a27a6 | 58 | return 50000; |
jah128 | 0:d88fd55a27a6 | 59 | case 5: |
jah128 | 0:d88fd55a27a6 | 60 | return 33333; |
jah128 | 0:d88fd55a27a6 | 61 | case 6: |
jah128 | 0:d88fd55a27a6 | 62 | return 25000; |
jah128 | 0:d88fd55a27a6 | 63 | case 7: |
jah128 | 0:d88fd55a27a6 | 64 | return 20000; |
jah128 | 0:d88fd55a27a6 | 65 | } |
jah128 | 0:d88fd55a27a6 | 66 | return 0; |
jah128 | 0:d88fd55a27a6 | 67 | } |
jah128 | 0:d88fd55a27a6 | 68 | |
jah128 | 0:d88fd55a27a6 | 69 | void update_cycles() |
jah128 | 0:d88fd55a27a6 | 70 | { |
jah128 | 0:d88fd55a27a6 | 71 | total_period = get_period(); |
jah128 | 0:d88fd55a27a6 | 72 | switch(duty){ |
jah128 | 1:7093cc21a293 | 73 | case 0: on_period=total_period/20;break; |
jah128 | 1:7093cc21a293 | 74 | case 1: on_period=total_period/10;break; |
jah128 | 1:7093cc21a293 | 75 | case 2: on_period=total_period/4;break; |
jah128 | 1:7093cc21a293 | 76 | case 3: on_period=total_period/2;break; |
jah128 | 1:7093cc21a293 | 77 | case 4: on_period=(total_period*3)/4;break; |
jah128 | 1:7093cc21a293 | 78 | case 5: on_period=total_period-(total_period/10);break; |
jah128 | 0:d88fd55a27a6 | 79 | } |
jah128 | 0:d88fd55a27a6 | 80 | off_period = total_period - on_period; |
jah128 | 0:d88fd55a27a6 | 81 | phase = 0; |
jah128 | 0:d88fd55a27a6 | 82 | system_timer.reset(); |
jah128 | 0:d88fd55a27a6 | 83 | } |
jah128 | 0:d88fd55a27a6 | 84 | |
jah128 | 0:d88fd55a27a6 | 85 | void init() |
jah128 | 0:d88fd55a27a6 | 86 | { |
jah128 | 0:d88fd55a27a6 | 87 | display.init_display(); |
jah128 | 0:d88fd55a27a6 | 88 | display.set_position(0,2); |
jah128 | 0:d88fd55a27a6 | 89 | display.write_string("YORK ROBOTICS",13); |
jah128 | 0:d88fd55a27a6 | 90 | display.set_position(1,3); |
jah128 | 0:d88fd55a27a6 | 91 | display.write_string("LABORATORY",10); |
jah128 | 0:d88fd55a27a6 | 92 | wait(0.45); |
jah128 | 0:d88fd55a27a6 | 93 | display.clear_display(); |
jah128 | 0:d88fd55a27a6 | 94 | display.set_position(0,2); |
jah128 | 0:d88fd55a27a6 | 95 | display.write_string("Programmable",12); |
jah128 | 0:d88fd55a27a6 | 96 | display.set_position(1,3); |
jah128 | 0:d88fd55a27a6 | 97 | display.write_string("IR Beacon",9); |
jah128 | 0:d88fd55a27a6 | 98 | wait(0.45); |
jah128 | 0:d88fd55a27a6 | 99 | } |
jah128 | 0:d88fd55a27a6 | 100 | |
jah128 | 0:d88fd55a27a6 | 101 | char * mode_string() |
jah128 | 0:d88fd55a27a6 | 102 | { |
jah128 | 0:d88fd55a27a6 | 103 | switch(mode) { |
jah128 | 0:d88fd55a27a6 | 104 | case 1: |
jah128 | 1:7093cc21a293 | 105 | return "OUT 1"; |
jah128 | 0:d88fd55a27a6 | 106 | case 2: |
jah128 | 1:7093cc21a293 | 107 | return "OUT 2"; |
jah128 | 1:7093cc21a293 | 108 | case 3: |
jah128 | 1:7093cc21a293 | 109 | return "OUT 3"; |
jah128 | 0:d88fd55a27a6 | 110 | } |
jah128 | 1:7093cc21a293 | 111 | return "ALL "; |
jah128 | 0:d88fd55a27a6 | 112 | } |
jah128 | 0:d88fd55a27a6 | 113 | |
jah128 | 0:d88fd55a27a6 | 114 | char * duty_string() |
jah128 | 0:d88fd55a27a6 | 115 | { |
jah128 | 0:d88fd55a27a6 | 116 | switch(duty) { |
jah128 | 0:d88fd55a27a6 | 117 | case 0: |
jah128 | 1:7093cc21a293 | 118 | return " 5%"; |
jah128 | 0:d88fd55a27a6 | 119 | case 1: |
jah128 | 1:7093cc21a293 | 120 | return " 10%"; |
jah128 | 0:d88fd55a27a6 | 121 | case 2: |
jah128 | 1:7093cc21a293 | 122 | return " 25%"; |
jah128 | 0:d88fd55a27a6 | 123 | case 3: |
jah128 | 1:7093cc21a293 | 124 | return " 50%"; |
jah128 | 1:7093cc21a293 | 125 | case 4: |
jah128 | 0:d88fd55a27a6 | 126 | return " 75%"; |
jah128 | 1:7093cc21a293 | 127 | case 5: |
jah128 | 0:d88fd55a27a6 | 128 | return " 90%"; |
jah128 | 0:d88fd55a27a6 | 129 | } |
jah128 | 0:d88fd55a27a6 | 130 | return"???"; |
jah128 | 0:d88fd55a27a6 | 131 | } |
jah128 | 0:d88fd55a27a6 | 132 | |
jah128 | 0:d88fd55a27a6 | 133 | char * power_string() |
jah128 | 0:d88fd55a27a6 | 134 | { |
jah128 | 0:d88fd55a27a6 | 135 | switch(power) { |
jah128 | 0:d88fd55a27a6 | 136 | case 0: |
jah128 | 0:d88fd55a27a6 | 137 | return " 25%"; |
jah128 | 0:d88fd55a27a6 | 138 | case 1: |
jah128 | 0:d88fd55a27a6 | 139 | return " 50%"; |
jah128 | 0:d88fd55a27a6 | 140 | case 2: |
jah128 | 0:d88fd55a27a6 | 141 | return " 75%"; |
jah128 | 0:d88fd55a27a6 | 142 | case 3: |
jah128 | 0:d88fd55a27a6 | 143 | return "100%"; |
jah128 | 0:d88fd55a27a6 | 144 | } |
jah128 | 0:d88fd55a27a6 | 145 | return"????"; |
jah128 | 0:d88fd55a27a6 | 146 | } |
jah128 | 0:d88fd55a27a6 | 147 | |
jah128 | 0:d88fd55a27a6 | 148 | char * freq_string() |
jah128 | 0:d88fd55a27a6 | 149 | { |
jah128 | 0:d88fd55a27a6 | 150 | switch(frequency) { |
jah128 | 0:d88fd55a27a6 | 151 | case 0: |
jah128 | 0:d88fd55a27a6 | 152 | return " 1Hz"; |
jah128 | 0:d88fd55a27a6 | 153 | case 1: |
jah128 | 0:d88fd55a27a6 | 154 | return " 2Hz"; |
jah128 | 0:d88fd55a27a6 | 155 | case 2: |
jah128 | 0:d88fd55a27a6 | 156 | return " 5Hz"; |
jah128 | 0:d88fd55a27a6 | 157 | case 3: |
jah128 | 0:d88fd55a27a6 | 158 | return "10Hz"; |
jah128 | 0:d88fd55a27a6 | 159 | case 4: |
jah128 | 0:d88fd55a27a6 | 160 | return "20Hz"; |
jah128 | 0:d88fd55a27a6 | 161 | case 5: |
jah128 | 0:d88fd55a27a6 | 162 | return "30Hz"; |
jah128 | 0:d88fd55a27a6 | 163 | case 6: |
jah128 | 0:d88fd55a27a6 | 164 | return "40Hz"; |
jah128 | 0:d88fd55a27a6 | 165 | case 7: |
jah128 | 0:d88fd55a27a6 | 166 | return "50Hz"; |
jah128 | 0:d88fd55a27a6 | 167 | } |
jah128 | 0:d88fd55a27a6 | 168 | return "????"; |
jah128 | 0:d88fd55a27a6 | 169 | } |
jah128 | 0:d88fd55a27a6 | 170 | |
jah128 | 0:d88fd55a27a6 | 171 | // The normal mode display output: shows the frequency, power, duty-cycle and output mode (ie wide, narrow or both) |
jah128 | 0:d88fd55a27a6 | 172 | void display_status() |
jah128 | 0:d88fd55a27a6 | 173 | { |
jah128 | 0:d88fd55a27a6 | 174 | display.clear_display(); |
jah128 | 0:d88fd55a27a6 | 175 | display.set_position(0,0); |
jah128 | 0:d88fd55a27a6 | 176 | char line1[15] ; |
jah128 | 0:d88fd55a27a6 | 177 | strcpy(line1, "F:"); |
jah128 | 0:d88fd55a27a6 | 178 | strcat(line1, freq_string()); |
jah128 | 0:d88fd55a27a6 | 179 | strcat(line1, " P:"); |
jah128 | 0:d88fd55a27a6 | 180 | strcat(line1, power_string()); |
jah128 | 0:d88fd55a27a6 | 181 | display.write_string(line1,13); |
jah128 | 0:d88fd55a27a6 | 182 | char line2[17]; |
jah128 | 0:d88fd55a27a6 | 183 | strcpy(line2, "D:"); |
jah128 | 0:d88fd55a27a6 | 184 | strcat(line2, duty_string()); |
jah128 | 0:d88fd55a27a6 | 185 | strcat(line2, " M:"); |
jah128 | 0:d88fd55a27a6 | 186 | strcat(line2, mode_string()); |
jah128 | 0:d88fd55a27a6 | 187 | display.set_position(1,0); |
jah128 | 0:d88fd55a27a6 | 188 | display.write_string(line2,16); |
jah128 | 0:d88fd55a27a6 | 189 | } |
jah128 | 0:d88fd55a27a6 | 190 | |
jah128 | 0:d88fd55a27a6 | 191 | // The configuration mode; entered by holding the 'set' button for one second. In this mode the user can through the options |
jah128 | 0:d88fd55a27a6 | 192 | // by pressing 'set' and change a setting by pressing 'select'. The final screen in the loop allows the user to return to |
jah128 | 0:d88fd55a27a6 | 193 | // normal operation, this will also happen with no user input for 5 seconds. |
jah128 | 0:d88fd55a27a6 | 194 | void change_settings() |
jah128 | 0:d88fd55a27a6 | 195 | { |
jah128 | 0:d88fd55a27a6 | 196 | //Switch off LEDs whilst in configuration mode |
jah128 | 1:7093cc21a293 | 197 | out_1.pulsewidth_us(0); |
jah128 | 1:7093cc21a293 | 198 | out_2.pulsewidth_us(0); |
jah128 | 1:7093cc21a293 | 199 | out_3.pulsewidth_us(0); |
jah128 | 1:7093cc21a293 | 200 | led_1=0; |
jah128 | 1:7093cc21a293 | 201 | led_2=0; |
jah128 | 1:7093cc21a293 | 202 | led_3=0; |
jah128 | 0:d88fd55a27a6 | 203 | display.clear_display(); |
jah128 | 0:d88fd55a27a6 | 204 | display.set_position(0,0); |
jah128 | 0:d88fd55a27a6 | 205 | display.write_string("CONFIGURATION",13); |
jah128 | 0:d88fd55a27a6 | 206 | display.set_position(1,0); |
jah128 | 0:d88fd55a27a6 | 207 | display.write_string("MODE",4); |
jah128 | 0:d88fd55a27a6 | 208 | while(button1 == 1); |
jah128 | 0:d88fd55a27a6 | 209 | char screen = 0; |
jah128 | 0:d88fd55a27a6 | 210 | char active = 1; |
jah128 | 0:d88fd55a27a6 | 211 | Timer settings_timer; |
jah128 | 0:d88fd55a27a6 | 212 | settings_timer.start(); |
jah128 | 0:d88fd55a27a6 | 213 | while(active) { |
jah128 | 0:d88fd55a27a6 | 214 | display.clear_display(); |
jah128 | 0:d88fd55a27a6 | 215 | display.set_position(0,0); |
jah128 | 0:d88fd55a27a6 | 216 | char line2[17]; |
jah128 | 0:d88fd55a27a6 | 217 | switch(screen) { |
jah128 | 0:d88fd55a27a6 | 218 | case 0: |
jah128 | 0:d88fd55a27a6 | 219 | display.write_string("Set Frequency:",14); |
jah128 | 0:d88fd55a27a6 | 220 | display.set_position(1,0); |
jah128 | 0:d88fd55a27a6 | 221 | strcpy(line2,freq_string()); |
jah128 | 0:d88fd55a27a6 | 222 | display.write_string(line2,4); |
jah128 | 0:d88fd55a27a6 | 223 | break; |
jah128 | 0:d88fd55a27a6 | 224 | case 1: |
jah128 | 0:d88fd55a27a6 | 225 | display.write_string("Set Power: ",14); |
jah128 | 0:d88fd55a27a6 | 226 | display.set_position(1,0); |
jah128 | 0:d88fd55a27a6 | 227 | strcpy(line2,power_string()); |
jah128 | 0:d88fd55a27a6 | 228 | display.write_string(line2,4); |
jah128 | 0:d88fd55a27a6 | 229 | break; |
jah128 | 0:d88fd55a27a6 | 230 | case 2: |
jah128 | 0:d88fd55a27a6 | 231 | display.write_string("Set Duty Cycle:",15); |
jah128 | 0:d88fd55a27a6 | 232 | display.set_position(1,0); |
jah128 | 0:d88fd55a27a6 | 233 | strcpy(line2,duty_string()); |
jah128 | 0:d88fd55a27a6 | 234 | display.write_string(line2,4); |
jah128 | 0:d88fd55a27a6 | 235 | break; |
jah128 | 0:d88fd55a27a6 | 236 | case 3: |
jah128 | 0:d88fd55a27a6 | 237 | display.write_string("Set Mode: ",14); |
jah128 | 0:d88fd55a27a6 | 238 | display.set_position(1,0); |
jah128 | 0:d88fd55a27a6 | 239 | strcpy(line2,mode_string()); |
jah128 | 0:d88fd55a27a6 | 240 | display.write_string(line2,6); |
jah128 | 0:d88fd55a27a6 | 241 | break; |
jah128 | 0:d88fd55a27a6 | 242 | case 4: |
jah128 | 0:d88fd55a27a6 | 243 | display.write_string("End Setup",9); |
jah128 | 0:d88fd55a27a6 | 244 | break; |
jah128 | 0:d88fd55a27a6 | 245 | } |
jah128 | 0:d88fd55a27a6 | 246 | char button_pressed = 0; |
jah128 | 0:d88fd55a27a6 | 247 | |
jah128 | 0:d88fd55a27a6 | 248 | while(button_pressed < 2 && settings_timer.read_ms() < 5000){ |
jah128 | 0:d88fd55a27a6 | 249 | if(button1 == 1 || button2 == 1){ |
jah128 | 0:d88fd55a27a6 | 250 | if(button_pressed == 1){ |
jah128 | 0:d88fd55a27a6 | 251 | if(button_timer.read_ms() > 50) button_pressed = 2; |
jah128 | 0:d88fd55a27a6 | 252 | } else {button_pressed = 1; button_timer.reset();} |
jah128 | 0:d88fd55a27a6 | 253 | } else button_pressed = 0; |
jah128 | 0:d88fd55a27a6 | 254 | } |
jah128 | 0:d88fd55a27a6 | 255 | if(button1==1){ |
jah128 | 0:d88fd55a27a6 | 256 | screen++; |
jah128 | 0:d88fd55a27a6 | 257 | if(screen == 5)screen=0; |
jah128 | 0:d88fd55a27a6 | 258 | while(button1 == 1); |
jah128 | 0:d88fd55a27a6 | 259 | }else{ |
jah128 | 0:d88fd55a27a6 | 260 | if(button2==1){ |
jah128 | 0:d88fd55a27a6 | 261 | switch(screen){ |
jah128 | 0:d88fd55a27a6 | 262 | case 0: frequency ++; |
jah128 | 0:d88fd55a27a6 | 263 | if(frequency == 8) frequency = 0; |
jah128 | 0:d88fd55a27a6 | 264 | break; |
jah128 | 0:d88fd55a27a6 | 265 | case 1: power++; |
jah128 | 0:d88fd55a27a6 | 266 | if(power == 4) power=0; |
jah128 | 0:d88fd55a27a6 | 267 | break; |
jah128 | 0:d88fd55a27a6 | 268 | case 2: duty++; |
jah128 | 1:7093cc21a293 | 269 | if(duty == 6) duty=0; |
jah128 | 0:d88fd55a27a6 | 270 | break; |
jah128 | 0:d88fd55a27a6 | 271 | case 3: mode++; |
jah128 | 1:7093cc21a293 | 272 | if(mode == 4) mode = 0; |
jah128 | 0:d88fd55a27a6 | 273 | break; |
jah128 | 0:d88fd55a27a6 | 274 | case 4: active=0; break; |
jah128 | 0:d88fd55a27a6 | 275 | } |
jah128 | 0:d88fd55a27a6 | 276 | while(button2 == 1); |
jah128 | 0:d88fd55a27a6 | 277 | } |
jah128 | 0:d88fd55a27a6 | 278 | } |
jah128 | 0:d88fd55a27a6 | 279 | if(settings_timer > 5000) active=0; |
jah128 | 0:d88fd55a27a6 | 280 | settings_timer.reset(); |
jah128 | 0:d88fd55a27a6 | 281 | } |
jah128 | 0:d88fd55a27a6 | 282 | } |
jah128 | 0:d88fd55a27a6 | 283 | |
jah128 | 0:d88fd55a27a6 | 284 | int main() |
jah128 | 0:d88fd55a27a6 | 285 | { |
jah128 | 0:d88fd55a27a6 | 286 | init(); |
jah128 | 0:d88fd55a27a6 | 287 | display_status(); |
jah128 | 0:d88fd55a27a6 | 288 | char b_p = 0; |
jah128 | 0:d88fd55a27a6 | 289 | system_timer.start(); |
jah128 | 0:d88fd55a27a6 | 290 | button_timer.start(); |
jah128 | 0:d88fd55a27a6 | 291 | update_cycles(); |
jah128 | 1:7093cc21a293 | 292 | out_1.period_us(1000); |
jah128 | 1:7093cc21a293 | 293 | out_2.period_us(1000); |
jah128 | 1:7093cc21a293 | 294 | out_3.period_us(1000); |
jah128 | 1:7093cc21a293 | 295 | out_1.pulsewidth_us(0); |
jah128 | 1:7093cc21a293 | 296 | out_2.pulsewidth_us(0); |
jah128 | 1:7093cc21a293 | 297 | out_3.pulsewidth_us(0); |
jah128 | 0:d88fd55a27a6 | 298 | |
jah128 | 0:d88fd55a27a6 | 299 | while(1) { |
jah128 | 0:d88fd55a27a6 | 300 | if(phase==0){ |
jah128 | 0:d88fd55a27a6 | 301 | if(system_timer.read_us() > off_period){ |
jah128 | 0:d88fd55a27a6 | 302 | system_timer.reset(); |
jah128 | 0:d88fd55a27a6 | 303 | int pw = 250; |
jah128 | 0:d88fd55a27a6 | 304 | if(power==1) pw=500; |
jah128 | 0:d88fd55a27a6 | 305 | if(power==2) pw=750; |
jah128 | 0:d88fd55a27a6 | 306 | if(power==3) pw=1000; |
jah128 | 1:7093cc21a293 | 307 | if(mode==0 || mode==1){ |
jah128 | 1:7093cc21a293 | 308 | out_1.pulsewidth_us(pw); |
jah128 | 1:7093cc21a293 | 309 | led_1=1; |
jah128 | 0:d88fd55a27a6 | 310 | } |
jah128 | 1:7093cc21a293 | 311 | if(mode==0 || mode==2){ |
jah128 | 1:7093cc21a293 | 312 | out_2.pulsewidth_us(pw); |
jah128 | 1:7093cc21a293 | 313 | led_2=1; |
jah128 | 1:7093cc21a293 | 314 | } |
jah128 | 1:7093cc21a293 | 315 | if(mode==0 || mode==3){ |
jah128 | 1:7093cc21a293 | 316 | out_3.pulsewidth_us(pw); |
jah128 | 1:7093cc21a293 | 317 | led_3=1; |
jah128 | 1:7093cc21a293 | 318 | } |
jah128 | 0:d88fd55a27a6 | 319 | phase = 1; |
jah128 | 0:d88fd55a27a6 | 320 | } |
jah128 | 0:d88fd55a27a6 | 321 | }else{ |
jah128 | 0:d88fd55a27a6 | 322 | if(system_timer.read_us() > on_period){ |
jah128 | 0:d88fd55a27a6 | 323 | system_timer.reset(); |
jah128 | 0:d88fd55a27a6 | 324 | phase = 0; |
jah128 | 1:7093cc21a293 | 325 | out_1.pulsewidth_us(0); |
jah128 | 1:7093cc21a293 | 326 | out_2.pulsewidth_us(0); |
jah128 | 1:7093cc21a293 | 327 | out_3.pulsewidth_us(0); |
jah128 | 1:7093cc21a293 | 328 | led_1=0; |
jah128 | 1:7093cc21a293 | 329 | led_2=0; |
jah128 | 1:7093cc21a293 | 330 | led_3=0; |
jah128 | 0:d88fd55a27a6 | 331 | } |
jah128 | 0:d88fd55a27a6 | 332 | } |
jah128 | 0:d88fd55a27a6 | 333 | |
jah128 | 0:d88fd55a27a6 | 334 | |
jah128 | 0:d88fd55a27a6 | 335 | if(button1 == 1) { |
jah128 | 0:d88fd55a27a6 | 336 | if(b_p == 0) { |
jah128 | 0:d88fd55a27a6 | 337 | b_p=1; |
jah128 | 0:d88fd55a27a6 | 338 | button_timer.reset(); |
jah128 | 0:d88fd55a27a6 | 339 | } |
jah128 | 0:d88fd55a27a6 | 340 | if(b_p == 1) { |
jah128 | 0:d88fd55a27a6 | 341 | if(button_timer.read_ms() > 100) { |
jah128 | 0:d88fd55a27a6 | 342 | b_p=2; |
jah128 | 0:d88fd55a27a6 | 343 | display.clear_display(); |
jah128 | 0:d88fd55a27a6 | 344 | display.set_position(0,0); |
jah128 | 0:d88fd55a27a6 | 345 | display.write_string("Hold to change",14); |
jah128 | 0:d88fd55a27a6 | 346 | display.set_position(1,0); |
jah128 | 0:d88fd55a27a6 | 347 | display.write_string("settings",8); |
jah128 | 0:d88fd55a27a6 | 348 | } |
jah128 | 0:d88fd55a27a6 | 349 | } |
jah128 | 0:d88fd55a27a6 | 350 | if(b_p == 2) { |
jah128 | 0:d88fd55a27a6 | 351 | if(button_timer.read_ms() > 1000) { |
jah128 | 0:d88fd55a27a6 | 352 | change_settings(); |
jah128 | 0:d88fd55a27a6 | 353 | update_cycles(); |
jah128 | 0:d88fd55a27a6 | 354 | display_status(); |
jah128 | 0:d88fd55a27a6 | 355 | b_p=0; |
jah128 | 0:d88fd55a27a6 | 356 | } |
jah128 | 0:d88fd55a27a6 | 357 | } |
jah128 | 0:d88fd55a27a6 | 358 | } else { |
jah128 | 0:d88fd55a27a6 | 359 | if (b_p > 0) { |
jah128 | 0:d88fd55a27a6 | 360 | if(b_p == 2) display_status(); |
jah128 | 0:d88fd55a27a6 | 361 | b_p=0; |
jah128 | 0:d88fd55a27a6 | 362 | } |
jah128 | 0:d88fd55a27a6 | 363 | } |
jah128 | 0:d88fd55a27a6 | 364 | } |
jah128 | 0:d88fd55a27a6 | 365 | } |