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.
main.cpp@0:c3fdb309cfac, 2018-12-19 (annotated)
- Committer:
- agusdubatti
- Date:
- Wed Dec 19 04:40:40 2018 +0000
- Revision:
- 0:c3fdb309cfac
holafio
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| agusdubatti | 0:c3fdb309cfac | 1 | #include "mbed.h" |
| agusdubatti | 0:c3fdb309cfac | 2 | |
| agusdubatti | 0:c3fdb309cfac | 3 | DigitalOut myled(LED1); |
| agusdubatti | 0:c3fdb309cfac | 4 | Ticker tick; //Inicializar el ticker |
| agusdubatti | 0:c3fdb309cfac | 5 | |
| agusdubatti | 0:c3fdb309cfac | 6 | enum {PRENDIDO, APAGADO}; |
| agusdubatti | 0:c3fdb309cfac | 7 | |
| agusdubatti | 0:c3fdb309cfac | 8 | int timer1 = 0; |
| agusdubatti | 0:c3fdb309cfac | 9 | int timer2 = 0; |
| agusdubatti | 0:c3fdb309cfac | 10 | |
| agusdubatti | 0:c3fdb309cfac | 11 | int LED_estado = 0; |
| agusdubatti | 0:c3fdb309cfac | 12 | |
| agusdubatti | 0:c3fdb309cfac | 13 | void funcion_facu(); |
| agusdubatti | 0:c3fdb309cfac | 14 | void LED_Step(); |
| agusdubatti | 0:c3fdb309cfac | 15 | |
| agusdubatti | 0:c3fdb309cfac | 16 | int main() { |
| agusdubatti | 0:c3fdb309cfac | 17 | tick.attach(&funcion_facu, 1 / 1000.0); |
| agusdubatti | 0:c3fdb309cfac | 18 | |
| agusdubatti | 0:c3fdb309cfac | 19 | |
| agusdubatti | 0:c3fdb309cfac | 20 | while(1) { |
| agusdubatti | 0:c3fdb309cfac | 21 | LED_Step(); |
| agusdubatti | 0:c3fdb309cfac | 22 | } |
| agusdubatti | 0:c3fdb309cfac | 23 | } |
| agusdubatti | 0:c3fdb309cfac | 24 | |
| agusdubatti | 0:c3fdb309cfac | 25 | |
| agusdubatti | 0:c3fdb309cfac | 26 | void funcion_facu(){ //Funcion que descuenta cada un milisegundo las variables |
| agusdubatti | 0:c3fdb309cfac | 27 | |
| agusdubatti | 0:c3fdb309cfac | 28 | if(timer1 > 0){ |
| agusdubatti | 0:c3fdb309cfac | 29 | timer1--; |
| agusdubatti | 0:c3fdb309cfac | 30 | } |
| agusdubatti | 0:c3fdb309cfac | 31 | |
| agusdubatti | 0:c3fdb309cfac | 32 | if(timer2 > 0){ |
| agusdubatti | 0:c3fdb309cfac | 33 | timer2--; |
| agusdubatti | 0:c3fdb309cfac | 34 | } |
| agusdubatti | 0:c3fdb309cfac | 35 | |
| agusdubatti | 0:c3fdb309cfac | 36 | } |
| agusdubatti | 0:c3fdb309cfac | 37 | |
| agusdubatti | 0:c3fdb309cfac | 38 | |
| agusdubatti | 0:c3fdb309cfac | 39 | |
| agusdubatti | 0:c3fdb309cfac | 40 | |
| agusdubatti | 0:c3fdb309cfac | 41 | |
| agusdubatti | 0:c3fdb309cfac | 42 | void LED_Step(){ //Maquina de estado |
| agusdubatti | 0:c3fdb309cfac | 43 | |
| agusdubatti | 0:c3fdb309cfac | 44 | timer1 = 1000; //Tiempo para la primera vez que entre |
| agusdubatti | 0:c3fdb309cfac | 45 | |
| agusdubatti | 0:c3fdb309cfac | 46 | switch(LED_estado){ |
| agusdubatti | 0:c3fdb309cfac | 47 | |
| agusdubatti | 0:c3fdb309cfac | 48 | default: |
| agusdubatti | 0:c3fdb309cfac | 49 | case PRENDIDO: |
| agusdubatti | 0:c3fdb309cfac | 50 | if(timer1==0){ |
| agusdubatti | 0:c3fdb309cfac | 51 | myled=0; |
| agusdubatti | 0:c3fdb309cfac | 52 | timer1=2000; //Tiempo para el siguiente estado |
| agusdubatti | 0:c3fdb309cfac | 53 | LED_estado=APAGADO;} |
| agusdubatti | 0:c3fdb309cfac | 54 | break; |
| agusdubatti | 0:c3fdb309cfac | 55 | |
| agusdubatti | 0:c3fdb309cfac | 56 | case APAGADO: |
| agusdubatti | 0:c3fdb309cfac | 57 | if(timer1==0){ |
| agusdubatti | 0:c3fdb309cfac | 58 | myled=1; |
| agusdubatti | 0:c3fdb309cfac | 59 | timer1=1000; //Tiempo para el siguiente estado |
| agusdubatti | 0:c3fdb309cfac | 60 | LED_estado=PRENDIDO; |
| agusdubatti | 0:c3fdb309cfac | 61 | } |
| agusdubatti | 0:c3fdb309cfac | 62 | break; |
| agusdubatti | 0:c3fdb309cfac | 63 | |
| agusdubatti | 0:c3fdb309cfac | 64 | |
| agusdubatti | 0:c3fdb309cfac | 65 | } |
| agusdubatti | 0:c3fdb309cfac | 66 | |
| agusdubatti | 0:c3fdb309cfac | 67 | } |