Multicolor light display
so i'm making single multicolored led light display can learn language bit better/and test out new equalization equation made.
anyway, i'm having bit of problem. 2 problems.
first, i'm experiencing bit of flickering, not sure why.
and seems me 1 of colors randomly goes out.(and starts getting brighter again per loop).
here's code:
anyone have ideas i'm doing wrong.
anyway, i'm having bit of problem. 2 problems.
first, i'm experiencing bit of flickering, not sure why.
and seems me 1 of colors randomly goes out.(and starts getting brighter again per loop).
here's code:
code: [select]
int led1 = 3;
int dirs[] = {0, 0, 0};
float values[] = {0, 0, 0};
int led2 = 5;
int led3 = 6;
int random;
float ratio;
void setup(){
serial.begin(9600); //debugging
pinmode(led1,output);
pinmode(led2,output);
pinmode(led3,output);
randomseed(analogread(0));
values[0] = random(0,1025);
values[1] = random(0,1025);
values[2] = random(0,1025);
}
void loop(){
for(int = 0;i < 3; i++){ //this statement meant cause values loop , forth between 0-255.
random = random(1,5);
if(dirs[i] < 1){
values[i] = values[i] + random;
}
else{
values[i] = values[i] - random;
}
if(values[i] >= 1024 , dirs[i] < 1){
dirs[i] = 1;
values[i] = 1024; //fail-safe want avoid values outside of range 0-1024
}
else if(values[i] <= 0 , dirs[i] >= 1){
dirs[i] = 0;
values[i] = 0; //fail-safe want avoid values outside of range 0-1024
}
}
delay(200); //i have no sense of time, might fast. explain flickerying anyway.
ratio = 31*3/(values[0]+values[1]+values[2]); //this equation meant equalize numbers, light outputs same ammount of power. equalizes around 31/32 (don't know since pwm starts 0)
analogwrite(led1,values[0]*ratio);
analogwrite(led2,values[1]*ratio);
analogwrite(led3,values[2]*ratio);
}
anyone have ideas i'm doing wrong.
code: [select]
ratio = 31*3/(values[0]+values[1]+values[2]);
analogwrite(led1,values[0]*ratio);
analogwrite(led2,values[1]*ratio);
analogwrite(led3,values[2]*ratio);
you need rethink this. analogwrite takes values between 0-255. values range between 0-1024 , ratio ranges between 0.03-93.
you have potential divide 0 problem.
Arduino Forum > Using Arduino > Programming Questions > Multicolor light display
arduino
Comments
Post a Comment