-#define AMBIENT_ADC N_PWMLEDS
-#define BATTERY_ADC (N_PWMLEDS + 1)
-#define ADC1_GAIN20 (N_PWMLEDS + 2)
-
-#define NUM_ADCS 6
-volatile static unsigned char current_adc;
-static uint16_t adc_sum;
-static unsigned char sum_shift;
-static unsigned char adc_vals;
-static uint16_t adc1_gain20_offset_x16;
-
-static void inline setup_mux(unsigned char n)
-{
- ADCSRA |= _BV(ADEN); // enable ADC
+// pwmleds are measured continuously (when active)
+#define AMBIENT_ADC N_PWMLEDS // measured every jiffy (16 Hz)
+#define BUTTON_ADC (N_PWMLEDS + 1) // measured every jiffy (16 Hz)
+#define FIRST_16HZ_ADC BUTTON_ADC
+#define BATTERY_ADC (N_PWMLEDS + 2) // once per second
+#define ADC1_GAIN20 (N_PWMLEDS + 3) // once per second
+#define FIRST_1S_ADC ADC1_GAIN20
+#define ZERO_ADC (N_PWMLEDS + 4) // must be last
+
+#define NUM_ADCS ZERO_ADC
+
+struct {
+ unsigned char read_zero_log : 2;
+ unsigned char read_drop_log : 2;
+ unsigned char read_keep_log : 4;
+} adc_params[NUM_ADCS] = {
+ { 0, 1, PWMLED_ADC_SHIFT }, // pwmled 1
+ { 0, 1, PWMLED_ADC_SHIFT }, // pwmled 2
+ { 0, 1, PWMLED_ADC_SHIFT }, // pwmled 3
+ { 0, 1, AMBIENT_ADC_SHIFT }, // ambient
+ { 0, 1, 0 }, // buttons
+ { 0, 1, 0 }, // battery
+ { 0, 1, 0 }, // gain20
+};
+
+volatile unsigned char adc_is_on;
+
+volatile static unsigned char current_adc, slow_adcs_wanted;
+static uint16_t adc_sum, zero_count, drop_count, read_count, n_reads_log;
+#define ADC1_GAIN20_OFFSET_SHIFT 6
+static uint16_t adc1_gain20_offset;