Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Fork of Elearnning by
main.cpp
00001 00002 //------------------------------------------------------------------------------ 00003 // Headers 00004 //------------------------------------------------------------------------------ 00005 00006 #include "mbed.h" 00007 #include "BLE.h" 00008 //#include "UARTService.h" 00009 //#include "nrf.h" 00010 //#include "nrf_temp.h" 00011 //#include "nrf_gpio.h" 00012 00013 00014 00015 00016 //------------------------------------------------------------------------------ 00017 00018 BLE ble; 00019 00020 00021 //------------------------------------------------------------------------------ 00022 // Inputs 00023 //------------------------------------------------------------------------------ 00024 00025 DigitalIn btn(P0_20); 00026 InterruptIn btn_event(P0_20); 00027 00028 //------------------------------------------------------------------------------ 00029 // Outputs 00030 //------------------------------------------------------------------------------ 00031 00032 DigitalOut led1(LED1); 00033 DigitalOut led2(LED2); 00034 DigitalOut led3(LED3); 00035 DigitalOut led4(LED4); 00036 00037 //------------------------------------------------------------------------------ 00038 // Timers 00039 //------------------------------------------------------------------------------ 00040 00041 Ticker t1; //Temporizador 1 00042 Ticker t2; //Temporizador 2 00043 Ticker t3; //Temporizador 3 00044 00045 Ticker auxbtn; 00046 Ticker pause; 00047 00048 //------------------------------------------------------------------------------ 00049 //-- Variables 00050 //------------------------------------------------------------------------------ 00051 00052 bool t1_start_cmd; //Variables del funcionamiento de temporizador 1 00053 bool t1_running_flag; 00054 bool t1_stop_cmd; 00055 bool t1_pause_cmd; 00056 bool t1_paused; 00057 int t1_counter; 00058 00059 bool t2_start_cmd; //Variables del funcionamiento de temporizador 2 00060 bool t2_running_flag; 00061 bool t2_stop_cmd; 00062 bool t2_pause_cmd; 00063 bool t2_paused; 00064 int t2_counter; 00065 00066 bool t3_start_cmd; //Variables del funcionamiento de temporizador 3 00067 bool t3_running_flag; 00068 bool t3_stop_cmd; 00069 bool t3_pause_cmd; 00070 bool t3_paused; 00071 int t3_counter; 00072 00073 int pause_counter; 00074 00075 int t1_interval; // Intervalo en segundos del temporizador 1 00076 int t2_interval; // Intervalo en segundos del temporizador 2 00077 int t3_interval; 00078 int pause_interval; // Intervalo en segundos del temporizador 3 00079 00080 int auxbtn_counter = 0; //Tiempo para rehabilitación de boton 00081 00082 00083 //------------------------------------------------------------------------------ 00084 //-- Functions 00085 //------------------------------------------------------------------------------ 00086 00087 void btn_event_func(); 00088 00089 void t1_func(); 00090 void t2_func(); 00091 void t3_func(); 00092 void pause_func(); 00093 void app_init(); 00094 00095 void auxbtn_func(); 00096 00097 00098 // main() runs in its own thread in the OS 00099 int main() 00100 { 00101 app_init(); 00102 00103 ble.init(); 00104 00105 btn_event.fall(&btn_event_func); 00106 btn_event.enable_irq(); 00107 00108 t1_start_cmd = true; 00109 00110 while (true) { 00111 00112 00113 00114 00115 if (t1_start_cmd) { 00116 t1_start_cmd = false; 00117 t1_counter = 0; 00118 t1.attach(t1_func,t1_interval); 00119 } 00120 00121 if (t1_stop_cmd) { 00122 t1_stop_cmd = false; 00123 00124 t1.detach(); 00125 t1_running_flag = false; 00126 led1 = 1; 00127 t2_start_cmd = true; 00128 } 00129 00130 00131 if(t2_start_cmd) { 00132 t2_start_cmd = false; 00133 if (!t2_paused) { 00134 t2_counter = 0; 00135 } 00136 t2.attach(t2_func,t2_interval); 00137 } 00138 00139 if (t2_stop_cmd) { 00140 t2_stop_cmd = false; 00141 00142 t2.detach(); 00143 t2_running_flag = false; 00144 led2 = 1; 00145 t3_start_cmd = true; 00146 } 00147 00148 if(t3_start_cmd) { 00149 t3_start_cmd = false; 00150 if (!t3_paused) { 00151 t3_counter = 0; 00152 } 00153 t3.attach(t3_func,t3_interval); 00154 } 00155 00156 if (t3_stop_cmd) { 00157 t3_stop_cmd = false; 00158 00159 t3.detach(); 00160 t3_running_flag = false; 00161 led3 = 1; 00162 t1_start_cmd = true; 00163 } 00164 00165 //ble.waitForEvent(); 00166 00167 00168 00169 00170 /* 00171 while (counter_t1 <= 10){ 00172 led2 = !led2; 00173 led1 = false; 00174 } 00175 if (counter_t1 > 10){ 00176 T1.detach(); 00177 btn1_Event.enable_irq(); 00178 t1_Stop = true; 00179 } 00180 led1 = !led1; 00181 wait(0.5); 00182 }*/ 00183 00184 00185 } 00186 00187 } 00188 00189 void pause_func() 00190 { 00191 led1 = 0;led2 = 0;led3 = 0;led4 = 0; 00192 wait_ms(100); 00193 led1=1;led2=1;led3=1;led4=1; 00194 pause_counter++; 00195 } 00196 00197 void t1_func() 00198 { 00199 00200 if (t1_pause_cmd) { 00201 t1_pause_cmd = false; 00202 t1_paused = true; 00203 t1.detach(); 00204 } 00205 00206 if(t1_paused) { 00207 pause_counter = 0; 00208 pause.attach(pause_func,pause_interval); 00209 } 00210 if (!t1_paused) { 00211 00212 led1 = 0; 00213 wait_ms(100); 00214 led1=1; 00215 t1_counter++; 00216 00217 if (t1_counter == 1) { 00218 t1_running_flag = true; 00219 } 00220 00221 if (t1_counter > 10) { 00222 t1_stop_cmd = true; 00223 } 00224 } 00225 00226 00227 } 00228 00229 void t2_func() 00230 { 00231 if (t2_pause_cmd) { 00232 t2_pause_cmd = false; 00233 t2_paused = true; 00234 t2.detach(); 00235 } 00236 if(t2_paused) { 00237 pause_counter = 0; 00238 pause.attach(pause_func,pause_interval); 00239 } 00240 if (!t2_paused) { 00241 00242 led2 = 0; 00243 wait_ms(100); 00244 led2=1; 00245 t2_counter++; 00246 00247 if (t2_counter == 1) { 00248 t2_running_flag = true; 00249 } 00250 00251 if (t2_counter > 15) { 00252 t2_stop_cmd = true; 00253 } 00254 } 00255 } 00256 00257 void t3_func() 00258 { 00259 if (t3_pause_cmd) { 00260 t3_pause_cmd = false; 00261 t3_paused = true; 00262 t3.detach(); 00263 } 00264 if(t3_paused) { 00265 pause_counter = 0; 00266 pause.attach(pause_func,pause_interval); 00267 } 00268 if (!t3_paused) { 00269 00270 led3 = 0; 00271 wait_ms(150); 00272 led3=1; 00273 t3_counter++; 00274 00275 if (t3_counter == 1) { 00276 t3_running_flag = true; 00277 } 00278 00279 if (t3_counter > 10) { 00280 t3_stop_cmd = true; 00281 } 00282 } 00283 } 00284 00285 void app_init() 00286 { 00287 led1 = led2 = led3 = led4 = 1; 00288 00289 t1_start_cmd = false; //Variables del funcionamiento de temporizador 1 00290 t1_running_flag = false; 00291 t1_stop_cmd = false; 00292 t1_pause_cmd = false; 00293 t1_paused = false; 00294 t1_counter = 0; 00295 00296 t2_start_cmd = false; //Variables del funcionamiento de temporizador 2 00297 t2_running_flag = false; 00298 t2_stop_cmd = false; 00299 t2_pause_cmd = false; 00300 t2_paused = false; 00301 t2_counter = 0; 00302 00303 t3_start_cmd = false; //Variables del funcionamiento de temporizador 3 00304 t3_running_flag = false; 00305 t3_stop_cmd = false; 00306 t3_pause_cmd = false; 00307 t3_paused = false; 00308 t3_counter = 0; 00309 00310 pause_counter = 0; 00311 00312 t1_interval = 1; // Intervalo en segundos del temporizador 1 00313 t2_interval = 1; // Intervalo en segundos del temporizador 2 00314 t3_interval = 1; 00315 pause_interval = 1; // Intervalo en segundos del temporizador 3 00316 } 00317 00318 void auxbtn_func() 00319 { 00320 auxbtn_counter++; 00321 if (auxbtn_counter > 2) { 00322 btn_event.enable_irq(); 00323 auxbtn.detach(); 00324 } 00325 } 00326 00327 00328 void btn_event_func() 00329 { 00330 btn_event.disable_irq(); 00331 auxbtn_counter = 0; 00332 auxbtn.attach(auxbtn_func,1); 00333 if(t1_running_flag && !t1_paused) { 00334 t1_pause_cmd = true; 00335 } 00336 if(t2_running_flag && !t2_paused) { 00337 t2_pause_cmd = true; 00338 } 00339 if(t3_running_flag && !t3_paused) { 00340 t3_pause_cmd = true; 00341 } 00342 if(t1_paused) { 00343 t1_paused = false; 00344 t1.attach(t1_func,t1_interval); 00345 pause.detach(); 00346 00347 } 00348 if(t2_paused) { 00349 t2_paused = false; 00350 t2.attach(t2_func,t2_interval); 00351 pause.detach(); 00352 } 00353 if(t3_paused) { 00354 t3_paused = false; 00355 t3.attach(t3_func,t3_interval); 00356 pause.detach(); 00357 } 00358 }
Generated on Tue Jul 12 2022 15:08:28 by
1.7.2
