 		}
 	}
 
-	Serial.println(fadeBrightness);
 	setBrightness(fadeBrightness);
 }
 
-void showRainbow(byte wait)
-{
-	uint16_t i;
-	uint16_t j;
-
-	for(j = 0; j < 256 * 5; j++) 
-	{
-		for(i = 0; i < pixels.numPixels(); i++) 
-		{
-			pixels.setPixelColor(i, Wheel(( i + j) & 255));
-		}
-
-		pixels.show();
-		delay(wait);
-	}
-}
-
-uint32_t Wheel(byte WheelPos) 
+void showRainbow()
+{
+	rainbowCounter++;
+	if(rainbowCounter >= 256 * 5)
+	{
+		rainbowCounter = 0;
+	}
+
+	for(int i = 0; i < pixels.numPixels(); i++) 
+	{
+		pixels.setPixelColor(i, Wheel(( i + rainbowCounter) & 255));
+	}
+
+	pixels.show();
+}
+
+uint16_t Wheel(byte WheelPos) 
 {
 	WheelPos = 255 - WheelPos;
 

{
	while (!Serial.available());

	delay(25);

	while(Serial.available()) 
	{
		if (Serial.available() > 0) 
		{
			char data = (char)Serial.read();
			cmd += data;

			if(data == 0x0A) {

				flashColorThread.enabled = false;
				alternateColorsThread.enabled = false;
				fadeThread.enabled = false;

				setBrightness(255);

				switch (cmd[0])
				{
					case (char)SHOW_COLOR:
						setColor(-1, cmd[1], cmd[2], cmd[3]);
						break;

					case (char)SET_BRIGHTNESS:
						setBrightness(cmd[1]);
						break;

					case (char)TWO_COLOR:
						setColor(0, cmd[1], cmd[2], cmd[3]);
						setColor(1, cmd[4], cmd[5], cmd[6]);
						break;

					case (char)ALTERNATE_COLORS:
						colorOne[0] = cmd[1];
						colorOne[1] = cmd[2];
						colorOne[2] = cmd[3];

						colorTwo[0] = cmd[4];
						colorTwo[1] = cmd[5];
						colorTwo[2] = cmd[6];

						alternateColorsThread.setInterval(cmd[7] * 100);
						alternateColorsThread.enabled = true;
						break;

					case (char)FLASH_COLOR:
						colorOne[0] = cmd[1];
						colorOne[1] = cmd[2];
						colorOne[2] = cmd[3];

						flashColorThread.setInterval(cmd[4] * 100);
						flashColorThread.enabled = true;
						break;

					case (char)SHOW_RAINBOW:
						showRainbow(cmd[1]);
						break;

					case (char)FADE:
						setColor(-1, cmd[1], cmd[2], cmd[3]);
						fadeBrightness = 255;
						isFadingDown = true;

						Serial.println(cmd[4] * 1);

						fadeThread.setInterval(cmd[4] * 1);
						fadeThread.enabled = true;
						break;
				}
			
				cmd = "";
			}
		}
	}
}

	pixels.begin();
	pixels.show();
	
	Timer1.initialize(10000);
	Timer1.attachInterrupt(timerCallback);
	Timer1.start();
}
