Advertisement
Guest User

Pulse

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