programa simple mide tiempo en segundos desde pulsar un botón hasta restablecerlo, aplica la función timer

Dependencies:   Debounced TextLCD mbed

Fork of teclas_aceleradas by Gustavo Ramirez

main.cpp

Committer:
tony63
Date:
2017-03-17
Revision:
1:805cb7a5f18a
Parent:
0:a33e7761911a

File content as of revision 1:805cb7a5f18a:

#include "mbed.h"
#include "DebouncedIn.h"
#include "TextLCD.h"

TextLCD lcd(PTB10, PTB11, PTE2, PTE3, PTE4, PTE5); // rs, e, d4-d7
DigitalOut led1(LED1);
DigitalOut led2(LED2);
DigitalOut led3(LED3);
DebouncedIn button1(PTC12);   //incrementar
DebouncedIn button2(PTC13);   //decrementar

int sp=0;
int t1;

int main()
{
  lcd.cls();
  lcd.locate(0,0);
  lcd.printf("T=");
    
  Timer t;
       t.stop();
       t.reset(); 
       while(1){
               if (button1.falling()){
               t.reset();
               t.start();            }
               t1=t.read();
                
               if (!button1 and t1<6){
               wait(0.1);
               ++sp;
                                     }
               if (!button1 and t1>5 and t1<11){
               sp=sp+10;
                                               }
               if (!button1 and t1>10 and t1<16){
               sp=sp+50;
                                                }                                 
               if (button1.rising()){                                 
               t.reset();
               t.start();           }                                      
               
               
               
               if (button2.falling()){
               t.reset();
               t.start();            }
               t1=t.read(); 
               if (!button2 and t1<6){
               wait(0.1);    
               --sp;
                                     }
               if (!button2 and t1>5 and t1<11){
               sp=sp-10;
                                               }
               if (!button2 and t1>10 and t1<16){
               sp=sp-50;
                                                }                                 
               if (button2.rising()){                                 
               t.reset();
               t.start();           }                                      
               
               if (sp>999){
                   sp=1000;
                          }
               if (sp<0){
                   sp=0;
                        } 
               lcd.locate(2,0);
               lcd.printf("%d",sp);
               wait(0.2);
               lcd.locate(2,0);
               lcd.printf("     ");
                   
               }
}