Go Down

Topic: Please help with aquarium lights - one more question- solved (Read 1 time) previous topic - next topic

muda

Aug 09, 2011, 10:36 pm Last Edit: Aug 12, 2011, 08:37 pm by muda Reason: 1
Hi all.
Not many days passed, since I discovered arduino's wonders, so still not strong enough  to talk to it.  :smiley-eek-blue:
Hope you guys can help me solve this puzle.
I have variation of popular controler for reef lighting .Originally written by "Christian".  I will demonstrate idea. Not whole sketch , just essentials :

Code: [Select]


int blue = 10;             // blue  LEDs connected to digital pin 10 (pwm)
int white = 11;            // white LEDs connected to digital pin 11 (pwm)


int bluepercent[11] = { 0, 26, 52, 78, 103, 128, 154, 180, 205, 230, 255 };
int whitepercent[11] = { 0, 26, 52, 78, 103, 128, 154, 180, 205, 230, 255 };


 for (int i = 1; i <= 10; i++) // setting ib value for 10% increment. Start with 0% - at given time blue leds fade in from 0 to 255

analogWrite(blue, bluepercent[i]);
lcd.setCursor(13, 1);
lcd.print(i);

 for (int i = 1; i <= 10; i++) // setting i value for 10% increment. Start with 0% - after blues are at 100% , whites start to fade in

analogWrite(white, whitepercent[i]);
lcd.setCursor(18, 1);
lcd.print(i);



As  you see blue lights come in first and fade in following  " bluepercent" schedule. After it finishes , whites start  fading in folowing its own " whitepercent" schedule which is same in my case.

What I want to change , is that I want  both lights fading in  at the same time but different schedules : like


int bluepercent[11] =  { 0, 26, 52, 78, 103, 128, 154, 180, 205, 230, 255, 255, 255, 255, 255 };
int whitepercent[11] = { 0, 0,  0,  0,  0,   26,  52,  78,  103, 128, 154, 180, 205, 230, 255 };

"11" as i understand is not the right number anymore.And  thats all what I understand at the moment $ :smiley-red:
And how to make LCD to show real degree of each  light intensity in this case ?  Better 0 as min  to 10 as max. LCD space is limited  :)

Thanks in advance to anyone, who will bother to help or just read to this word.


 

EinTyp

I can not help you with the fading at the same time and the LCD output.

But the thing with the array I can explain.

Code: [Select]

int bluepercent[11] =  { 0, 26, 52, 78, 103, 128, 154, 180, 205, 230, 255, 255, 255, 255, 255 };
int whitepercent[11] = { 0, 0,  0,  0,  0,   26,  52,  78,  103, 128, 154, 180, 205, 230, 255 };


Dont work anymore since with "int bluepercent[ x ]" you are create an array which can store x values. In your code the amount of those values exceeds 11. For it to work you have to change 11 to 15.

Code: [Select]

int bluepercent[15] =  { 0, 26, 52, 78, 103, 128, 154, 180, 205, 230, 255, 255, 255, 255, 255 };
int whitepercent[15] = { 0, 0,  0,  0,  0,   26,  52,  78,  103, 128, 154, 180, 205, 230, 255 };


I hope someone else with more knowledge can help you out with the rest of your problem.

-EinTyp

muda

Hi,

Thanks for input. That was exactly one thing what I understood by myself 
May be I need to paste more of the sketch  ?

Can anybody explain what is (i). If I can give different names for this like (i) and (f)  , then I can run both at the same time ?

David Pankhurst

#3
Aug 10, 2011, 10:44 am Last Edit: Aug 10, 2011, 10:42 pm by David Pankhurst Reason: 1
You can have them work together by putting them in the same loop:

Code:

Code: [Select]
int bluepercent[] =  { 0, 26, 52, 78, 103, 128, 154, 180, 205, 230, 255, 255, 255, 255, 255 };
int whitepercent[]=  { 0,  0,  0,  0,   0,  26,  52,  78, 103, 128, 154, 180, 205, 230, 255 };

for (int i = 0; i <sizeof(bluepercent)/sizeof(bluepercent[0]); i++)
{
  analogWrite(blue, bluepercent[i]);
  analogWrite(white, whitepercent[i]);
}


Is that what you mean?

The item "sizeof(bluepercent)/sizeof(bluepercent[0])" is a way to indicate your array length without putting a specific value in it - as you add/remove from the bluepercent array, the count will always be correct. As well, 'i' can start counting at 0, not 1.

Also, if you keep them in the same loop the two arrays must have the same number of items - I've formatted them so they line up so it's easier to check visually.

PaulS

OP: Note the { and } around the code to be executed in David's example. Note that they are missing in your code. Your code will loop through all the values in the array, changing the brightness of the LED, and then print to the LCD.

Presumably, you want the LED to stay at that brightness for some period of time. Neither your code nor David's will do that. Both will simply run the array as fast as possible.

Go Up