                         strobe = 0;
         }
 
-        r *= brightness;
-        g *= brightness;
-        b *= brightness;
-
         analogWrite(RED_PIN, 255 * r);
         analogWrite(GREEN_PIN, 255 * g);
         analogWrite(BLUE_PIN, 255 * b);

        TCCR3C = 0;
        TCNT3 = 0;
        TIMSK3 = 0;
}

void loop() {

                    STROBE_FREQ = 3,
                    FLASH_FREQ = 4;

        static int mode = MODE_SMOOTH, strobe_on = 0;
        static float brightness = 1, time = 0, strobe = 0,
                     a_h = 0, a_s = 0, a_v = 0,
                     b_h = 0, b_s = 0, b_v = 0;

        int cmd = command, rep = repeated;
        command = repeated = 0;
//Serial.println(digitalRead(IR_PIN));
        if (cmd) {
                Serial.print("IR command: ");
                Serial.print(command2string(cmd));
                Serial.println(rep ? " (repeated)" : "");
        }

        float elapsed = timer3() * (1024 / 1.6e7);
        time += elapsed;

        switch (cmd) {
        case LIGHT_RED:
                a_h = a_s = a_v = 1;
                mode = MODE_STATIC;
                break;
        case LIGHT_RED1:
                a_h = -0.015;
                a_s = 1;
                a_v = 0.8;
                mode = MODE_STATIC;
                break;
        case LIGHT_RED2:
                a_h = -0.03;
                a_s = 1;
                a_v = 0.7;
                mode = MODE_STATIC;
                break;
        case LIGHT_RED3:
                a_h = -0.045;
                a_s = 1;
                a_v = 0.6;
                mode = MODE_STATIC;
                break;
        case LIGHT_RED4:
                a_h = -0.06;
                a_s = 1;
                a_v = 0.5;
                mode = MODE_STATIC;
                break;
        case LIGHT_GREEN:
                a_h = 2./3;
                a_s = 1;
                a_v = 1;
                mode = MODE_STATIC;
                break;
        case LIGHT_GREEN1:
                a_h = 2./3 - 0.025;
                a_s = 1;
                a_v = 0.6;
                mode = MODE_STATIC;
                break;
        case LIGHT_GREEN2:
                a_h = 2./3 - 0.05;
                a_s = 1;
                a_v = 0.5;
                mode = MODE_STATIC;
                break;
        case LIGHT_GREEN3:
                a_h = 2./3 - 0.075;
                a_s = 1;
                a_v = 0.4;
                mode = MODE_STATIC;
                break;
        case LIGHT_GREEN4:
                a_h = 2./3 - 0.1;
                a_s = 1;
                a_v = 0.3;
                mode = MODE_STATIC;
                break;
        case LIGHT_BLUE:
                a_h = 1./3;
                a_s = 1;
                a_v = 1;
                mode = MODE_STATIC;
                break;
        case LIGHT_BLUE1:
                a_h = 1./3 - 0.05;
                a_s = 1;
                a_v = 0.7;
                mode = MODE_STATIC;
                break;
        case LIGHT_BLUE2:
                a_h = 1./3 - 0.1;
                a_s = 1;
                a_v = 0.6;
                mode = MODE_STATIC;
                break;
        case LIGHT_BLUE3:
                a_h = 1./3 - 0.15;
                a_s = 1;
                a_v = 0.5;
                mode = MODE_STATIC;
                break;
        case LIGHT_BLUE4:
                a_h = 1./3 - 0.2;
                a_s = 1;
                a_v = 0.4;
                mode = MODE_STATIC;
                break;
        case LIGHT_SMOOTH:
                if (!rep) {
                        mode = MODE_SMOOTH;
                        time = 0;
                }
                break;
        case LIGHT_OFF:
                a_h = a_s = a_v = 0;
                mode = MODE_STATIC;
                break;
        case LIGHT_BRIGHTER:
                brightness *= 1.1;
                if (brightness > 1)
                        brightness = 1;
                break;
        case LIGHT_DARKER:
                brightness /= 1.1;
                if (brightness < 0.005)
                        brightness = 0.005;
                break;
        case LIGHT_STROBE:
                if (!rep)
                        strobe_on = !strobe_on;
                break;
        case LIGHT_FLASH:
                if (!rep) {
                        mode = MODE_FLASH;
                        a_h = random(1e6)/1e6;
                        a_s = a_v = 1;
                        time = 0;
                }
                break;
        case LIGHT_FADE:
                if (!rep) {
                        if (a_s < 1e-6) {
                                mode = MODE_FADE_ALL;
                                a_h = random(1e6)/1e6;
                                b_h = random(1e6)/1e6;
                                a_s = a_v = b_s = b_v = 1;
                        } else {
                                mode = MODE_FADE_COLOR;
                                b_h = a_h + (random(1e6)/1e6 - 0.5) / 60;
                                b_s = a_s;
                                b_v = a_v;
                        }
                        time = 0;
                }
                break;
        case 0:
                break;
        default:
                a_h = a_s = 0;
                a_v = 1;
                mode = MODE_STATIC;
                break;
        }

        /*
        while (Serial.available() >= 6) {
                char data[6];
                for (int i = 0; i < sizeof (data); ++i)
