     uint8_t            i, ch, data[3];
     static uint8_t     found_header = 0;
     static uint16_t    crc = 0, len = 0, recd = 0;
-
+    
+    update_pattern(g_cur_pattern);
+    
     if (Serial.available() > 0) 
     {
         ch = Serial.read();

            for(int j=0; j < NUM_PIXELS; j++)
                g_pixels.setPixelColor(j, g_pixels.Color(data[0], data[1], data[2]));
            break;
        case PACKET_COLOR_ARRAY:
            for(int j=0; j < NUM_PIXELS; j++, data += 3)
                g_pixels.setPixelColor(j, g_pixels.Color(data[0], data[1], data[2]));      
            break;  
        case PACKET_PATTERN:
            g_pattern = parse(data, len - 2);
            if (!g_pattern)
            {
                Serial.println("Parse failed.");
                error_pattern();
                return;
            }

            Serial.println("Parse ok.");
            show_pattern((s_source_t *)g_pattern);
            break;  
        case PACKET_ENTROPY:
            g_random_seed = data[0];
            break;  
    }
}

void tick()
{
    g_ticks++;

    if (g_target && g_ticks >= g_target)
    {
        g_pixels.show();
        g_last_target = g_target;
        g_target = 0;
    }
}

void evaluate_pattern(s_source_t *pattern)
{
    uint8_t  i;
    color_t  color;

    if (g_target || !pattern)
        return;

    if (g_last_target)
        g_target = g_last_target + g_delay;
    else
        g_target = ticks + g_delay;

    evaluate(pattern, g_target, &color);
    for(i = 0; i < NUM_PIXELS; i++)
        g_pixels.setPixelColor(i, color.c[0], color.c[1], color.c[2]); 
}

void loop()

        }
    }

}
