Generar un programa capaz de crear un contador binario de 0 a 5 (000 – 101) ascendente cuando un botón propio de la tarjeta esta presionado, en caso de no estar presionado el contador deberá ir en sentido contrario, es decir de 5 a 0, la secuencia debe ser cíclica.
Diff: main.cpp
- Revision:
- 25:86b50a023d28
- Parent:
- 24:7f14b70fc9ef
--- a/main.cpp Mon Apr 08 11:03:25 2019 +0100 +++ b/main.cpp Sun Apr 12 03:58:02 2020 +0000 @@ -1,12 +1,88 @@ -#include "mbed.h" +//Generar un programa capaz de crear un contador binario de 0 a 5 (000 – 101)ascendente cuando un botón propio de la tarjeta esta presionado, en caso de no estar presionado el contador deberá ir en sentido contrario, es decir de 5 a 0, la secuencia debe ser cíclica. + +#include "mbed.h" //librería que nos permite utilizar comandos y sentencias propias de mbed -DigitalOut myled(LED1); +DigitalIn enable(SW2); +DigitalOut un(LED3); +DigitalOut deux(LED2); +DigitalOut trois(LED1); int main() { - while(1) { - myled = 1; - wait(0.2); - myled = 0; - wait(0.2); + while(1) + { + if(enable == 1) { + //zero + un = 0; + deux=0; + trois=0; + wait(1); + + //un + un = 0; + deux=0; + trois=1; + wait(1); + + //deux + un = 0; + deux=1; + trois=0; + wait(1); + + //trois + un=0; + deux=1; + trois=1; + wait(1); + + //quatre + un=1; + deux=0; + trois=0; + wait(1); + + //cinq + un=1; + deux=0; + trois=1; + wait(1); + } else { + //cinq + un=1; + deux=0; + trois=1; + wait(1); + + //quatre + un=1; + deux=0; + trois=0; + wait(1); + + //trois + un=0; + deux=1; + trois=1; + wait(1); + + //deux + un = 0; + deux=1; + trois=0; + wait(1); + + //un + un=0; + deux=0; + trois=1; + wait(1); + + //zero + un=0; + deux=0; + trois=0; + wait(1); + } -} + } +} \ No newline at end of file