(WIP) RGB controller on Arduino w/ sync to main PC system
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ripple.cpp 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #include "ripple.h"
  2. #include "color.h"
  3. // ==== The Ripple Effect ====
  4. void RippleEffect::reset() {
  5. paletteCounter = 0;
  6. rippleCounter = 0;
  7. rippleWidth = NUM_LEDS / 3;
  8. rippleDecrement = MAX_BRIGHTNESS / rippleWidth;
  9. }
  10. void RippleEffect::postInit() {
  11. this->stepColor();
  12. }
  13. void RippleEffect::stepColor() {
  14. curColor = *getPaletteColor(paletteCounter);
  15. nextColor = *nextPaletteColor(&paletteCounter);
  16. }
  17. void RippleEffect::onUpdate() {
  18. int cycleProgress = rippleDecrement * (rippleCounter % rippleWidth);
  19. for (int k = 0; k < RIPPLE_CENTERS; k++) {
  20. int startCell = 0;
  21. if (k > 0) {
  22. startCell =
  23. rippleCenter[k - 1] + (rippleCenter[k] - rippleCenter[k - 1]) / 2;
  24. }
  25. int endCell = NUM_LEDS - 1;
  26. if (k < RIPPLE_CENTERS - 1) {
  27. endCell = rippleCenter[k] + (rippleCenter[k + 1] - rippleCenter[k]) / 2;
  28. }
  29. // Shift every LED left to the center left
  30. for (int i = startCell; i < rippleCenter[k] - 1; i++) {
  31. leds[i] = CRGB(leds[i + 1].r, leds[i + 1].g, leds[i + 1].b);
  32. }
  33. // Shift every LED right to the center right
  34. for (int i = endCell; i > rippleCenter[k] - 1; i--) {
  35. leds[i] = CRGB(leds[i - 1].r, leds[i - 1].g, leds[i - 1].b);
  36. }
  37. // Calculate new color for center
  38. int center = rippleCenter[k] - 1;
  39. leds[center] = blendColor(curColor, nextColor, rippleCounter, rippleWidth);
  40. }
  41. if (rippleCounter == rippleWidth - 1) {
  42. this->stepColor();
  43. }
  44. rippleCounter = (rippleCounter + 1) % rippleWidth;
  45. }