I will definetely give that a thorough read. Judging by the quick scimming I did and the animation included, I would say that that is kinda what the code does. I am pretty confident that I understand what it does, I am just a bit confused why that is possible. Anyway, I will read what you sent :).
I have one last problem though (everything else works now, so I am very close to completion) and it is just from a programming standpoint I guess. Since you made the mistake of answering me again (thank you :)), I am going to ask you first. I will put my Code below.
The comments in the code should explain what it does, but I will try to explain it here too. The while loop is where I get my "analog" output from (the sorcery) and the for loops are adressing the two LED stripes. Some tweaking in that part of the code might be necessary, but it shouldnt play a role with my problem.
This is my problem:
I need the mic code to run until there is an output that the LEDs can use and I opted for a while loop. The problem is that I can basically choose between the mic code working
while(millisElapsed <= (Sample_Time+1))
and LED code working (I am assuming that I never exit the while loop and never reach the LED code otherwise)
while(millisElapsed <= Sample_Time)
This is the complete code, I hope I dont violate any international laws with my programming style.
#include <Adafruit_NeoPixel.h>
#define LED1 17
#define N_PIXELS 25
#define LED2 32
Adafruit_NeoPixel strip1 = Adafruit_NeoPixel(N_PIXELS, LED1, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip2 = Adafruit_NeoPixel(N_PIXELS, LED2, NEO_GRB + NEO_KHZ800);
const int micPin = 33;
const int Sample_Time = 10;
unsigned long millisCurrent;
unsigned long millisLast;
unsigned long millisElapsed = 0;
int Volume = 0;
int i = 0;
int Height = 0;
double Sensitivity = 1;
void setup()
{
Serial.begin(9600);
while( !Serial) delay(20);
pinMode(micPin , INPUT);
}
//while loop takes the binary output from the mic and turns it into a (faked but surprisingly well working) analog output to use for the VU-Meter
void loop()
{
while(millisElapsed <= (Sample_Time+1)) // while loop added because the mic code has to run often enough for if (millisElapsed > Sample_Time) to activate (no output otherwise)
{
millisCurrent = millis(); //millis() is time since the programm started
millisElapsed = millisCurrent - millisLast; //millisElapsed is time since end of last Sample time
if(digitalRead(micPin) == HIGH) // HIGH = there is a sound detected (mic output is only binary)
{
Volume++;
}
if (millisElapsed > Sample_Time) //Sample time is 10 millis
{
Serial.println(Volume); // basically just for testing purposes
Height = Volume / 240 * Sensitivity; // Height is how many of the 25 LEDs will light up (numbers probably need some tweaking)
Volume = 0; // Volume reset for next loop
millisLast = millisCurrent; // in order to calculate the next millisElapsed
}
}
Height = 12; // just to see if the LEDs work without relying on the mic data
for (i = 0; i < N_PIXELS; i++) // rest of the code isnt that important for the problem, it works when commenting the mic code or changing while(millisElapsed <= (Sample_Time+1)) to while(millisElapsed <= Sample_Time)
{
if (i >= Height)
{
strip1.setPixelColor(i, 0, 0, 0);
}
else
{
strip1.setPixelColor(i, 0, 0, 150);
}
strip1.show();
}
for (i = 0; i < N_PIXELS; i++)
{
if (i >= Height)
{
strip2.setPixelColor(i, 0, 0, 0);
}
else
{
strip2.setPixelColor(i, 220, 0, 0);
}
strip2.show();
}
}
I feel like I have been looking at this long enough to stop seeing my own mistakes, so a 2nd pair of (qualified) eyes just might do the trick. I cant wait to see if this just takes a small change or if everything collapses. Again thanks for your help and have a great day/night.