Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* flash 3 Pixel LED strips randomly by uri with sound input
- www. steamtraininfo.com.
- This sketch uses 3
- WS2812B pixel strips.
- */
- #include <FastLED.h>
- #define NUM_LEDS 15 /*the number of leds that will light. If */
- //****************************
- #define DATA_PINA 8 // Connect to the data wires on the pixel strips
- #define DATA_PINB 7
- #define DATA_PINC 6
- #define Sound A1
- int val = 0;
- CRGB ledsA[NUM_LEDS]; // sets number of pixels that will light on each strip.
- CRGB ledsB[NUM_LEDS];
- CRGB ledsC[NUM_LEDS];
- //*****************************************************
- void setup() {
- FastLED.addLeds<WS2812B, DATA_PINA, GRB>(ledsA, NUM_LEDS);
- FastLED.addLeds<WS2812B, DATA_PINB, GRB>(ledsB, NUM_LEDS);
- FastLED.addLeds<WS2812B, DATA_PINC, GRB>(ledsC, NUM_LEDS);
- randomSeed(analogRead(A0)); /*sets the pin to create "static so the the initial LED to light is different
- each time through the loop */
- pinMode(Sound, INPUT);
- }
- //********************************************************
- void loop() {
- val = analogRead(Sound);
- if (val > 750) {
- BlinkRandomly();
- }
- }
- //**************************************************
- void fillStrip(int number, const struct CRGB &color) {
- switch (number) {
- case 1:
- fill_solid(ledsA, NUM_LEDS, color);
- break;
- case 2:
- fill_solid(ledsB, NUM_LEDS, color);
- break;
- case 3:
- fill_solid(ledsC, NUM_LEDS, color);
- break;
- case 4:
- fill_solid(ledsC, NUM_LEDS, color);
- fill_solid(ledsB, NUM_LEDS, color);
- break;
- }
- FastLED.show();
- }
- //**************************************************
- void BlinkRandomly() {
- int delayTime = random(25, 200); // sets the blink rate in milliseconds
- int stripIndex = random(1, 5);
- fillStrip(stripIndex, CRGB::Red);
- delay(delayTime);
- fillStrip(stripIndex, CRGB::Black);
- delay(delayTime);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement