Scanner

The Scanner pattern consists of a single bright led scanning back and forth, leaving a trail of fading leds behind as it goes.

Initialization:

 Scanner() initializes the NeoPattern object for executing the Scanner pattern.  

The color parameter is the color of the scanning pixel.

The interval parameter specifies the number of milliseconds between updates and controls the speed of the scanning.

A scan is considered to be a complete round-trip from one end of the strip to the other and back with no additional dwell-time on the end pixels.  So the TotalSteps is set to twice the number of pixels minus two.

    // Initialize for a SCANNNER
    void Scanner(uint32_t color1, uint8_t interval)
    {
        ActivePattern = SCANNER;
        Interval = interval;
        TotalSteps = (Strip->numPixels() - 1) * 2;
        Color1 = color1;
        Index = 0;
    }

Update:

ScannerUpdate() iterates over the pixels in the strip.  If the pixel corresponds to the current value of Index or TotalSteps - Index, we set the pixel to color1.

Otherwise, we 'dim' the pixel to create a fading trail effect.

As with all the other patterns, the ScannerUpdate calls show() to write to the strip and Increment() to advance the state machine.

    // Update the Scanner Pattern
    void ScannerUpdate()
    { 
        for (int i = 0; i < numPixels(); i++)
        {
            if (i == Index) // first half of the scan
            {
                Serial.print(i);
                setPixelColor(i, Color1);
            }
            else if (i == TotalSteps - Index) // The return trip.
            {
                Serial.print(i);
                setPixelColor(i, Color1);
            }
            else  // fade to black
            {
                setPixelColor(i, DimColor(getPixelColor(i)));
            }
        }
        show();
        Increment();
    }
Last updated on 2015-05-04 at 04.27.27 PM Published on 2015-03-02 at 12.29.14 PM