Hello guys,
I am new in these waters.
I am doing for my finish project for Faculty. VU meter.
I have Teensy 3.2 + audio board. On it is connected programabile LED strip type WS2812B. For input I use LineIn or Mic.
My code works and everything is shown on LEDs and Serial monitor (for test) if I use at the end of my code FastLED.show(); then Delay(40); and FastLED.clear();. But this is not correct, everytime all LEDs turn off after code ends.
After that I've put in my code which LEDs and how needs to be turned on and other LEDs which I don't need I turn it off:
for(int led1 = NUM_LEDS; led1 >= ledsToLightLeft; led1--){
ledsLeft[led1] = CRGB(0,0,0);
}
Then before code ends I just put FastLED.show(); to show what code calculates.
So regarding on microphone output, code calculates how many LEDs need to be turned on, other from previous calculation turns off (if previous peak was higher).
But when I run the program. The Void loop runs just once (LEDs turn on that value), even if I open Serial monitor it shows the given peak from microphone but it stays on that value.
Bellow is my code and if someone have a clue what is incorrect please comment it:
I will be very thankful for any asnwer.
I hope I was clear enough
I am new in these waters.
I am doing for my finish project for Faculty. VU meter.
I have Teensy 3.2 + audio board. On it is connected programabile LED strip type WS2812B. For input I use LineIn or Mic.
My code works and everything is shown on LEDs and Serial monitor (for test) if I use at the end of my code FastLED.show(); then Delay(40); and FastLED.clear();. But this is not correct, everytime all LEDs turn off after code ends.
After that I've put in my code which LEDs and how needs to be turned on and other LEDs which I don't need I turn it off:
for(int led1 = NUM_LEDS; led1 >= ledsToLightLeft; led1--){
ledsLeft[led1] = CRGB(0,0,0);
}
Then before code ends I just put FastLED.show(); to show what code calculates.
So regarding on microphone output, code calculates how many LEDs need to be turned on, other from previous calculation turns off (if previous peak was higher).
But when I run the program. The Void loop runs just once (LEDs turn on that value), even if I open Serial monitor it shows the given peak from microphone but it stays on that value.
Bellow is my code and if someone have a clue what is incorrect please comment it:
Code:
#include <FastLED.h>
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SerialFlash.h>
#define DATA_PIN 12
#define NUM_LEDS 60
#define BRIGHTNESS 50
CRGB ledsLeft[NUM_LEDS];
// GUItool: begin automatically generated code
AudioInputI2S i2s2; //xy=412,200
AudioOutputI2S i2s1; //xy=595.0000076293945,156.9999885559082
AudioAnalyzePeak peak2; //xy=596.551176071167,294.00562477111816
AudioAnalyzePeak peak1; //xy=597.5511741638184,239.0056552886963
AudioConnection patchCord1(i2s2, 0, i2s1, 0);
AudioConnection patchCord2(i2s2, 0, peak1, 0);
AudioConnection patchCord3(i2s2, 1, i2s1, 1);
AudioConnection patchCord4(i2s2, 1, peak2, 0);
AudioControlSGTL5000 sgtl5000_1; //xy=421.00000762939453,370.9999942779541
// GUItool: end automatically generated code
int middleColorLED = 30;
int ledsToLightLeft;
elapsedMillis msecs;
void setup() {
AudioMemory(100);
FastLED.addLeds<WS2812B, DATA_PIN, GRB>(ledsLeft, NUM_LEDS);//.setCorrection( TypicalSMD5050 );
FastLED.setBrightness(BRIGHTNESS);
sgtl5000_1.enable();
sgtl5000_1.volume(0.8);
sgtl5000_1.inputSelect(AUDIO_INPUT_LINEIN);
sgtl5000_1.lineInLevel(7);
}
void loop() {
if (msecs > 1000){
if (peak1.available()) {
msecs = 0;
float leftPeak = peak1.read();
int count;
for (count=0; count < 60-leftPeak; count++) {
Serial.print(" ");
}
while (count++ < 60) {
Serial.print("<");
}
while (count++ < 60) {
Serial.print(" ");
}
Serial.print(leftPeak);
Serial.println();
ledsToLightLeft = map(leftPeak, 0, 1, 0, NUM_LEDS);
for(int led = 0; led < ledsToLightLeft; led++){
if(led < middleColorLED){
ledsLeft[led] = CRGB(map(led, 0, middleColorLED - 1, 0, 255) ,255,0);
}
else if(led > middleColorLED){
ledsLeft[led] = CRGB(255, map(led, middleColorLED, NUM_LEDS, 255, 0),0);
}
}
for(int led1 = NUM_LEDS; led1 >= ledsToLightLeft; led1--){ //IF I INCLUDE THAT FOR LOOP IT STOP WORKING. IT RUN JUST ONCE.
ledsLeft[led1] = CRGB(0,0,255);
}
FastLED.show();
}
}
}
I hope I was clear enough
Last edited by a moderator: