#include <avr/io.h>
#include <avr/interrupt.h>
+#include <avr/power.h>
#include <avr/sleep.h>
#include "lights.h"
current_slow_adc = NUM_ADCS;
current_adc = 0;
+ power_adc_enable();
+ ACSR |= _BV(ACD); // but disable the analog comparator
+
ADCSRA = _BV(ADEN) // enable
| _BV(ADPS1) | _BV(ADPS0) // CLK/8 = 125 kHz
// | _BV(ADPS2) // CLK/16 = 62.5 kHz
}
#endif
+static void inline adc_based_timer()
+{
+ static uint16_t pattern_counter;
+
+ if (++pattern_counter > 250) {
+ pattern_counter = 0;
+ patterns_next_tick();
+ }
+}
+
ISR(ADC_vect) { // IRQ handler
uint16_t adcval = ADCW;
+ adc_based_timer();
+
if (read_zero) {
setup_mux(current_adc);
read_zero = 0;