Compilar y cargar un programa que simule un semáforo, es decir que encienda un LED durante cierto tiempo, después otro LED otro cierto intervalo de tiempo y finalmente encienda un último LED tal y como lo hace un semáforo (incluir la intermitencia). El programa debe ser cíclico (utilizar leds internos de la tarjeta).
Revision 25:ec72507ea71b, committed 2020-04-12
- Comitter:
- nervy
- Date:
- Sun Apr 12 03:56:57 2020 +0000
- Parent:
- 24:7f14b70fc9ef
- Commit message:
- e3p3
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Mon Apr 08 11:03:25 2019 +0100 +++ b/main.cpp Sun Apr 12 03:56:57 2020 +0000 @@ -1,12 +1,46 @@ -#include "mbed.h" +#include "mbed.h" //librería que nos permite utilizar comandos y sentencias propias de mbed + +DigitalOut alto(LED1); +DigitalOut prev(LED2); +DigitalOut siga(LED3); -DigitalOut myled(LED1); +void luz_alto() { + alto = 1; + prev = 0; + siga = 0; + wait(5); +} -int main() { - while(1) { - myled = 1; - wait(0.2); - myled = 0; +void luz_preventivo() { + alto = 0; + prev = 1; + siga = 0; + wait(1); +} + +void luz_siga() { + alto = 0; + prev = 0; + siga = 1; + wait(3); +} + +void parpadear_luz(DigitalOut luz) { + for(int i=0; i<4; i++) { + luz = 1; wait(0.2); } } + +int main() { + + while(true) + { + luz_alto(); + parpadear_luz(alto); + luz_preventivo(); + luz_siga(); + parpadear_luz(siga); + } + +} \ No newline at end of file