Go Down

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

muda

Thanks David ,

Thats exactly what I wanted. I will try it and report back how things are going.

Thanks Paul,

There are other procedures in the code too, that are responsible for fading sped, start time etc. ... I just wanted to be simple here .


muda

#6
Aug 10, 2011, 05:10 pm Last Edit: Aug 10, 2011, 05:14 pm by muda Reason: 1


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.




David,

This value is used to calculate many other parameters. Now it become too complicated as is very masive. For example :

if (((ontime * 60) + photoperiod + whiteramptime + 2*blueramptime + (blueramptime/10*9)) >= daybyminute)

Now i need to use "sizeof(bluepercent)/sizeof(bluepercent[0])"  instead of 10. And "sizeof(bluepercent)/sizeof(bluepercent[0])" -1  instead of 9.

becomes :  if (((ontime * 60) + photoperiod + whiteramptime + 2*blueramptime + (blueramptime/sizeof(bluepercent)/sizeof(bluepercent[0])*sizeof(bluepercent)/sizeof(bluepercent[0])-1)) >= daybyminute)

Seems crazy to me  :smiley-mr-green:  Please advice on this.

Can I do like that:

Int array;
array = sizeof(bluepercent)/sizeof(bluepercent[0]);
if (((ontime * 60) + photoperiod + whiteramptime + 2*blueramptime + (blueramptime/array*(array-1))) >= daybyminute)

PaulS

Quote
Seems crazy to me  Please advice on this.

The compiler doesn't care. If you do, use intermediate variables.

Quote
Can I do like that:

Int array;
array = sizeof(bluepercent)/sizeof(bluepercent[0]);
if (((ontime * 60) + photoperiod + whiteramptime + 2*blueramptime + (blueramptime/array*(array-1))) >= daybyminute)

Will, it should be int, not Int, and array as the name of the variable, when it contains size data, doesn't make sense, but, yes that is the general idea.

David Pankhurst

#8
Aug 10, 2011, 10:41 pm Last Edit: Aug 10, 2011, 10:44 pm by David Pankhurst Reason: 1
It's true - to reuse that value in more than one place is unwieldy, and so you have the right idea:

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 };

int total=sizeof(bluepercent)/sizeof(bluepercent[0]); // <--

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

Now you can use 'total' throughout your code to indicate the number of items - I'd recommend it over 'array', which may be confusing at 4am in the morning when you wonder 'what is THAT variable for'?

One advantage of using total here is that the whole code doesn't need a change every time you do something - as long as total is updated, you're safe.


muda

#9
Aug 11, 2011, 10:26 am Last Edit: Aug 11, 2011, 02:20 pm by muda Reason: 1
Thanks guys,

Now trying to implement . Got bunch of errors, need to deal with them. Can take time for expert like me  :smiley-red:



OK finally fighted all troubles. And you know what - ALL WORKS BRILLIANTLY. Exactly as I wished - big thanks . My brain is boiling, but was worth.

Now would you please assist me integrating light output printing to LCD? Before simply (i) value was printed 1 to 10, as white and blue proceses were separate and had 10 steps each. Now doing same is rather non informative. It would be nicer to display bluepercent and whitepercent  values in as %  (0   to 99 as only two digit space available).
  Now my sketch looks like this:

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

int abc(sizeof(bluepercent)/sizeof(bluepercent[0]));


if (daybyminute >= (ontime*60))
   { if (daybyminute < ((ontime*60) + ramptime))            //if time is in range start fading in
    {
     
      int i;
      for (int i = 0; i < abc; i++)
{
  analogWrite(blue, bluepercent[i]);
  analogWrite(white, whitepercent[i]);

       lcd.setCursor(13, 1);  // for blue LEDs
       lcd.print( here is my problem );                        
       
       
       lcd.setCursor(18, 1);  // for white LEDs
       lcd.print( and here );
       

       int countdown = ((rampup*60)/abc);
       while (countdown>0)
        {
          onesecond();
          countdown--;
        }
       }
     }
    }   





Do you have any ideas ?

Go Up