+}
+
+static void inline init_tmr()
+{
+ TCCR0A = _BV(WGM00);
+ TCCR0B = _BV(CS02); // | _BV(CS00);
+ OCR0A = 0x80;
+ TIMSK |= _BV(OCIE0A);
+ DDRA |= _BV( PA0 );
+}
+
+int main(void)
+{
+ char seen = 0;
+ char pcount, ppos;
+
+ init_pwm();
+ init_adc();
+ init_tmr();
+
+ ppos = 0;
+ pcount = pattern[ppos].length;
+ if (pattern[ppos].intensity) {
+ PORTA |= _BV( PA0 );
+ }
+
+ while (1) {
+ unsigned char pwmhi, pwmlo;
+
+ if (intflags.adc_int) {
+ intflags.adc_int = 0;
+
+ if (adcval > 0x3C0)
+ adcval = 0x3C0;
+ if (adcval < 1)
+ adcval = 1;
+ pwmhi = adcval >> 8;
+ pwmlo = adcval & 0xFF;
+
+ TC1H = pwmhi;
+ OCR1D = pwmlo;
+
+ TC1H = pwmhi;
+ OCR1B = pwmlo;
+
+ TC1H = pwmhi;
+ OCR1A = pwmlo;
+
+ TIMSK |= _BV(TOIE1);
+ }
+
+ if (intflags.pwm_int) {
+ intflags.pwm_int = 0;
+ ADCSRA |= _BV(ADIE) | _BV(ADSC);
+ }
+
+ if (intflags.tmr_int) {
+ intflags.tmr_int = 0;
+ if (--pcount == 0) {
+ ppos++;
+ pcount = pattern[ppos].length;
+ if (!pcount) {
+ ppos = 0;
+ pcount = pattern[ppos].length;
+ }
+ if (pattern[ppos].intensity) {
+ PORTA |= _BV(PA0);
+ } else {
+ PORTA &= ~_BV(PA0);
+ }
+ }
+ }
+
+ sei();
+ sleep_mode();
+ cli();