Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //arduino colored lightning randomly placed white leds
- //randomly placed leds. num leds that light are based on audio level
- #include <FastLED.h>
- #define LED_PIN 6 // Pin to which the data line of WS2812B is connected
- #define NUM_LEDS 62 // Number of LEDs in your strip
- #define AUDIO_INPUT_PIN A0 // Pin to which the audio input is connected
- CRGB leds[NUM_LEDS]; // Define an array for LED colors
- void setup() {
- Serial.begin(9600);
- FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS); // Initialize the LED strip
- }
- void loop() {
- int audioLevel = analogRead(AUDIO_INPUT_PIN); // Read the audio level from A0
- if (audioLevel < 550) {
- // If audio level is below 550, turn off all LEDs
- fill_solid(leds, NUM_LEDS, CRGB::Black);
- } else {
- // If audio level is above 550, calculate the number of pixels to light
- int numPixels = map(audioLevel, 550, 1023, 0, NUM_LEDS);
- // Generate a random starting point for lighting pixels
- int startPixel = random(NUM_LEDS - numPixels);
- // Light up the pixels
- fill_solid(leds + startPixel, numPixels, CRGB::Green); // You can change the color here
- }
- FastLED.show(); // Update the LED strip
- delay(50); // Adjust the delay as needed
- }
Advertisement
Add Comment
Please, Sign In to add comment