From f1690c6cd15ee8de7297bbaba72781599ae812c9 Mon Sep 17 00:00:00 2001 From: bigalex Date: Fri, 5 Oct 2012 22:43:38 +0200 Subject: [PATCH] now detecting sound --- firmware/lib/bughal.c | 18 ++++++++++++------ firmware/main.c | 43 ++++++++++++++++++++++++++++++++++--------- 2 files changed, 46 insertions(+), 15 deletions(-) diff --git a/firmware/lib/bughal.c b/firmware/lib/bughal.c index ed6309e..a959499 100644 --- a/firmware/lib/bughal.c +++ b/firmware/lib/bughal.c @@ -58,12 +58,18 @@ void init_buzzr(void){ void init_mic(void){ - //its on B2 and C5, for reasons - // - DDRC |= (1 << PORTC5); - DDRB |= (1 << PORTB2); - //switch it off - buzzr_off(); + //buzzer is on B2 and C5, for reasons + // we use it as a mic + DDRC &= ~(1 << PORTC5); //switch C5 to input + DDRB |= (1 << PORTB2); //B2 as output + PORTB &= ~(1 << PORTB2);//and to GND + ADMUX = (1<0) {led_on(LED_R|LED_L);} else {led_off(LED_R|LED_L);}; maxval=0; - buzzr_inv(); - }; //end if timer_expired - maxval++; - + + }; //end if timer_expired + + // single measurement + ADMUX = (ADMUX & ~(0x1F)) | 5; // select channel 5 + ADCSRA |= (1<maxval) ? curval : maxval; + }; //end do_mode0 + + + + + + + + + + + + + + + void do_mode1(void){ static uint16_t tone; if (ModeChanged){