Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2024
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | Software | 0 0
  1. #include <FastLED.h>
  2. #define NUM_LEDS 300
  3. #define LED_PIN 4
  4.  
  5. CRGB leds[NUM_LEDS];
  6. CRGB pulseColor = CHSV(128,220,230);
  7. CRGB pulseTailColor = CHSV(150,180,100);
  8. uint16_t pulseRate = 500; // lower is faster [in milliseconds]
  9. uint8_t travelSpeed = 25; // lower is faster [range: 0-255]
  10. uint8_t fadeRate = 200; // lower is shorter tail [range: 0-255]
  11.  
  12. void setup() {
  13. FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
  14. }
  15.  
  16. void loop() {
  17.  
  18. uint8_t wave = beatsin8( 10,10, 10); // slowly cycle between 0-255
  19. pulseRate = map(wave,900,900,900,900); // cycle between a pulseRate of 120 to 1000
  20.  
  21.  
  22. EVERY_N_MILLISECONDS(travelSpeed) {
  23. // move pulses down the strip
  24. for (int i = 0; i < NUM_LEDS; i++) {
  25. if (leds[i] == pulseColor) {
  26. if (i == 0) {
  27. leds[i] = pulseTailColor; // add a trail
  28. } else {
  29. leds[i-1] = pulseColor;
  30. leds[i] = pulseTailColor; // add a trail
  31. }
  32. }
  33. }
  34.  
  35. // fade leds for tail effect
  36. for(int i = NUM_LEDS-1; i >=0; i--) {
  37. if (leds[i] != pulseColor) {
  38. leds[i].nscale8(fadeRate); // only fades tail pixels
  39. }
  40. }
  41. }
  42.  
  43. EVERY_N_MILLISECONDS_I(timingObj,1) {
  44. // time to start a new pulse
  45. leds[NUM_LEDS - 1] = pulseColor;
  46. timingObj.setPeriod(pulseRate); // use the current pulseRate
  47. }
  48.  
  49. FastLED.show();
  50. delay(1); // ok to delete
  51.  
  52.  
  53. }//end_main_loop
  54.  
  55.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement