Typhon led code cloud

Hi I am new to Arduino, am trying to get this typhon led code working. Coming up with this error message

Arduino: 1.6.5 (Windows 8.1), Board: "Arduino Uno"

typhon-code-cloud.ino: In function 'void CheckCloud()': typhon-code-cloud:59: error: 'NumMins' was not declared in this scope typhon-code-cloud.ino:123:27: note: in expansion of macro 'Start_Cloud_After' typhon-code-cloud:141: error: 'NumMins' was not declared in this scope typhon-code-cloud:147: error: 'NumMins' was not declared in this scope typhon-code-cloud:182: error: 'NumMins' was not declared in this scope typhon-code-cloud.ino: In function 'void Seasons()': typhon-code-cloud:363: error: 'LEDPWM0' was not declared in this scope typhon-code-cloud:363: error: 'PWMSlope' was not declared in this scope typhon-code-cloud:364: error: 'LEDPWM1' was not declared in this scope typhon-code-cloud:365: error: 'LEDPWM2' was not declared in this scope typhon-code-cloud:366: error: 'LEDPWM3' was not declared in this scope Multiple libraries were found for "LiquidCrystal.h"

Used: C:\Users\user\Documents\Arduino\libraries\LiquidCrystal

Not used: C:\Program Files (x86)\Arduino\libraries\LiquidCrystal

'NumMins' was not declared in this scope

Not sure how to fix it. Any help would be good. thanks

jimmy01:
Not sure how to fix it.
Any help would be good.

It is hard to give advice when you have not posted the code that is causing the problem.

And please post your program using the code button </> so it looks like this

…R

Ok that makes sense

tried to add the code keeps saying this over the 9000 allowed characters, will try to split it up

here’s the code

[code]

//LED Variables
long calcSec(long,long);
long calcTime(long,long);
short Ndays;
static byte lightningchance=1;
byte cloudduration=20;
int cloudstart=7;
int rhour = 0, rmin = 0, shour = 0, smin = 0;
byte PWMports[] ={3,5,6,9,10,11};
int ChannelValue[] = {0,0,0,0,0,0};
byte SeasonsVar[]={0,0,0,0,0,0,0,0,0,0,0,0}; // PWM0, sunrisehour, sunriseminute, sunsethour, sunsetminute, cloudstarthout, cloudstartminute, cloudduration,lightningchance, PWM1,PWM2,PWM3
byte cmdnum=255;
byte datanum=255;
boolean ForceCloud=false;
 

 

 
// Random Cloud/Thunderstorm effects function
void CheckCloud()
{
 

  // Change the values below to customize your cloud/storm effect
 
  // Frequency in days based on the day of the month - number 2 means every 2 days, for example (day 2,4,6 etc)
  // For testing purposes, you can use 1 and cause the cloud to occur everyday
#define Clouds_Every_X_Days 1
 
  // Percentage chance of a cloud happening today
  // For testing purposes, you can use 100 and cause the cloud to have 100% chance of happening
#define Cloud_Chance_per_Day 100
 
  // Minimum number of minutes for cloud duration.  Don't use max duration of less than 6
#define Min_Cloud_Duration 6
 
  // Maximum number of minutes for the cloud duration. Don't use max duration of more than 255
#define Max_Cloud_Duration 30
 
  // Minimum number of clouds that can happen per day
#define Min_Clouds_per_Day 2
 
  // Maximum number of clouds that can happen per day
#define Max_Clouds_per_Day 5
 
  // Only start the cloud effect after this setting
  // In this example, start could after 11:30am
#define Start_Cloud_After NumMins(700)
 
  // Always end the cloud effect before this setting
  // In this example, end could before 8:00pm
#define End_Cloud_Before NumMins(1900)
 
  // Percentage chance of a lightning happen for every cloud
  // For testing purposes, you can use 100 and cause the lightning to have 100% chance of happening
#define Lightning_Change_per_Cloud 100
 
  // Channels used by the actinic LEDs on the PWM Expansion module
  // These channels will not be dimmed when the cloud effect is triggered
  // Number is a binary form. B001100 means channel 2 and 3 are used for actinics
#define Actinic_Channels B010110
 
  // Channels used by the daylight LEDs on the PWM Expansion module
  // These channels will be used for the spike when lightning effect is triggered
  // Number is a binary form. B000011 means channel 0 and 1 are used for daylights
#define Daylight_Channels B001001
 
  // Note: Make sure to choose correct values that will work within your PWMSLope settings.
  // For example, in our case, we could have a max of 5 clouds per day and they could last for 50 minutes.
  // Which could mean 250 minutes of clouds. We need to make sure the PWMSlope can accomodate 250 minutes of effects or unforseen 
  // results could happen.
  // Also, make sure that you can fit double those minutes between Start_Cloud_After and End_Cloud_Before.
  // In our example, we have 510 minutes between Start_Cloud_After and End_Cloud_Before, so double the 250 minutes (or 500 minutes) can
  //fit in that 510 minutes window.
  // It's a tight fit, but it did.
 
  //#define printdebug // Uncomment this for debug print on Serial Monitor window
#define forcecloudcalculation // Uncomment this to force the cloud calculation to happen in the boot process. 
 
 
  // Change the values above to customize your cloud/storm effect
 
  // Do not change anything below here
 


  static byte cloudchance=255;
  static byte numclouds=0;
  static byte cloudindex=0;
  static byte lightningstatus=0;
  static int LastNumMins=0;
  // 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
 
  if (ForceCloud)
  {
    ForceCloud=false;
    cloudchance=1;
    cloudduration=10;
    lightningchance=1;
    cloudstart=NumMins(hour(),minute())+1;
  }
 
  if (cloudchance)
  {
    //is it time for cloud yet?
    if (NumMins(hour(),minute())>=cloudstart && NumMins(hour(),minute())<(cloudstart+cloudduration))
    {
      // let's go through all channels to pick which ones will be dimmed
      for (int a=0;a<6;a++)
      {
        if (bitRead(Actinic_Channels,a)==0)
        {
          // this will slope down the channel from the current PWM to 0 within 3minutes.
          // then it will stay at 0 for the duration of the cycle
          // and finally slope up from 0 to PWM value within 3 minutes
          // it is basically an inversed slope
          ChannelValue[a]=ReversePWMSlope(cloudstart,cloudstart+cloudduration,ChannelValue[a],0,180);
        }
      }
      if (lightningchance && (NumMins(hour(),minute())==(cloudstart/*+(cloudduration/2)*/)) && second()<3) 
      {
        int strikes = random(7);
        for (int b=0;b<strikes;b++)
        {
          if (bitRead(Daylight_Channels,b)==1)
          {
            if (random(100)<20) lightningstatus=1; 
            else lightningstatus=0;
            if (lightningstatus) ChannelValue[b]=100; 
            else ChannelValue[b]=0;
            if (b==(random(strikes))) delay(5);
          }
          else
          {
            ChannelValue[b]=20;
          }
        }
      }
    }
 
    if (NumMins(hour(),minute())>(cloudstart+cloudduration))
    {
      cloudindex++;
      if (cloudindex < numclouds)
      {
        cloudstart=random(Start_Cloud_After+(((End_Cloud_Before-Start_Cloud_After)/(numclouds*2))*cloudindex*2),(Start_Cloud_After+(((End_Cloud_Before-Start_Cloud_After)/(numclouds*2))*cloudindex*2))+((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;
      }
    }
  }
}
//End Cloud Function




//Reverse PWM slope from cloud function
byte ReversePWMSlope(long cstart,long cend,byte PWMStart,byte PWMEnd, byte clength)
{
  long n=elapsedSecsToday(now());
  cstart*=60;
  cend*=60;
  if (n<cstart) return PWMStart;
  if (n>=cstart && n<=(cstart+clength)) return map(n,cstart,cstart+clength,PWMStart,PWMEnd);
  if (n>(cstart+clength) && n<(cend-clength)) return PWMEnd;
  if (n>=(cend-clength) && n<=cend) return map(n,cend-clength,cend,PWMEnd,PWMStart);
  if (n>cend) return PWMStart;
}
//End Reverse PWM function

//*

[/code]

and the other half

//Calculate Sunrise/set by date & predefined season & rise/set times
void Seasons()
{
  //Set the hour you want the calculations of rise an set to be based on
  int UserRiseHour = 7;
  int UserSetHour =  17;
 
#define forceseasoncalculation
  static byte ssn , ssnp = 0 , ssnpt ;
  long stime, wstime, vstime, wrtime, rtime, vrtime;
  int wrhour,wrmin,wrsec,wshour,wsmin,wssec,rsec,ssec,vrhour,vrmin,vrsec,vshour,vsmin,vssec;
  int iDiffrise = 0;
  int iDiffset = 0;
  int risediffperday = 0;
  int setdiffperday = 0;
  int totalrise = 0;
  int totalset = 0;
  byte s=0;
  int DaysPerYear;        
 
  //rise and set times set by hour and minute. there are 4 seasons however there are 8 highs & lows in rise and set throughout the year
  //first spot is second half of winter starting jan 1st - DO NOT CHANGE
  int risehour[8]= {
    UserRiseHour+1,UserRiseHour+1,UserRiseHour+1,UserRiseHour,UserRiseHour,UserRiseHour-1,UserRiseHour,UserRiseHour      };/*{
   7,7,7,6,6,5,6,6      };*/
  int riseminute[8]={
    00,30,00,30,00,30,00,30            };
  int sethour[8] = {
    UserSetHour-2,UserSetHour-1,UserSetHour-1,UserSetHour,UserSetHour,UserSetHour,UserSetHour,UserSetHour-1      };/*{
   17,18,18,19,19,19,19,18      };*/
  int setminute[8] = {
    30,00,30,00,00,30,00,00            };
 
/*  //
  if (hour()==0 && minute()==0 && second()==0) ssnp=0;
#ifdef forceseasoncalculation
  if (ssnp==0)
#else
    if (hour()==0 && minute()==0 && second()==1 && ssnp==0)
#endif
    {*/
      //leapyear or not to define DaysPerYear - DO NOT CHANGE
      if (year()%4 == 0 && !(year()%100 == 0 && year()%400 != 0))
      {
        DaysPerYear=366;
      }
      else 
      {
        DaysPerYear = 365;
      }
      //Call Day Number Calc to determin day ie december 31st on a non leap year is day 365 - DO NOT CHANGE
      DayNumber(year(),month(),day());
      //define days between beginning, middle and end of seasons high peaks -  DO NOT CHANGE
      int seasons[9] ={
        0,45,96,135,187,238,283,328,DaysPerYear                                    };
      //define season and array pulling variable - DO NOT CHANGE
      for (s=0; seasons[s] < Ndays; s++) ssn = s+1, ssnpt = s+1, ssnp = s;
      //set loop on array time pulling variable to go back to beginning instead of increasing array size - DO NOT CHANGE
      if (ssn >= 7) ssn = 0;
 
      //differece in seconds between two rise/set array times pulled - DO NOT CHANGE
      long rise1 = calcSec(risehour[ssn],riseminute[ssn]);
      long rise2 = calcSec(risehour[ssnp],riseminute[ssnp]);
      iDiffrise = calcTime(rise1, rise2);
      long set1 = calcSec(sethour[ssn],setminute[ssn]);
      long set2 = calcSec(sethour[ssnp],setminute[ssnp]);
      iDiffset = calcTime(set1,set2);             
 
      //calculate new sunrise/set difference from array value & last group of code - DO NOT CHANGE
      risediffperday = iDiffrise/(seasons[ssnpt]-seasons[ssnp]);
      totalrise = risediffperday*(Ndays - seasons[ssnp]);
      setdiffperday = iDiffset/(seasons[ssnpt]-seasons[ssnp]);
      totalset = setdiffperday*(Ndays - seasons[ssnp]);
 
      //creating time in seconds for main sun rise/set number - DO NOT CHANGE
      rtime=calcSec(risehour[ssnp],riseminute[ssnp]);
      if (ssnp == 0 || ssnp == 2 || ssnp == 4 || ssnp == 6){ 
        rtime += totalrise;
      }
      else {
        rtime -= totalrise;
      }
      stime=calcSec(sethour[ssnp],setminute[ssnp]);
      if (ssnp == 1 || ssnp == 3 || ssnp == 5 || ssnp == 7){ 
        stime -= totalset;
      }
      else {
        stime += totalset;
      }
 
      //These are the off set times, standard rtime and stime are for Royal Blues & Blues
      // DO NOT CHANGE the operators in these equations ie +- 
      // The number is in seconds (1200) change this number to change the offset for each color
       wrtime = rtime + 1800;//w r/stime is for Whites - shorter time span then blues
       wstime = stime - 3600;
       vrtime = rtime - 1800;//v r/stime is for Violets - Longer time then blues
       vstime = stime + 1800;
       
       //turning seconds back to Hours:Minutes:Seconds
       //Blues
       rhour=rtime/3600; 
       rtime=rtime%3600;
       rmin=rtime/60; 
       rtime=rtime%60; 
       rsec=rtime;
       if(rsec > 30) rmin++; 
       shour=stime/3600; 
       stime=stime%3600;
       smin=stime/60; 
       stime=stime%60; 
       ssec=stime;
       if(ssec > 30) smin++;
       //White
       wrhour = wrtime/3600;
       wrtime=wrtime%3600;
       wrmin=wrtime/60;
       wrtime=wrtime%60;
       wrsec=wrtime;
       if(wrsec>30) wrmin++;
       wshour = wstime/3600;
       wstime=wstime%3600;
       wsmin=wstime/60;
       wstime=wstime%60;
       wssec=wstime;
       if(wssec>30) wsmin++;
       //Violet
       vrhour = vrtime/3600;
       vrtime=vrtime%3600;
       vrmin=vrtime/60;
       vrtime=vrtime%60;
       vrsec=vrtime;
       if(vrsec>30) vrmin++;
       vshour = vstime/3600;
       vstime=vstime%3600;
       vsmin=vstime/60;
       vstime=vstime%60;
       vssec=vstime;
       if(vssec>30) vsmin++;
       
       if (rmin==60)rmin=00, rhour+=1;
       if (smin==60)smin=00, shour+=1;
       if (wrmin==60)wrmin=00, wrhour+=1;
       if (wsmin==60)wsmin=00, wshour+=1;
       if (vrmin==60)vrmin=00, vrhour+=1;
       if (vsmin==60)vsmin=00, vshour+=1;
      //This is the PWM Slope for each channel, each channel pulls an array value from above(hour,minute) to use, how you set them is up to you. 
        //Just always use a Rise hour in a Rise spot, always a set hour in a set spot ect ect
      ChannelValue[LEDPWM0]=PWMSlope(wrhour,wrmin,wshour,wsmin,0,2.55*28,120,ChannelValue[LEDPWM0]);
      ChannelValue[LEDPWM1]=PWMSlope(vrhour,vrmin,vshour,vsmin,0,2.55*58,70,ChannelValue[LEDPWM1]);
      ChannelValue[LEDPWM2]=PWMSlope(rhour,rmin,shour,smin,0,2.55*58,90,ChannelValue[LEDPWM2]);
      ChannelValue[LEDPWM3]=PWMSlope(wrhour,wrmin,wshour,wsmin,0,2.55*36,105,ChannelValue[LEDPWM3]);
      //ChannelValue[LEDPWM4]=PWMSlope(vrhour,vrmin,vshour,vsmin,0,2.55*90,45,ChannelValue[LEDPWM4]);
      //ChannelValue[LEDPWM0]=PWMSlope(wrhour,wrmin,wshour,wsmin,0,2.55*85,180,ChannelValue[LEDPWM4]);
}
//End Seasons Calculation
 
//Calculators for Seasons function
long calcSec(long hr, long minu)
{
  long totalseconds;
  totalseconds=(hr*3600)+(minu*60);
  return totalseconds;
}
 
long calcTime(long seconds1, long seconds2)
{
  long timediff=abs(seconds1-seconds2);
  return timediff;
}
 
void DayNumber(unsigned int y, unsigned int m, unsigned int d)
{
  int days[]={
    0,31,59,90,120,151,181,212,243,273,304,334            };    // Number of days at the beginning of the month in a not leap year.
  //Start to calculate the number of day
  if (m==1 || m==2){
    Ndays = days[(m-1)]+d;            //for any type of year, it calculate the number of days for January or february
  }            // Now, try to calculate for the other months
  else if ((y % 4 == 0 && y % 100 != 0) ||  y % 400 == 0){  //those are the conditions to have a leap year
    Ndays = days[(m-1)]+d+1;     // if leap year, calculate in the same way but increasing one day
  }
  else {                 //if not a leap year, calculate in the normal way, such as January or February
    Ndays = days[(m-1)]+d;
  }
} 
//End calculators

When the code is too long you can add the .INO file as an attachment. I am always wary of joining two parts together in case there is an error at the join.

I will await your .INO file.

Of course it would be much better if you could write a short program that illustrates the problem.

...R

Ok will do that when I get on the computer tonight. Not really sure how to write code to make it shorter, it's a code I got of the internet.

Added an attachment of the code

typhon-code-cloud.ino (16.4 KB)

jimmy01: Added an attachment of the code

Thanks. I won't get a chance to look at that before tonight or tomorrow.

...R

that's cool thanks for your help

  if (hour()==0 && minute()==0 && second()==0) cloudchance=255;

So, where ARE hour(), minute(), and second() defined?

      if ((day()%Clouds_Every_X_Days)!=0) cloudchance=0;

So, where IS day() defined?

    if (NumMins(hour(),minute())>=cloudstart && NumMins(hour(),minute())<(cloudstart+cloudduration))

So, where IS NumMins() defined?

Anyone know how I can fix it?

Just realized that I forgot to look at your program on 26th - sorry.

It looks like the attached code is not what generated the errors in your Original Post. There is no NumMins on line 59.

I'm not good at #defines and I wonder if you are missing an underscore before NumMins on lines 51 and 55

Your code has no definition of functions hour() minute() etc and I wonder if you were intended to include some Real Time Clock library.

...R

hey
I’m now getting this error cant work out how to fix it.
Any suggestions?

typhon-code-cloud.ino:103:1: error: expected unqualified-id before ‘if’
typhon-code-cloud.ino:106:3: error: expected unqualified-id before ‘if’
expected unqualified-id before ‘if’

typhon-code-cloud.ino (17.8 KB)

Any suggestions?

Yes. Don't do stupid shit like this:

byte NumMins

//*********************************************************************************************************************************



//*********************************************************************************************************************************
// Random Cloud/Thunderstorm effects function
;

All those useless comments in the middle of the statement are not indicative of the sharpest crayon in the box.

define statements belong at the top of the file, NOT between a function declaration statement and the non-existent open curly brace.

hour(), minute(), etc. are STILL not defined.

jimmy01: hey I'm now getting this error cant work out how to fix it. Any suggestions?

You do not seem to be responding to any of the advice you have already been given.

  • What have you tried?
  • What effect did it have?
  • What have you not tried ?
  • Why not ?

People put in some effort to try to help and it would be nice to get some feedback.

...R

Sorry, I added the libarays at the top and added a rtc witch I think fixed the nummins problem. Thank u for that suggestion robin.

I think I would need to know the RTC library to make sense of your code and I don't have an RTC.

...R