kartonman

randomly placed leds blue and white.

Jan 8th, 2025 (edited)
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. // arduino randomly placed leds blue and white.
  2.  
  3. #include <FastLED.h>
  4.  
  5. #define LED_PIN 6
  6. #define NUM_LEDS 62
  7. #define AUDIO_PIN A0
  8.  
  9. CRGB leds[NUM_LEDS];
  10.  
  11. void setup() {
  12. Serial.begin(9600);
  13. FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
  14. randomSeed(analogRead(0)); // Seed the random number generator with analogRead value
  15. }
  16.  
  17. void loop() {
  18. int audioLevel = analogRead(AUDIO_PIN);
  19.  
  20. int startPixel = random(NUM_LEDS); // Randomly determine the start pixel
  21.  
  22. if (audioLevel < 450) {
  23. // No pixels light
  24. fill_solid(leds, NUM_LEDS, CRGB::Black);
  25. } else {
  26. int numPixels = map(audioLevel, 450, 1023, 0, NUM_LEDS);
  27.  
  28. if (audioLevel >= 450 && audioLevel <= 550) {
  29. // Light blue
  30. fill_solid(leds, NUM_LEDS, CRGB::LightSkyBlue);
  31. } else if (audioLevel > 550 && audioLevel <= 650) {
  32. // Sky blue
  33. fill_solid(leds, startPixel, CRGB::Black);
  34. fill_solid(leds + startPixel, numPixels, CRGB::DeepSkyBlue);
  35. fill_solid(leds + startPixel + numPixels, NUM_LEDS - startPixel - numPixels, CRGB::Black);
  36. } else {
  37. // White
  38. fill_solid(leds, startPixel, CRGB::Black);
  39. fill_solid(leds + startPixel, numPixels, CRGB::White);
  40. fill_solid(leds + startPixel + numPixels, NUM_LEDS - startPixel - numPixels, CRGB::Black);
  41. }
  42. }
  43.  
  44. FastLED.show();
  45. delay(50); // Adjust the delay as needed
  46. }
  47.  
Advertisement
Add Comment
Please, Sign In to add comment