The Rainbow Cycle uses the color wheel to create a rainbow effect that cycles over the length of the strip. This is a straightforward re-structuring of the RainbowCycle pattern in the StrandTest example sketch from the library.
Initialization:
The RainbowCycle() function initializes the NeoPatterns class for running the Rainbow Cycle pattern.
ActivePattern is set to RAINBOW_CYCLE.
The "interval" parameter specifies the number of milliseconds between updates, which determines the speed of the pattern.
The "dir" parameter is optional. It defaults to FORWARD operation, but you can specify REVERSE.
TotalSteps is set to 255, which is the number of colors in the color wheel.
Index is set to 0, so we start with the first color in the wheel.
// Initialize for a RainbowCycle void RainbowCycle(uint8_t interval, direction dir = FORWARD) { ActivePattern = RAINBOW_CYCLE; Interval = interval; TotalSteps = 255; Index = 0; Direction = dir; }
Update:
The RainbowCycleUpdate() function sets each pixel on the strip to a color from the wheel. The starting point on the wheel is offset by Index.
After writing to the strip with a call to show(), Increment() is called to update the Index.
// Update the Rainbow Cycle Pattern void RainbowCycleUpdate() { for(int i=0; i< numPixels(); i++) { setPixelColor(i, Wheel(((i * 256 / numPixels()) + Index) & 255)); } show(); Increment(); }
Text editor powered by tinymce.