I make circuit on Thinkercad and wrote 3 similar code for each circuit.
Circuit 1 is using less pins, but code is less ofitient.
Circuit 3 use more pins but code is more ofitient with speed and memory.
Circuit design 3 update of another way of floating RGB with random function | Tinkercad <-- 3
Circuit design another way of floating RGB colors with random function | Tinkercad <-- 2
Circuit design floating RGB colors with random function | Tinkercad <--1
Problem is that to make fluid change colors with arduino is very dificult, because arduino for that purpouse is very slow.
Imagine to drive rgb display with 16/16 led display. it will be so slow, that flikering of the leds will make You to insane.
And what about 4 RGB leds?
I make that project because I need build fluit color changer. But after build and testing it, I found that arduino pwm is so slow, that when I want swich fast beetwen leds, PWM was not so fast to create diming and fluit colors.
That make me wondering how get more efitiency using arduino and still get what I want.
On this site of thinkercad, I create 3 kinds of circuits and updating code in that way, to see what advantages I will get.
The last circuit use 8 pins, 2 digital pins and 3 PWM, second circuit use 10 pins, 4 digital and 6 PWM.
And first circuit use 7 pins, 4 digital, and 3 PWM.
I find out that to turn each led and each kolor, is taking so much time for other leds, that with setting full brightnes of PWM, leds was shining only at 40% light.
Because each of leds need wait 1/12 time to be turned on.
2 and 3 circuit use idea to turn on 2 leds in this same time, and still be able to have for each RGB led diferent value.
Please check and tell me what You think.
Under I will post code from last newest circuit. This one is the most ofitient of what I was able to create.
const unsigned short ledpin[4] = {12, 8};
const unsigned short RGBpin[6] = {11, 10, 9, 6, 5, 3};
const short cathode_anode = 0;
bool poweron = 0;
bool poweroff = 1; // <-- If comon anode leds, flip 1 to 0
const unsigned short mapmin = 0; // <-- If comon anode leds, flip 0 to 255
const unsigned short mapmax = 255; // <-- If comon anode leds, flip 255 to 0
unsigned short ledrgb[4][6]={};
unsigned short randomrgb[4][6]={};
void setrandom();
void slide();
void printstring();
void setup()
{
Serial.begin(9600); // !! Serial. is slowing down Your program.
delay(1000);
// Pinmode for leds ******************************************
for (short i = 0; i < 2; i++)
{
pinMode( ledpin[i], OUTPUT ); // Initiate as output.
delay(100);
digitalWrite ( ledpin[i], cathode_anode ); // Set pins to turn of leds.
Serial.println(ledpin[i]);
}
// pinmode for colors *****************************************
for (short i = 0; i < 6; i++)
{
pinMode( RGBpin[i], OUTPUT );
delay(100);
analogWrite ( RGBpin[i], cathode_anode );
Serial.println(RGBpin[i]);
}
// initiate array *************************************************************
for ( short i = 0; i < 2; i++)
{
for (short j = 0; j < 6; j++)
{
ledrgb[i][j] = cathode_anode;
}
}
// Initiate array **************************************************************
for ( short i = 0; i < 2; i++)
{
for (short j = 0; j < 6; j++)
{
randomrgb[i][j] = cathode_anode;
}
}
}
void loop()
{
setrandom();
for (short t = 0; t < 255; t++){
leddriver();
slide();
}
}
void leddriver()
{
short k, n, i, j;
for (i = 0; i < 2; i++)
{
digitalWrite(ledpin[i],poweron);
//digitalWrite(ledpin[k=i+2],poweron);
for (j = 0; j < 6; j++)
{
analogWrite(RGBpin[j], ledrgb[i][j]);
//analogWrite(RGBpin[k=j+3], ledrgb[n=i+2][k=j+3]);
delay(1);
}
delay(1);
digitalWrite(ledpin[i], poweroff);
//digitalWrite(ledpin[k=i+2], poweroff);
}
}
void setrandom()
{
for (unsigned short i=0; i < 2; i++)
{
for (unsigned short j=0; j < 6; j++)
{
unsigned short number = random(0, 5);
randomrgb[i][j] = map(number, 0, 4, mapmin, mapmax);
Serial.print(randomrgb[i][j]); Serial.print(" ");
delay(1);
}
Serial.print(" ");
}
Serial.println(" ");
}
void slide()
{
for (unsigned short i = 0; i < 2; i++)
{
for (unsigned short j = 0; j < 6; j++)
{
if ( ledrgb[i][j] < randomrgb[i][j] )
{
ledrgb[i][j] += 1;
}
else if ( ledrgb[i][j] > randomrgb[i][j] )
{
ledrgb[i][j] -= 1;
}
else
{ // do nothing means values are equal to random number
}
}
}
}
void printstring()
{
for (unsigned short i = 0; i < 2; i++)
{
for (unsigned short j = 0; j < 6; j++ )
{
Serial.print( randomrgb[i][j] ); Serial.print(" ");
delay(1);
}
delay(1);
}
Serial.println("");
}