     }
 }
 
+// stepAnimation returns true if it is time for the next step in the animation,
+// according to the speed parameter.
+bool stepAnimation(uint8_t speed) {
+    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;
+    }
+
+    clock = millis();
+    diff = clock - lastClock;
+
+    /* Otherwise, delay 1000/speed milliseconds. */
+    expectedDelay = map(speed, 1, 255, 1000, 40);
+    rval = (diff >= expectedDelay);
+
+    if (rval) {
+        lastClock = clock;
+    }
+
+    return rval;
+}
+
 // Read a value from an analog pin as a byte value between 0-255.
 uint8_t adc8(uint8_t pin) {
     uint16_t analog = analogRead(pin);

// This variable holds the LED color state.
CRGB leds[NUM_LEDS];

/* All the different modes that are available. */
#define MAX_MODES 10
void modeOff();
void modeSolid();
void modeRainbow();
void (*modes[MAX_MODES])() = {
    &modeOff,
    &modeSolid,
    &modeRainbow,
    &modeOff,
    &modeOff,
    &modeOff,
    &modeOff,

    uint8_t val;
} pots;

// Initial setup, called once on boot.
void setup() {
    FastLED.addLeds<NEOPIXEL, PIN_LED>(leds, NUM_LEDS).setCorrection(TypicalSMD5050);
#ifdef DEBUG_POTS
