     }
 }
 
-// stepAnimation returns true if it is time for the next step in the animation,
-// according to the speed parameter.
-bool stepAnimation(uint8_t speed) {
+// animate returns true if the animation should be stepped.
+uint8_t animate() {
     static uint32_t lastClock = 0;
     uint32_t diff;
     uint32_t clock;
     uint32_t expectedDelay;
-    bool rval;
-
-    /* Animations are disabled when speed is zero */
-    if (speed == 0) {
-        return false;
+
+    // Animations are disabled when speed is zero.
+    if (pots.var == 0) {
+        return 0;
     }
 
     clock = millis();
     diff = clock - lastClock;
 
-    /* Otherwise, delay 1000/speed milliseconds. */
-    expectedDelay = map(speed, 1, 255, 1000, 40);
-    rval = (diff >= expectedDelay);
-
-    if (rval) {
+    expectedDelay = map(pots.var, 1, 255, 400, 5);
+    if (diff >= expectedDelay) {
         lastClock = clock;
-    }
-
-    return rval;
+        return 1;
+    }
+
+    return 0;
+}
+
+// animation animates linearly, repeating the numbers 0-255.
+uint8_t animation() {
+    static uint8_t an = 0;
+    an += animate();
+    return an;
+}
+
+// animation animates linearly, repeating the numbers 0-255.
+uint8_t animationCubic() {
+    static uint8_t an = 0;
+    static int8_t multiplier = 1;
+    if (an == 255 && multiplier == 1) {
+        multiplier = -1;
+    } else if (an == 0 && multiplier == -1) {
+        multiplier = 1;
+    }
+    an = an + (multiplier * animate());
+    return an;
 }
 
 // Read a value from an analog pin as a byte value between 0-255.

    for (uint8_t led = 0; led < NUM_LEDS; led++) {
        hue = map(led, 0, NUM_LEDS, 0, 255);
        hue += pots.var;
        leds[led] = CHSV(hue, pots.saturation, pots.val);
    }
}

// Draw the rainbow, and gradually move it according to the addition parameter,
// which regulates the speed.
void modeRainbowCycle() {
    static uint8_t offset = 0;
    uint8_t hue;
    if (stepAnimation(pots.var)) {
        offset++;
    }
    for (uint8_t led = 0; led < NUM_LEDS; led++) {
        hue = map(led, 0, NUM_LEDS, 0, 255);
        hue += offset;
        leds[led] = CHSV(hue, pots.saturation, pots.val);
    }
}



// Fill all LEDs with the same color. This mode does not have an additional parameter.
void modeSolid() {
    fill_solid(&leds[0], NUM_LEDS, CHSV(pots.hue, pots.sat, pots.val));
}

// Draw the rainbow. The additional parameter moves the rainbow back and forth.
