mirror of
https://github.com/eddyem/stm32samples.git
synced 2026-08-15 20:49:27 +03:00
.
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
|
||||
#include "commproto.h"
|
||||
#include "hardware.h"
|
||||
#include "strfunc.h"
|
||||
#include "usart.h"
|
||||
|
||||
// 40ms for debouncing
|
||||
@@ -33,6 +34,7 @@ int main(void){
|
||||
usart_setup(115200);
|
||||
bool pressed = false;
|
||||
uint32_t Tblink = 0, Tkey = 0; // blink and key pressed time
|
||||
uint32_t Tpressed = 0;
|
||||
while(1){
|
||||
USART_flags_t f = usart_process();
|
||||
if(f.rxovrfl) usart_sendstr("Rx buffer overflow!\n");
|
||||
@@ -50,12 +52,19 @@ int main(void){
|
||||
if(!pressed){ // new event
|
||||
pressed = true;
|
||||
usart_sendstr("Key pressed\n");
|
||||
timer_start();
|
||||
Tpressed = Tms;
|
||||
}
|
||||
Tkey = Tms;
|
||||
}else{ // key released
|
||||
if(pressed && (Tms - Tkey) > TDEBOUNCE){ // wait for debounce
|
||||
timer_stop();
|
||||
uint32_t micros = timer_read();
|
||||
uint32_t millis = Tms - Tpressed;
|
||||
pressed = false;
|
||||
usart_sendstr("Key released\n");
|
||||
usart_sendstr("Tms="); usart_sendstr(u2str(millis));
|
||||
usart_sendstr("\nTus="); usart_sendstr(u2str(micros)); usart_sendstr("\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user