Pages: [1] 2   Go Down
Author Topic: Please help with aquarium lights - one more question- solved  (Read 1279 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 28
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:

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  smiley

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

  
« Last Edit: August 12, 2011, 01:37:26 pm by muda » Logged

Germany
Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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:
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
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 28
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 ?
Logged

Victoria, BC, Canada
Offline Offline
Full Member
***
Karma: 0
Posts: 222
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You can have them work together by putting them in the same loop:

Code:

Code:
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.
« Last Edit: August 10, 2011, 03:42:17 pm by David Pankhurst » Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 28
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 .

Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 28
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


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)
« Last Edit: August 10, 2011, 10:14:18 am by muda » Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Victoria, BC, Canada
Offline Offline
Full Member
***
Karma: 0
Posts: 222
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

It's true - to reuse that value in more than one place is unwieldy, and so you have the right idea:

Code:
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.

« Last Edit: August 10, 2011, 03:44:11 pm by David Pankhurst » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 28
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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 ?
« Last Edit: August 11, 2011, 07:20:36 am by muda » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 28
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I try to use "bluepercent" and "whitepercent" variables for calculation, but only  get bunch of errors. I understood this is not allowed to use it directly ?
Logged

New Jersey
Offline Offline
Faraday Member
**
Karma: 65
Posts: 3638
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Post your code & errors, it'll be easier to help you with more data.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 28
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
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]));


 
    
      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 (bluepercent/255*100 );                  // this line      
      
      
       lcd.setCursor(18, 1);  // for white LEDs
       lcd.print( whitepercent/255*100 );                   // this linee too
}


both lines get -" error: invalid operands of types 'int [16]' and 'int' to binary 'operator/'"


EDIT:  would it work  better this way  ?  Im not sure if I understand what "i"  stands for :
Code:
 lcd.print( whitepercent [i] /255*100 );
   

« Last Edit: August 12, 2011, 10:29:35 am by muda » Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
      lcd.print (bluepercent/255*100 );                     // this line      
You are trying to pass the whole array to an operation that wants one element of the array.

Quote
EDIT:  would it work  better this way  ?  Im not sure if I understand what "i"  stands for :
Yes. The [ i ] is how you reference the ith element in the array. In this case, the i is the loop index.
Logged

New Jersey
Offline Offline
Faraday Member
**
Karma: 65
Posts: 3638
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

and shouldn't this:
Code:
int abc(sizeof(bluepercent)/sizeof(bluepercent[0]));
be this?
Code:
int abc=(sizeof(bluepercent)/sizeof(bluepercent[0]));
Logged

Pages: [1] 2   Go Up
Jump to: