 void next_pattern(void);
 
 #if F_CPU == 16000000UL
-#define    TIMER1_INIT         0xF82F
+#define    TIMER1_INIT         1000
 #else
-#define    TIMER1_INIT         0xFC17
-#endif
-#define    TIMER1_FLAGS        _BV(CS11); // 8Mhz / 8 = 1us per tick.
+#define    TIMER1_INIT         61535
+#endif     
 
 volatile uint32_t g_time = 0;
-uint16_t g_timer_init = TIMER1_INIT;
-
-ISR (TIMER1_OVF_vect)
+void tick(void)
 {
     g_time++;
-    TCNT1 = g_timer_init;
 }
 
 uint32_t cmillis(void)

const uint8_t NUM_CLASSES = 10;
const uint8_t NO_CLASS = 255;
uint8_t g_classes[NUM_CLASSES];

// Gamma correction table in progmem
const uint8_t PROGMEM gamma[] = {

    uint8_t            i, ch, data[3];
    static uint8_t     found_header = 0;
    static uint16_t    crc = 0, len = 0, recd = 0;
    static uint32_t    calibrate_start = 0;
    
    if (g_calibrate)
    {
        if (Serial.available() > 0 && calibrate_start == 0)
        {
             noInterrupts();
             calibrate_start = g_time;
             interrupts();
             //calibrate_start = cmillis();
             Serial.println("start: " + String(calibrate_start));
             
             Serial.read();
             return;
        }
        if (Serial.available() > 0 && calibrate_start > 0)
        {
             uint32_t done, duration;
             noInterrupts();
             done = g_time;
             interrupts();
             //done = cmillis();
             Serial.println(" done: " + String(done));
             
             show_color(NULL);
             
             duration = done - calibrate_start;

             Serial.println("start: " + String(calibrate_start));
             Serial.println(" done: " + String(done));
             Serial.println("  dur: " + String(duration));
             Serial.read();
                       
             g_calibrate = 0;
             calibrate_start = 0;
             
             return;
        }
    }
    
    update_pattern();
    
