kartonman

randomly placed white leds

Jan 8th, 2025
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. //arduino colored lightning randomly placed white leds
  2. //randomly placed leds. num leds that light are based on audio level
  3. #include <FastLED.h>
  4.  
  5. #define LED_PIN 6 // Pin to which the data line of WS2812B is connected
  6. #define NUM_LEDS 62 // Number of LEDs in your strip
  7. #define AUDIO_INPUT_PIN A0 // Pin to which the audio input is connected
  8.  
  9. CRGB leds[NUM_LEDS]; // Define an array for LED colors
  10.  
  11. void setup() {
  12. Serial.begin(9600);
  13. FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS); // Initialize the LED strip
  14. }
  15.  
  16. void loop() {
  17. int audioLevel = analogRead(AUDIO_INPUT_PIN); // Read the audio level from A0
  18.  
  19. if (audioLevel < 550) {
  20. // If audio level is below 550, turn off all LEDs
  21. fill_solid(leds, NUM_LEDS, CRGB::Black);
  22. } else {
  23. // If audio level is above 550, calculate the number of pixels to light
  24. int numPixels = map(audioLevel, 550, 1023, 0, NUM_LEDS);
  25.  
  26. // Generate a random starting point for lighting pixels
  27. int startPixel = random(NUM_LEDS - numPixels);
  28.  
  29. // Light up the pixels
  30. fill_solid(leds + startPixel, numPixels, CRGB::Green); // You can change the color here
  31. }
  32.  
  33. FastLED.show(); // Update the LED strip
  34. delay(50); // Adjust the delay as needed
  35. }
  36.  
Advertisement
Add Comment
Please, Sign In to add comment