AirPower

A work in progress

	
#pragma mark - Audio Interface

void audio_init()
{
	/* Enable ADC on pin PB4, left adjust mode */
	ADCSRA |= _BV(ADEN);
	ADCSRA &= ~_BV(ADSC);
	ADMUX |= _BV(ADLAR) | _BV(MUX1);
}

void audio_wait_for_input()
{
	uint8_t value;

	do {
		value = read_adc();
	} while (AUDIO_IS_SILENT(value));
}

void audio_wait_for_silence()
{
	uint8_t value;
	
	init_timer();
    
	while (timer_overflows < SHUTDOWN_DELAY) {
		value = read_adc();
		
		if (!AUDIO_IS_SILENT(value)) {
			timer_overflows = 0;
		}
	}
    
	cleanup_timer();
}
	

As a follow up form yesterday's Circuits post, a short expert from the codebase, designed to run on an ATtiny microcontroller.