void LEDS::rainbow() { _ledStrip.setPixelColor(firstRainbowIndex, Wheel((firstRainbowIndex + secondRainbowIndex) % 96)); _ledStrip.show(); // write all the pixels out if(firstRainbowIndex < _ledStrip.numPixels()) { ++firstRainbowIndex; } else { firstRainbowIndex = 0; if(secondRainbowIndex < 96 * 3) { ++secondRainbowIndex; } else { secondRainbowIndex = 0; } } Serial.print("first "); Serial.println(firstRainbowIndex); Serial.print("second "); Serial.println(secondRainbowIndex); }
void LEDS::setSectionColor(byte section[], int sectionLength, uint16_t sectionColor) { for(int i=0; i< sectionLength; i++) { _ledStrip.setPixelColor(section[i], sectionColor); _ledStrip.show(); } }
// The colorWipe method switched all LEDs to one given color void LEDS::colorWipe(uint16_t c) { for(int i = 0; i < _ledStrip.numPixels(); ++i) { _ledStrip.setPixelColor(i, c); _ledStrip.show(); } delay(50); }
void LEDS::setOneColorForAll(uint16_t color1) { int i = 0; while(i < _ledStrip.numPixels()) { _ledStrip.setPixelColor(i, color1); ++i; _ledStrip.show(); } }
void setup() { // The Arduino needs to clock out the data to the pixels // this happens in interrupt timer 1, we can change how often // to call the interrupt. setting CPUmax to 100 will take nearly all all the // time to do the pixel updates and a nicer/faster display, // especially with strands of over 100 dots. // (Note that the max is 'pessimistic', its probably 10% or 20% less in reality) strip.setCPUmax(50); // start with 50% CPU usage. up this if the strand flickers or is slow // initialise our LED strip strip.begin(); // make the first pixel red as an indicator that it is awaiting data strip.setPixelColor(0, 10, 0, 0); // turn all the other pixels on so we know they're working for(uint16_t i = 1; i < stripLength; ++i) strip.setPixelColor(i, 5, 5, 5); strip.show(); Serial.begin(serialRate); }
void loop() { // wait until we see the prefix for (byte i = 0; i < sizeof prefix; ++i) { waitLoop: while (!Serial.available()) ;; // look for the next byte in the sequence if we see the one we want if(prefix[i] == Serial.read()) continue; // otherwise, start over i = 0; goto waitLoop; } // read the transmitted data for (uint8_t i = 0; i < stripLength; i++) { byte r, g, b; while(!Serial.available()); r = Serial.read(); while(!Serial.available()); g = Serial.read(); while(!Serial.available()); b = Serial.read(); strip.setPixelColor(i, r, g, b); } strip.show(); }