Gestione Timer per roboval
Timer di misura per roboval. Il programma è stato scritto per la scheda Nucleo STM32F401RE, prevede la misura del tempo totale e dei parziali sui tre giri
Diff: main.cpp
- Revision:
- 1:289167b04f0d
- Parent:
- 0:c7170b5cd312
- Child:
- 2:9fc2b9475b38
--- a/main.cpp Mon Mar 07 08:51:08 2016 +0000 +++ b/main.cpp Fri Apr 22 07:21:35 2016 +0000 @@ -4,7 +4,7 @@ #include "TextLCD.h" #define NUM_LAP 3 - +#define VBAT_MIN 7 typedef struct time_screen { int cents; @@ -14,12 +14,13 @@ DigitalOut heartbeat(LED1); +AnalogIn vbat(PC_3); InterruptIn user_button(USER_BUTTON); InterruptIn proximity(D9); Timer t; -TextLCD lcd(D3,D4,D5,D6,D7,D8); +TextLCD lcd(D2,D3,D4,D5,D6,D7); int lap = 0; int last_read = 0; @@ -50,12 +51,13 @@ lap++; }else{ //Dabouncing per evitare problemi - if(read - last_read > 100){ + if(read - last_read > 1000){ lap_time = read - last_read; - if(lap > NUM_LAP){ + if(lap >= NUM_LAP){ t.stop(); + lap++; }else{ lap++; } @@ -67,9 +69,11 @@ } void reset_measure(){ + t.stop(); t.reset(); lap = 0; last_read = 0; + lcd.cls(); } @@ -82,6 +86,9 @@ proximity.rise(&measure_time); user_button.fall(&reset_measure); + //Controllo batteria + + while(true) { int read = t.read_ms(); @@ -100,9 +107,19 @@ heartbeat = !heartbeat; - if(lap > 0){ - wait(0.2); + if(lap > 0 && lap <= NUM_LAP){ + wait(0.1); }else{ + if(lap == 0){ + double battery = ((3.3 * vbat) * 57) / 10; + if(battery < VBAT_MIN){ + lcd.locate(0,1); + lcd.printf("LOW BAT %2.1f",battery); + }else{ + lcd.locate(0,1); + lcd.printf("OK BAT %2.1f",battery); + } + } wait(1); } }