I have noticed a glitch in my code. It cycles through different LED settings some using FFT and some not. The settings that don't use FFT glitch out. I have found that when removing both audio memory in setup and AudioOutputI2S the glitch goes away. When adding either one of those pieces the glitch is back.
I have simplified the problem in this code below. Its just a simple fade function but when running it will glitch out. It also does not need to be receiving any audio signal to perform this visual glitch. If I remove the two Audio pieces it runs just fine.
Any Ideas on how to fix this?
I have simplified the problem in this code below. Its just a simple fade function but when running it will glitch out. It also does not need to be receiving any audio signal to perform this visual glitch. If I remove the two Audio pieces it runs just fine.
Any Ideas on how to fix this?
Code:
#include <FastLED.h>
#define NUM_LEDS 6
#define DATA_PIN 2
#define BUTTON_PIN 8
#include <avr/power.h>
byte buttonChangeClick = 1;
byte buttonChangeHold = 1;
byte buttonChange3 = 1;
byte prevButtonChangeClick = 1;
byte prevButtonChangeHold = 1;
byte prevButtonChange3 = 1;
unsigned long millisTime;
static unsigned last_time = 0;
CRGB leds[NUM_LEDS];
int ledLevelPin = 0;
int ledLevelVal = 0;
int ledLevel;
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
AudioControlSGTL5000 audioShield;
byte fadeColor = 50;
byte fadeCount = 1;
AudioInputI2S audioInput; // audio shield: mic or line-in
AudioSynthWaveformSine sinewave;
AudioAnalyzeFFT1024 myFFT;
AudioOutputI2S audioOutput;
AudioConnection patchCord1(audioInput, 0, myFFT, 0);
const int myInput = AUDIO_INPUT_LINEIN;
void setup() {
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
AudioMemory(12);
audioShield.enable();
audioShield.inputSelect(myInput);
audioShield.volume(0.5);
myFFT.windowFunction(AudioWindowHanning1024);
sinewave.amplitude(0.8);
sinewave.frequency(1034.007);
}
void loop()
{
fadeLoop();
}
void fadeLoop()
{
millisTime = millis();
if (millisTime - last_time > 40 && fadeCount == 1)
{
fadeColor ++;
leds[0] = CRGB (fadeColor,0,255);
leds[2] = CRGB (fadeColor,0,255);
leds[4] = CRGB (fadeColor,0,255);
leds[1] = CRGB (fadeColor,0,0);
leds[3] = CRGB (fadeColor,0,0);
leds[5] = CRGB (fadeColor,0,0);
FastLED.show();
last_time = millisTime;
if (fadeColor >= 254) fadeCount =2;
}
if (millisTime - last_time > 40 && fadeCount == 2)
{
fadeColor --;
leds[0] = CRGB (fadeColor,0,255);
leds[2] = CRGB (fadeColor,0,255);
leds[4] = CRGB (fadeColor,0,255);
leds[1] = CRGB (fadeColor,0,0);
leds[3] = CRGB (fadeColor,0,0);
leds[5] = CRGB (fadeColor,0,0);
FastLED.show();
last_time = millisTime;
if (fadeColor <= 50) fadeCount =1;
}
}