Advertisement
Guest User

How to change animation speed (every_n_milliseconds) during program

a guest
Mar 17th, 2024
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. #include <FastLED.h>
  2.  
  3. #define NUM_LEDS 56
  4. #define LED_PIN 2
  5.  
  6. #define potPin A1
  7.  
  8.  
  9. int i;
  10. uint8_t hue = 0;
  11. uint8_t paletteIndex = 0;
  12.  
  13. CRGB leds[NUM_LEDS];
  14.  
  15.  
  16.  
  17. // Gradient palette "bhw1_05_gp", originally from
  18. // http://soliton.vm.bytemark.co.uk/pub/cpt-city/bhw/bhw1/tn/bhw1_05.png.index.html
  19. // converted for FastLED with gammas (2.6, 2.2, 2.5)
  20. // Size: 8 bytes of program space.
  21.  
  22. DEFINE_GRADIENT_PALETTE( bhw1_05_gp ) {
  23. 0, 1,221, 53,
  24. 255, 73, 3,178};
  25.  
  26.  
  27.  
  28.  
  29. CRGBPalette16 myPal = bhw1_05_gp; // stopt gradient in een palette
  30.  
  31. void setup() {
  32.  
  33. Serial.begin(9600);
  34. FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
  35. FastLED.setBrightness(50);
  36. }
  37.  
  38. void loop() { // deze code laat willekeurige leds aangaan in een willekeurige kleur binnen het palette, en ze daarna langzaam uit faden. De potmeter bepaald hoe snel leds aanspringen, dit wordt alleen bepaald bij opstarten.
  39.  
  40. int potRead = analogRead(potPin);
  41. int potVal = map(potRead, 0, 1023, 0, 200);
  42. Serial.println(potVal);
  43.  
  44. EVERY_N_MILLISECONDS(potRead) {
  45. leds[random8(0, NUM_LEDS - 1)] = ColorFromPalette(myPal, random8(), 255, LINEARBLEND);
  46. }
  47. EVERY_N_MILLISECONDS(50) {
  48. blur1d(leds, NUM_LEDS, 100);
  49. }
  50.  
  51.  
  52.  
  53. FastLED.setBrightness(potVal);
  54. FastLED.show();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement