//////////////////////////////////////////////////////////// #include "LPD8806.h" #include "SPI.h" #define TEST_SPI 1 // 4784 bytes 1432..1444 #define TEST_SLOWMO 2 // 4946 bytes 30228..30236 #define TEST_DEFAULT 3 // 4940 bytes 7760..7768 #define TEST_COMPILE_TIME 4 // 4858 bytes 1544..1552 #define TEST_MODE TEST_COMPILE_TIME //////////////////////////////////////////////////////////// // Number of RGB LEDs in strand: const int NumLeds = 86; // Chose 2 pins for output; can be any valid output pins: const int DataPin = 11; const int ClockPin = 13; #if TEST_MODE == TEST_SPI LPD8806 strip = LPD8806(NumLeds); #else LPD8806 strip = LPD8806(NumLeds, DataPin, ClockPin); #endif // Status for rainbow mode uint16_t rainbowCycleState = 0; //////////////////////////////////////////////////////////// class ScopeProfiler { public: ScopeProfiler() { StartTime = micros(); } ~ScopeProfiler() { uint32_t DeltaTimeMicros = micros() - StartTime; Serial.print(DeltaTimeMicros); Serial.println(" us elapsed"); } private: uint32_t StartTime; }; //////////////////////////////////////////////////////////// //Input a value 0 to 384 to get a color value. //The colours are a transition r - g -b - back to r uint32_t Wheel(uint16_t WheelPos) { byte r, g, b; switch(WheelPos / 128) { case 0: r = 127 - WheelPos % 128; //Red down g = WheelPos % 128; // Green up b = 0; //blue off break; case 1: g = 127 - WheelPos % 128; //green down b = WheelPos % 128; //blue up r = 0; //red off break; case 2: b = 127 - WheelPos % 128; //blue down r = WheelPos % 128; //red up g = 0; //green off break; } return(strip.Color(r,g,b)); } void TickRainbowCycle() { uint16_t i; for (i = 0; i < strip.numPixels(); ++i) { strip.setPixelColor(i, Wheel( ((i * 384 / strip.numPixels()) + rainbowCycleState) % 384) ); } rainbowCycleState += 1; if (rainbowCycleState == 384) { rainbowCycleState = 0; } } void RefreshStrip() { #if TEST_MODE == TEST_COMPILE_TIME strip.showCompileTime(); #else strip.show(); #endif } //////////////////////////////////////////////////////////// void setup() { Serial.begin(115200); // Start up the LED strip strip.begin(); strip.pause = 0; #if TEST_MODE == TEST_SLOWMO strip.slowmo = true; #endif RefreshStrip(); } void loop() { TickRainbowCycle(); { ScopeProfiler Profile; RefreshStrip(); } delay(3); }