enable/disable sound and motot by switch in sound detection mode

This commit is contained in:
bigalex 2012-10-06 00:22:12 +02:00
parent 935dcba060
commit 799bbdeeeb

View File

@ -46,12 +46,17 @@ void do_mode0(void){
static uint16_t maxval; static uint16_t maxval;
static uint16_t lastmaxval; static uint16_t lastmaxval;
uint16_t curval; uint16_t curval;
static uint16_t soundon; static bool signaling;
static bool sound_on;
static bool motor_on;
if (ModeChanged){ if (ModeChanged){
timer_set(&mytimer, 10); timer_set(&mytimer, 10);
maxval=0; maxval=0;
ModeChanged = false; ModeChanged = false;
soundon = false; signaling = false;
sound_on = true;
motor_on = true;
init_mic(); init_mic();
maxval=0; maxval=0;
}; };
@ -60,8 +65,18 @@ void do_mode0(void){
curval =ADCW; // read result curval =ADCW; // read result
maxval = (curval>maxval) ? curval : maxval; maxval = (curval>maxval) ? curval : maxval;
//check for Buttons
if (btn_state(BTNST_SUP,BTN_LEFT)) {
button_clear(BTN_LEFT);
sound_on = !sound_on;
};
if (btn_state(BTNST_SUP,BTN_RIGHT)) {
button_clear(BTN_RIGHT);
motor_on = !motor_on;
};
if(timer_expired(&mytimer)){ if(timer_expired(&mytimer)){
if (soundon) { if (signaling) {
//turn off sound //turn off sound
music_setNote(NOTE_PAUSE,0); //mute music_setNote(NOTE_PAUSE,0); //mute
set_motor(MOTOR_OFF); set_motor(MOTOR_OFF);
@ -69,7 +84,7 @@ void do_mode0(void){
init_mic(); init_mic();
led_off(LED_R|LED_L); led_off(LED_R|LED_L);
timer_set(&mytimer, 1); timer_set(&mytimer, 1);
soundon = false; signaling = false;
lastmaxval= 10000; lastmaxval= 10000;
} else { //sound was off wer're in measuring mode } else { //sound was off wer're in measuring mode
if(maxval>lastmaxval){ if(maxval>lastmaxval){
@ -77,9 +92,9 @@ void do_mode0(void){
USART0_crlf(); USART0_crlf();
led_on(LED_R|LED_L); led_on(LED_R|LED_L);
init_buzzr(); //buzzr to output init_buzzr(); //buzzr to output
music_setNote(NOTE_C,5); if (sound_on) music_setNote(NOTE_C,5);
set_motor(MOTOR_ON); if (motor_on) set_motor(MOTOR_ON);
soundon = true; signaling = true;
timer_set(&mytimer, 5); //sound duration timer_set(&mytimer, 5); //sound duration
} else { } else {
timer_set(&mytimer, 1); timer_set(&mytimer, 1);