![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Reloj
main.cpp@0:4182cf86e3bd, 2021-12-09 (annotated)
- Committer:
- javiervicente
- Date:
- Thu Dec 09 22:07:15 2021 +0000
- Revision:
- 0:4182cf86e3bd
- Child:
- 1:987fe977d122
dobleClick
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
javiervicente | 0:4182cf86e3bd | 1 | #include "mbed.h" |
javiervicente | 0:4182cf86e3bd | 2 | |
javiervicente | 0:4182cf86e3bd | 3 | #define botonPulsado 0 |
javiervicente | 0:4182cf86e3bd | 4 | #define botonNoPulsado 1 |
javiervicente | 0:4182cf86e3bd | 5 | #define tiempoMaximo 0.5 |
javiervicente | 0:4182cf86e3bd | 6 | |
javiervicente | 0:4182cf86e3bd | 7 | |
javiervicente | 0:4182cf86e3bd | 8 | Serial pc(USBTX, USBRX); // tx, rx |
javiervicente | 0:4182cf86e3bd | 9 | |
javiervicente | 0:4182cf86e3bd | 10 | DigitalOut led(LED1); |
javiervicente | 0:4182cf86e3bd | 11 | DigitalIn boton(USER_BUTTON); |
javiervicente | 0:4182cf86e3bd | 12 | Timer temporizador; |
javiervicente | 0:4182cf86e3bd | 13 | enum estados {esperandoPulsacion,esperandoSoltarBoton, esperandoSegundaPulsacion,esperandoSoltarSegundaPulsacion}; |
javiervicente | 0:4182cf86e3bd | 14 | estados estado; |
javiervicente | 0:4182cf86e3bd | 15 | |
javiervicente | 0:4182cf86e3bd | 16 | |
javiervicente | 0:4182cf86e3bd | 17 | void funcionEsperandoPulsacion() |
javiervicente | 0:4182cf86e3bd | 18 | { |
javiervicente | 0:4182cf86e3bd | 19 | if(boton==botonPulsado) { |
javiervicente | 0:4182cf86e3bd | 20 | temporizador.reset(); |
javiervicente | 0:4182cf86e3bd | 21 | temporizador.start(); |
javiervicente | 0:4182cf86e3bd | 22 | estado=esperandoSoltarBoton; |
javiervicente | 0:4182cf86e3bd | 23 | pc.printf("Boton pulsado\n"); |
javiervicente | 0:4182cf86e3bd | 24 | } |
javiervicente | 0:4182cf86e3bd | 25 | } |
javiervicente | 0:4182cf86e3bd | 26 | |
javiervicente | 0:4182cf86e3bd | 27 | void funcionEsperandoSoltarBoton() |
javiervicente | 0:4182cf86e3bd | 28 | { |
javiervicente | 0:4182cf86e3bd | 29 | if(boton==botonNoPulsado) { |
javiervicente | 0:4182cf86e3bd | 30 | estado=esperandoSegundaPulsacion; |
javiervicente | 0:4182cf86e3bd | 31 | pc.printf("Boton soltado\n"); |
javiervicente | 0:4182cf86e3bd | 32 | } |
javiervicente | 0:4182cf86e3bd | 33 | } |
javiervicente | 0:4182cf86e3bd | 34 | |
javiervicente | 0:4182cf86e3bd | 35 | void funcionEsperandoSegundaPulsacion() |
javiervicente | 0:4182cf86e3bd | 36 | { |
javiervicente | 0:4182cf86e3bd | 37 | if(temporizador.read()>tiempoMaximo) { |
javiervicente | 0:4182cf86e3bd | 38 | estado=esperandoPulsacion; |
javiervicente | 0:4182cf86e3bd | 39 | pc.printf("Emporizador expirado\n"); |
javiervicente | 0:4182cf86e3bd | 40 | } else if(boton==botonPulsado) { |
javiervicente | 0:4182cf86e3bd | 41 | led=!led; |
javiervicente | 0:4182cf86e3bd | 42 | estado=esperandoSoltarSegundaPulsacion; |
javiervicente | 0:4182cf86e3bd | 43 | pc.printf("Doble Click\n"); |
javiervicente | 0:4182cf86e3bd | 44 | } |
javiervicente | 0:4182cf86e3bd | 45 | } |
javiervicente | 0:4182cf86e3bd | 46 | |
javiervicente | 0:4182cf86e3bd | 47 | void funcionEsperandoSoltarSegundaPulsacion() |
javiervicente | 0:4182cf86e3bd | 48 | { |
javiervicente | 0:4182cf86e3bd | 49 | if(boton==botonNoPulsado) { |
javiervicente | 0:4182cf86e3bd | 50 | estado=esperandoPulsacion; |
javiervicente | 0:4182cf86e3bd | 51 | pc.printf("Boton soltado Segunda pulsacion\n"); |
javiervicente | 0:4182cf86e3bd | 52 | } |
javiervicente | 0:4182cf86e3bd | 53 | } |
javiervicente | 0:4182cf86e3bd | 54 | |
javiervicente | 0:4182cf86e3bd | 55 | int main() |
javiervicente | 0:4182cf86e3bd | 56 | { |
javiervicente | 0:4182cf86e3bd | 57 | pc.baud(115200); |
javiervicente | 0:4182cf86e3bd | 58 | estado=esperandoPulsacion; |
javiervicente | 0:4182cf86e3bd | 59 | while(1) { |
javiervicente | 0:4182cf86e3bd | 60 | switch(estado) { |
javiervicente | 0:4182cf86e3bd | 61 | case esperandoPulsacion: |
javiervicente | 0:4182cf86e3bd | 62 | funcionEsperandoPulsacion(); |
javiervicente | 0:4182cf86e3bd | 63 | break; |
javiervicente | 0:4182cf86e3bd | 64 | case esperandoSoltarBoton: |
javiervicente | 0:4182cf86e3bd | 65 | funcionEsperandoSoltarBoton(); |
javiervicente | 0:4182cf86e3bd | 66 | break; |
javiervicente | 0:4182cf86e3bd | 67 | case esperandoSegundaPulsacion: |
javiervicente | 0:4182cf86e3bd | 68 | funcionEsperandoSegundaPulsacion(); |
javiervicente | 0:4182cf86e3bd | 69 | break; |
javiervicente | 0:4182cf86e3bd | 70 | case esperandoSoltarSegundaPulsacion: |
javiervicente | 0:4182cf86e3bd | 71 | funcionEsperandoSoltarSegundaPulsacion(); |
javiervicente | 0:4182cf86e3bd | 72 | break; |
javiervicente | 0:4182cf86e3bd | 73 | } |
javiervicente | 0:4182cf86e3bd | 74 | } |
javiervicente | 0:4182cf86e3bd | 75 | } |