Advertisement
kartonman

sound actuated led pixel strips

Nov 8th, 2021
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. /* flash 3 Pixel LED strips randomly by uri with sound input
  2. www. steamtraininfo.com.
  3. This sketch uses 3
  4. WS2812B pixel strips.
  5. */
  6.  
  7. #include <FastLED.h>
  8. #define NUM_LEDS 15 /*the number of leds that will light. If */
  9. //****************************
  10. #define DATA_PINA 8 // Connect to the data wires on the pixel strips
  11. #define DATA_PINB 7
  12. #define DATA_PINC 6
  13. #define Sound A1
  14. int val = 0;
  15.  
  16. CRGB ledsA[NUM_LEDS]; // sets number of pixels that will light on each strip.
  17. CRGB ledsB[NUM_LEDS];
  18. CRGB ledsC[NUM_LEDS];
  19.  
  20. //*****************************************************
  21.  
  22. void setup() {
  23. FastLED.addLeds<WS2812B, DATA_PINA, GRB>(ledsA, NUM_LEDS);
  24. FastLED.addLeds<WS2812B, DATA_PINB, GRB>(ledsB, NUM_LEDS);
  25. FastLED.addLeds<WS2812B, DATA_PINC, GRB>(ledsC, NUM_LEDS);
  26. randomSeed(analogRead(A0)); /*sets the pin to create "static so the the initial LED to light is different
  27. each time through the loop */
  28. pinMode(Sound, INPUT);
  29. }
  30.  
  31. //********************************************************
  32.  
  33. void loop() {
  34. val = analogRead(Sound);
  35. if (val > 750) {
  36. BlinkRandomly();
  37. }
  38. }
  39.  
  40. //**************************************************
  41. void fillStrip(int number, const struct CRGB &color) {
  42. switch (number) {
  43. case 1:
  44. fill_solid(ledsA, NUM_LEDS, color);
  45. break;
  46. case 2:
  47. fill_solid(ledsB, NUM_LEDS, color);
  48. break;
  49. case 3:
  50. fill_solid(ledsC, NUM_LEDS, color);
  51. break;
  52. case 4:
  53. fill_solid(ledsC, NUM_LEDS, color);
  54. fill_solid(ledsB, NUM_LEDS, color);
  55. break;
  56. }
  57. FastLED.show();
  58. }
  59.  
  60. //**************************************************
  61. void BlinkRandomly() {
  62. int delayTime = random(25, 200); // sets the blink rate in milliseconds
  63. int stripIndex = random(1, 5);
  64. fillStrip(stripIndex, CRGB::Red);
  65. delay(delayTime);
  66. fillStrip(stripIndex, CRGB::Black);
  67. delay(delayTime);
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement