Page 1 of 1

help understanding a line of code in PWM cloud effect PDE

Posted: Fri Jan 06, 2012 3:49 pm
by rufessor
Hi All-

I have the PWM module and am going line by line through the code I post below and I am trying to figure out if I missed the decleration of the variable "day" or if somehow its implicitly implied in the statement I underlined. I am a bit confused what day is referencing in the logic statment on that line... a little help please

perhaps just explain what exactly that is doing. Kinda still getting a grasp on logic in c++ as it uses different text for some comparators than VBasic which I know a bit more about.


// Every day at midnight, we check for chance of cloud happening today
if (hour()==0 && minute()==0 && second()==0) cloudchance=255;

#ifdef forcecloudcalculation
if (cloudchance==255)
#else
if (hour()==0 && minute()==0 && second()==1 && cloudchance==255)
#endif
{
//Pick a random number between 0 and 99
cloudchance=random(100);
// if picked number is greater than Cloud_Chance_per_Day, we will not have clouds today
if (cloudchance>Cloud_Chance_per_Day) cloudchance=0;
// Check if today is day for clouds.
if ((day()%Clouds_Every_X_Days)!=0) cloudchance=0;
// If we have cloud today
if (cloudchance)
{
// pick a random number for number of clouds between Min_Clouds_per_Day and Max_Clouds_per_Day
numclouds=random(Min_Clouds_per_Day,Max_Clouds_per_Day);
// pick the time that the first cloud will start
// the range is calculated between Start_Cloud_After and the even distribuition of clouds on this day.
cloudstart=random(Start_Cloud_After,Start_Cloud_After+((End_Cloud_Before-Start_Cloud_After)/(numclouds*2)));
// pick a random number for the cloud duration of first cloud.
cloudduration=random(Min_Cloud_Duration,Max_Cloud_Duration);
//Pick a random number between 0 and 99
lightningchance=random(100);
// if picked number is greater than Lightning_Change_per_Cloud, we will not have lightning today
if (lightningchance>Lightning_Change_per_Cloud) lightningchance=0;
}
}
// Now that we have all the parameters for the cloud, let's create the effect

Re: help understanding a line of code in PWM cloud effect P

Posted: Fri Jan 06, 2012 4:11 pm
by rimai
day() is define on the time.cpp library.
It returns the day of the month.
% is modulo mathematical formula
http://arduino.cc/en/Reference/Modulo
So, that line basically finds out if today is the day for clouds based on Clouds_Every_X_Days defined within the code.

Re: help understanding a line of code in PWM cloud effect P

Posted: Fri Jan 06, 2012 4:14 pm
by rufessor
rimai wrote:day() is define on the time.cpp library.
It returns the day of the month.
% is modulo mathematical formula
http://arduino.cc/en/Reference/Modulo
So, that line basically finds out if today is the day for clouds based on Clouds_Every_X_Days defined within the code.

That makes sense.... I was looking through the libraries but could not get into them fully on the computer I am on so I kinda wondered if it was something like that. THANKS!

I need to print them out so I can find this stuff... its going to take a WHILE to get all this in my head...

revised plan, no way can I implement anything fancy, I could load code but to modify it I need to get WAY more time with this. Just going to load that PWM program in tonight and try running lights!

I will worry about the rest over time... perhaps a long time!