kartonman

colored lightning dark blue

Jan 8th, 2025
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. //arduino colored lightning dark blue
  2.  
  3. #include <FastLED.h>
  4.  
  5. #define NUM_LEDS 62 // Replace with the actual number of LEDs on your strip
  6. #define AUDIO_SENSOR 0
  7. #define LED_STRIP_PIN 6 // Change to the pin you've connected the data line of your LED strip
  8.  
  9. CRGB leds[NUM_LEDS];
  10.  
  11.  
  12. void setup() {
  13. analogReference(DEFAULT); // Use the default analog reference
  14. FastLED.addLeds<WS2812B, LED_STRIP_PIN, GRB>(leds, NUM_LEDS);
  15. Serial.begin(9600);
  16. }
  17.  
  18. void loop() {
  19. int sensorValue = analogRead(AUDIO_SENSOR);
  20. int threshold = 450;
  21.  
  22. if (sensorValue > threshold) {
  23. int numLedsToLight = map(sensorValue, threshold, 1023, 0, NUM_LEDS);
  24. numLedsToLight = constrain(numLedsToLight, 0, NUM_LEDS);
  25.  
  26. for (int i = 0; i < NUM_LEDS; i++) {
  27. leds[i] = CRGB::Black; // Set all LEDs to off initially
  28. }
  29.  
  30. for (int i = 0; i < numLedsToLight; i++) {
  31. leds[i] = blend(CRGB(0, 0, 128), CRGB::White, map(i, 0, numLedsToLight - 1, 0, 255));
  32.  
  33. }
  34.  
  35. FastLED.show();
  36. delay(random(100, 300)); // Random delay between flashes
  37.  
  38. for (int i = 0; i < NUM_LEDS; i++) {
  39. leds[i] = CRGB::Black; // Turn off all LEDs
  40. }
  41.  
  42. FastLED.show();
  43. }
  44. delay(20); // Add a small delay to avoid continuous reading
  45. }
  46.  
Advertisement
Add Comment
Please, Sign In to add comment