Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //arduino colored lightning dark blue
- #include <FastLED.h>
- #define NUM_LEDS 62 // Replace with the actual number of LEDs on your strip
- #define AUDIO_SENSOR 0
- #define LED_STRIP_PIN 6 // Change to the pin you've connected the data line of your LED strip
- CRGB leds[NUM_LEDS];
- void setup() {
- analogReference(DEFAULT); // Use the default analog reference
- FastLED.addLeds<WS2812B, LED_STRIP_PIN, GRB>(leds, NUM_LEDS);
- Serial.begin(9600);
- }
- void loop() {
- int sensorValue = analogRead(AUDIO_SENSOR);
- int threshold = 450;
- if (sensorValue > threshold) {
- int numLedsToLight = map(sensorValue, threshold, 1023, 0, NUM_LEDS);
- numLedsToLight = constrain(numLedsToLight, 0, NUM_LEDS);
- for (int i = 0; i < NUM_LEDS; i++) {
- leds[i] = CRGB::Black; // Set all LEDs to off initially
- }
- for (int i = 0; i < numLedsToLight; i++) {
- leds[i] = blend(CRGB(0, 0, 128), CRGB::White, map(i, 0, numLedsToLight - 1, 0, 255));
- }
- FastLED.show();
- delay(random(100, 300)); // Random delay between flashes
- for (int i = 0; i < NUM_LEDS; i++) {
- leds[i] = CRGB::Black; // Turn off all LEDs
- }
- FastLED.show();
- }
- delay(20); // Add a small delay to avoid continuous reading
- }
Advertisement
Add Comment
Please, Sign In to add comment