         }
     }
 
-    evaluate_pattern(g_pattern);
-}
+}

// ----- globals ------------

// time keeping
Timer t;
volatile uint32_t   g_ticks = 0;
volatile uint32_t   g_target = 0, g_last_target = 0;
uint8_t             g_delay = 10;

// random seed
uint8_t    g_random_seed = 0;

// The current packet
uint8_t    g_packet[MAX_PACKET_LEN];

// The LED control object
Adafruit_NeoPixel g_pixels = Adafruit_NeoPixel(NUM_PIXELS, OUT_PIN, NEO_GRB + NEO_KHZ800);

// our node id
uint8_t g_node_id = 0;


void show_color(uint8_t r, uint8_t g, uint8_t b)

            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_cur_pattern = (s_source_t *)parse(data, len - 2);
            if (!g_cur_pattern)
            {
                Serial.println("Parse failed.");
                error_pattern();
                return;
            }
            start_pattern(g_cur_pattern);
            break;  
            
        case PACKET_ENTROPY:
            g_random_seed = data[0];
            break;  
    }
}

void start_pattern(s_source_t *pattern)
{
    uint8_t  i;
    color_t  color;
    
    g_pattern_start = millis();
    g_target = g_pattern_start;
    
    evaluate(pattern, g_pattern_start, &color);
    for(i = 0; i < NUM_PIXELS; i++)
        g_pixels.setPixelColor(i, color.c[0], color.c[1], color.c[2]); 
}    

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

    if (!pattern)
        return;
       
    if (g_target && millis() >= g_target)
    {
        g_target += g_delay;
        g_pixels.show();

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

void loop()
