Skip to content

Instantly share code, notes, and snippets.

@cpl
Created May 21, 2019 15:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cpl/d4e085ddf7e8504f083e2b919d2123c7 to your computer and use it in GitHub Desktop.
Save cpl/d4e085ddf7e8504f083e2b919d2123c7 to your computer and use it in GitHub Desktop.
Arduino Sound LED Strip
#include <FastLED.h>
#define AUDIO_PIN A0
#define LEDST_PIN 5
#define LED_TYPE WS2811
#define BRIGHTNESS 100
#define NUM_LEDS 60
#define COLOR_ORDER GRB
#define UPDATES_PER_SECOND 100
CRGB leds[NUM_LEDS];
CRGBPalette16 colors;
CRGB randcolor;
int start = 0;
void setup() {
delay(3000);
Serial.begin(115200);
pinMode(5, INPUT);
pinMode(6, OUTPUT);
FastLED.addLeds<LED_TYPE, LEDST_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
FastLED.setBrightness( BRIGHTNESS );
}
int maxread = 0;
CRGB lastread;
void loop() {
int reading = analogRead(AUDIO_PIN);
if (reading > 50) {
lastread = CHSV(reading, 255, reading%200+random8()%50);
}
if (reading > maxread) {
maxread = reading;
Serial.println(maxread);
}
for (int i = NUM_LEDS-1; i >= 1 ; i--) {
leds[i] = leds[i-1];
}
leds[0] = lastread;
FastLED.show();
FastLED.delay(1000 / UPDATES_PER_SECOND);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment