Hey there,
I made myself a music reactive LED string and I’d like to change the color every 7 seconds to a random color. I tryed using random seed and the HSV command (like in the code) but I couldn’t figure out how to do it.
With this code the LED string lights up in some kind of green…
Can you help me please?
My code:
#include <FastLED.h>
#define NUM_LEDS 294
#define DATA_PIN 6
int strobePin = 13; // Strobe Pin on the MSGEQ7
int resetPin = 12; // Reset Pin on the MSGEQ7
int outPin = A0; // Output Pin on the MSGEQ7
int i;
int level [7];
unsigned long timestamp;
CRGB leds[NUM_LEDS];
void setup() {
delay(2000);
Serial.begin (9600);
timestamp = millis();
// Define pin modes
pinMode (strobePin, OUTPUT);
pinMode (resetPin, OUTPUT);
pinMode (outPin, INPUT);
// Create an initial state for our pins
digitalWrite (resetPin, LOW);
digitalWrite (strobePin, LOW);
delay (1);
// Reset the MSGEQ7 as per the datasheet timing diagram
digitalWrite (resetPin, HIGH);
delay (1);
digitalWrite (resetPin, LOW);
digitalWrite (strobePin, HIGH);
delay (1);
FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
}
void loop() {
for (int i = 0; i < 7; i++) {
digitalWrite (strobePin, LOW);
delayMicroseconds (100); // Delay necessary due to timing diagram
level[i] = analogRead (outPin);
digitalWrite (strobePin, HIGH);
delayMicroseconds (100);
}
int PWMvalue1 = map(level[0], 0, 1024, 0, 255);
int PWMvalue3 = map(level[3], 0, 1024, 0, 255);
int PWMvalue2 = map(level[6], 0, 1024, 0, 255);
//###############################################################################################################
if ((millis()- timestamp) > 0 && (millis()-timestamp) < 7000) //Important part
{
while (i==0)
{
fill_solid( leds, NUM_LEDS, CHSV(random8(),255,255));
FastLED.show ();
i++;
}
}
if (millis() > 7000)
{
timestamp = millis ();
i==0;
}
if (PWMvalue1>80)
{
FastLED.setBrightness (PWMvalue1);
FastLED.show ();
delay(15);
}
else
{
FastLED.setBrightness (20);
FastLED.show ();
}
}
Thank you for your reply!
I tryed random8(eight), but then the led string just turns and keeps red. Witht he randomSeed I always get kinda green color that never changes too. I think the problem is about something else in my code...