Thanks!
Apologies, I changed my code a bit to debug. This is what I'm using now.
int Led1 = 6;
int Dirs[] = {0, 0, 0};
float Values[] = {1, 1, 1};
int iValues[] = {0, 0, 0};
int Led2 = 10;
int Led3 = 11;
float Random;
float ratio;
void setup(){
Serial.begin(9600); //debugging
pinMode(Led1,OUTPUT);
pinMode(Led2,OUTPUT);
pinMode(Led3,OUTPUT);
randomSeed(analogRead(0));
Values[0] = random(1,1025);
Values[1] = random(1,1025);
Values[2] = random(1,1025);
}
void loop(){
for(int i = 0;i < 3; i++){ //this for statement is meant to cause all values to loop back and forth between 0-255.
Random = random(0.0,1.0);
if(Dirs[i] < 1){
Values[i] = Values[i] + Random;
}
else{
Values[i] = Values[i] - Random;
}
if(Values[i] >= 1025 and Dirs[i] < 1){
Dirs[i] = 1;
Values[i] = 1025; //Fail-safe I want to avoid values outside of the range 0-1024
}
else if(Values[i] <= 1 and Dirs[i] >= 1){
Dirs[i] = 0;
Values[i] = 1; //Fail-safe I want to avoid values outside of the range 0-1024
}
}
delay(200); //I have no sense of time, this might be to fast. That would explain the flickerying anyway.
ratio = 31*3/(Values[0]+Values[1]+Values[2]); //this equation is meant to equalize the numbers, so that the light always outputs the same ammount of power. Equalizes around 31/32 (don't really know which since pwm starts with 0)
iValues[0] = Values[0]*ratio;
iValues[1] = Values[1]*ratio;
iValues[2] = Values[2]*ratio;
analogWrite(Led1,iValues[0]);
analogWrite(Led2,iValues[0]);
analogWrite(Led3,iValues[0]);
Serial.print(iValues[0]);
Serial.print(" ");
Serial.print(iValues[1]);
Serial.print(" ");
Serial.print(iValues[2]);
Serial.print("\n");
}
The above doesn't climb or fall, it just stays the same.
And I did, when I unplug led's it usually stopped. I have had occasions when it still flashes with 2 leds, but once I only have 1 plugged in it stops.