atuline

Icicle drop

Jun 9th, 2020
1,654
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.16 KB | None | 0 0
  1. /* Icicle drop
  2.  *
  3.  * By: Andrew Tuline
  4.  *
  5.  * Date: June, 2020
  6.  *
  7.  * Just a simple icicle drop. Could do with a direction parameter, terminal velocity and more. .
  8.  *
  9.  */
  10.  
  11. #include <FastLED.h>
  12.  
  13.  
  14. #define LED_DT 12
  15. #define LED_CK 11
  16. #define COLOR_ORDER GRB
  17. #define LED_TYPE WS2812
  18. #define NUM_LEDS 30
  19.  
  20. uint8_t max_bright = 255;
  21. struct CRGB leds[NUM_LEDS];
  22. CRGBPalette16 currentPalette = OceanColors_p;
  23.  
  24.  
  25. void setup() {
  26.   Serial.begin(115200);
  27.   delay(1000);
  28.   LEDS.addLeds<LED_TYPE, LED_DT, COLOR_ORDER>(leds, NUM_LEDS);
  29.   FastLED.setBrightness(max_bright);
  30. } // setup()
  31.  
  32.  
  33.  
  34. void loop () {
  35.   drop();
  36.   FastLED.show();
  37. } // loop()
  38.  
  39.  
  40.  
  41. void drop() {
  42.  
  43.   static double dropLocn = (NUM_LEDS-1);
  44.   static double dropSpd = 0;
  45.   const double grav = .0008;                     // Let's just use floating point and be done with it.
  46.  
  47.   fadeToBlackBy(leds, NUM_LEDS, 32);
  48.  
  49.   CRGB color = ColorFromPalette(currentPalette, 192,128, LINEARBLEND);
  50.   fill_solid(leds+NUM_LEDS-6, 6, color);
  51.  
  52.   dropSpd += grav;
  53.   dropLocn -= dropSpd;
  54.  
  55.   if ((dropLocn) > 0 ) {
  56.     leds[(int)dropLocn] = ColorFromPalette(currentPalette, 192, 255, LINEARBLEND);
  57.   } else {
  58.     dropLocn = (NUM_LEDS-1); dropSpd = 0;
  59.   }
  60.  
  61. }  // drop()
Advertisement
Add Comment
Please, Sign In to add comment