atuline / FastLED-Demos

Here's my updated FastLED demos from January, 2017.
GNU General Public License v3.0
611 stars 174 forks source link

Want to make class program #9

Closed LedArts closed 7 years ago

LedArts commented 7 years ago

Please help me. i want to write this code as a "class" type (class example is below). I want to add this code with other class examples.

void loop() { theaterChase(strip.Color(127, 127, 127), 50); // White theaterChase(strip.Color(127, 0, 0), 50); // Red theaterChase(strip.Color(0, 0, 127), 50); // Blue } void theaterChase(uint32_t c, uint8_t wait) { for (int j=0; j<10; j++) { //do 10 cycles of chasing for (int q=0; q < 3; q++) { for (uint16_t i=0; i < strip.numPixels(); i=i+3) { strip.setPixelColor(i+q, c); //turn every third pixel on } strip.show();

  delay(wait);

  for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
    strip.setPixelColor(i+q, 0);        //turn every third pixel off
  }
}

} }

like this class example class colorWipe: public animation { public: colorWipe(void) { w = random(256); } virtual void init(void); virtual void show(void); private: byte w; int index; bool fwd; };

void colorWipe::init(void) { int p = random(2, 4); w += p*16 + 1; fwd = random(2); index = 0; if (!fwd) index = strip.numPixels() - 1; }

void colorWipe::show(void) { uint32_t color = Wheel(w); if (fwd) { if (index > int(strip.numPixels())) { // Start new sequence with the new color init(); complete = true; return; } strip.setPixelColor(index++, color); } else { if (index < 0) { // Start new sequence with the new color init(); complete = true; return; } strip.setPixelColor(index--, color); } complete = false; }

atuline commented 7 years ago

1) This code is for the Adafruit library, which I don't use. 2) None of my examples use classes so that beginners can pick them up and learn them. 3) I never bothered to follow through on learning classes anyways.