Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // arduino randomly placed leds blue and white.
- #include <FastLED.h>
- #define LED_PIN 6
- #define NUM_LEDS 62
- #define AUDIO_PIN A0
- CRGB leds[NUM_LEDS];
- void setup() {
- Serial.begin(9600);
- FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
- randomSeed(analogRead(0)); // Seed the random number generator with analogRead value
- }
- void loop() {
- int audioLevel = analogRead(AUDIO_PIN);
- int startPixel = random(NUM_LEDS); // Randomly determine the start pixel
- if (audioLevel < 450) {
- // No pixels light
- fill_solid(leds, NUM_LEDS, CRGB::Black);
- } else {
- int numPixels = map(audioLevel, 450, 1023, 0, NUM_LEDS);
- if (audioLevel >= 450 && audioLevel <= 550) {
- // Light blue
- fill_solid(leds, NUM_LEDS, CRGB::LightSkyBlue);
- } else if (audioLevel > 550 && audioLevel <= 650) {
- // Sky blue
- fill_solid(leds, startPixel, CRGB::Black);
- fill_solid(leds + startPixel, numPixels, CRGB::DeepSkyBlue);
- fill_solid(leds + startPixel + numPixels, NUM_LEDS - startPixel - numPixels, CRGB::Black);
- } else {
- // White
- fill_solid(leds, startPixel, CRGB::Black);
- fill_solid(leds + startPixel, numPixels, CRGB::White);
- fill_solid(leds + startPixel + numPixels, NUM_LEDS - startPixel - numPixels, CRGB::Black);
- }
- }
- FastLED.show();
- delay(50); // Adjust the delay as needed
- }
Advertisement
Add Comment
Please, Sign In to add comment