   {
     strip.setPin(i + BASE_PIN);
     strip.show(); // Initialize all pixels to 'off'
-
-    strings[i].phase = 0;
-    strings[i].timing = 0;
   }
 
-  dir = NORTH; // begin on the north resonator
+  dir = 0;
   owner = neutral;
   percent = 0;
 }

const uint16_t LEDS_PER_STRAND = 50;
const bool RGBW_SUPPORT = false;

// Mask to clear 'upper case' ASCII bit
const char CASE_MASK = ~0x20;

enum Direction { NORTH = 0, NORTHEAST, EAST, SOUTHEAST, SOUTH, SOUTHWEST, WEST, NORTHWEST };
enum Ownership {  neutral = 0, enlightened, resistance };

struct pixel_string {
  uint16_t phase;
  uint32_t timing;
};

// Static animation implementations singleton
Animations animations;

AnimationState states[NUM_STRINGS];

//Animation *pCurrAnimation;

CircularBuffer<Animation *> animationQueue;

pixel_string strings[NUM_STRINGS];

// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)

// the loop function runs over and over again forever
void loop()
{
    uint16_t i, val;

    if( collect_serial() )
    {
        // we have valid buffer of serial input
        char cmd = command[0];
        switch (cmd) {
            case '*':
                Serial.println("Magnus Core Node");
                break;
            case 'E':
            case 'e':
            case 'R':
            case 'r':
                owner = cmd == 'E' ? enlightened : resistance;
                percent = getPercent(&command[1]);
                uint8_t red, green, blue, white;
                Color c;
                c = ToColor(0x00, 
                        owner == enlightened ? 0xff : 0x00,
                        owner == resistance ? 0xff : 0x00,
                        0x00);
                for (int i = 0; i < NUM_STRINGS; i++) {
                    QueueType& animationQueue = animationQueues[i];
                    animations.pulse.init(states[i], strip, c);
                    animationQueue.setTo(&animations.pulse);
                }
                break;

            case 'N':
            case 'n':
                owner = neutral;
                percent = 20;
                for (int i = 0; i < NUM_STRINGS; i++) {
                    QueueType& animationQueue = animationQueues[i];
                    animations.redFlash.init(states[i], strip, RGBW_SUPPORT);
                    animationQueue.setTo(&animations.redFlash);
                    animationQueue.add(&animations.solid);
                }
                break;

            default:
                Serial.print("Unkwown command "); Serial.println(cmd);
                break;
        }
        Serial.print((char *)command); Serial.print(" - ");Serial.print(command[0],DEC);Serial.print(": "); 
        Serial.print("owner "); Serial.print(owner,DEC); Serial.print(", percent "); Serial.println(percent,DEC); 
    }

    strip.setPin(dir + BASE_PIN);  // pick the string

    QueueType& animationQueue = animationQueues[dir];
    unsigned int queueSize = animationQueue.size();
    if (queueSize > 1) {
        if (animationQueue.peek()->done(states[dir])) {
            animationQueue.remove();
            queueSize--;
            animationQueue.peek()->start(states[dir]);
        }
    }
    if (queueSize > 0) {
        //strip.setBrightness(255);
        strip.setBrightness((uint8_t)((uint16_t)(255*(percent/100.0))));
        //pCurrAnimation->doFrame(states[0], strip);
        animationQueue.peek()->doFrame(states[dir], strip);
    }

    // Update one strand each time through the loop
    dir = (dir + 1) % NUM_STRINGS;
}


