Attached is the new layout, I am required to do 2 LED's in series due to lack of resistors, and I might need lower value resistors. I had to do the Blue LED's in parallel pairs to get them to work at the appropriate brightness in series, they barely glowed. They must have a higher resistance/consumption than the other LEDS. The transistors seem to be working as PWM switches, now the code is sort of working, but not yet as responsive as I would like. It is posted below.
// noise reactive sculpture
const int ledPin = 13;
const int middleValue = 512;
const int numberOfSamples = 128;
int count;
int micPower = 12;
int sample;
int brightness;
int whiteBright = 0;
int lastwhite = 0;
long signal;
long averageReading;
long runningAverage=0;
long output = 0;
const int averagedOver= 16;
int y = 0;
const int threshold= 550;
float RGB1[3];
float RGB2[3];
float INC[3];
int red, green, blue, white=0;
int RedPin = 11;
int GreenPin = 10;
int BluePin = 9;
int WhitePin = 6;
void setup()
{
pinMode(ledPin, OUTPUT);
digitalWrite(micPower,HIGH);
Serial.begin(9600);
randomSeed(analogRead(0));
RGB1[0] = 0;
RGB1[1] = 0;
RGB1[2] = 0;
RGB2[0] = random(256);
RGB2[1] = random(256);
RGB2[2] = random(256);
}
void loop()
{
output = 0;
for(count=128; count>0; count--)// take 128 readings per loop to establish a common base line.
{
{
long sumOfSquares = 0;
for (int i=0; i<numberOfSamples; i++)
{
sample = analogRead(4);
signal = (sample - middleValue);
signal *= signal;
sumOfSquares += signal;
}
averageReading = sqrt (sumOfSquares / numberOfSamples);
runningAverage = ((( averagedOver - 1 ) * runningAverage ) + averageReading ) >> 4 ;//running average
output = ((runningAverage)*8);//boost the numbers so the difference is larger, and easier to use
Serial.println(output);
count = (count-1);
}
}
if (output >= 250 && output <= 399)
{
brightness = 200;
whiteBright = 50;
}
if (output >= 400 && output <= 499)
{
brightness = 150;
whiteBright = 100;
}
if (output >= 500 && output <= 599)
{
brightness = 100;
whiteBright = 150;
}
if (output >= 600 && output <= 699)
{
brightness = 50;
whiteBright = 200;
}
if (output >= 700)
{
brightness = 0;
whiteBright = 255;
}
else
{
brightness = 255;
whiteBright = 0;
}
randomSeed(analogRead(0));//nothing hooked to 0 the rest of the code deals with the shifting patterns in the lights.
for (y = lastwhite; y < whiteBright; y++)
{
analogWrite (WhitePin,(256 - y));
delay (10);
}
for (y = lastwhite; y > whiteBright; y--)
{
analogWrite (WhitePin, (256 - y));
delay (10);
}
for (int x=0; x<3; x++)
{
INC[x] = (RGB1[x] - RGB2[x]) / (brightness);
}
for (int x=0; x<(brightness); x++)
{
red = int(255-(RGB1[0]));
green = int(255-(RGB1[1]));
blue = int(255-(RGB1[2]));
analogWrite (RedPin, red);
analogWrite (GreenPin, green);
analogWrite (BluePin, blue);
delay(10);
RGB1[0] -= INC[0];
RGB1[1] -= INC[1];
RGB1[2] -= INC[2];
}
for (int x=0; x<3; x++ )
{
RGB2[x] = random((brightness + 300)-300);
RGB2[x] = constrain(RGB2[x], 0, (brightness - 1));
delay(100);
}
lastwhite = whiteBright;
y = lastwhite;
}