From 5d3c3bcb516788473b9c6197496b9424710d13f8 Mon Sep 17 00:00:00 2001 From: bigalex Date: Fri, 5 Oct 2012 23:11:24 +0200 Subject: [PATCH] better sond measurment, tolerant to static voltage on piezo --- firmware/main.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/firmware/main.c b/firmware/main.c index 1517851..7677eaf 100644 --- a/firmware/main.c +++ b/firmware/main.c @@ -44,6 +44,7 @@ void modeswitch_poll(void){ void do_mode0(void){ static timer_t mytimer; static uint16_t maxval; + static uint16_t lastmaxval; uint16_t curval; if (ModeChanged){ @@ -54,10 +55,14 @@ void do_mode0(void){ maxval=0; }; if(timer_expired(&mytimer)){ - USART0_put_uint16(maxval); - USART0_crlf(); + if(maxval>lastmaxval){ + USART0_put_uint16(maxval); + USART0_crlf(); + }; timer_set(&mytimer, 1); - if (maxval>0) {led_on(LED_R|LED_L);} else {led_off(LED_R|LED_L);}; + if (maxval>lastmaxval) {led_on(LED_R|LED_L);} else {led_off(LED_R|LED_L);}; + + lastmaxval=maxval; maxval=0;