Moonphase on custom main

Do you have a question on how to do something.
Ask in here.
User avatar
DrewPalmer04
Posts: 818
Joined: Tue May 29, 2012 2:12 pm
Location: Christopher, IL

Re: Moonphase on custom main

Post by DrewPalmer04 »

NO? lol
Out for now...but not over.

VISIT: Ethernet Module/Wifi Alternative
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Moonphase on custom main

Post by rimai »

Roberto.
User avatar
DrewPalmer04
Posts: 818
Joined: Tue May 29, 2012 2:12 pm
Location: Christopher, IL

Re: Moonphase on custom main

Post by DrewPalmer04 »

rimai wrote:Try this function.
Add to end of loop(). If it works, I'll make part of the libraries.

Code: Select all

char* MoonPhaseLabel()
{
  int m,d,y;
  int yy,mm;
  long K1,K2,K3,J;
  double V;
  byte PWMvalue;
  m = month();
  d = day();
  y = year();
  yy = y-((12-m)/10);
  mm = m+9;
  if (mm>=12) mm -= 12;
  K1 = 365.25*(yy+4712);
  K2 = 30.6*mm+.5;
  K3 = int(int((yy/100)+49)*.75)-38;
  J = K1+K2+d+59-K3;
  V = (J-2451550.1)/29.530588853;
  V -= floor(V);
  if (V<0) V++;
  if (V<0.0625) return "New Moon";
  else if (V<0.1875) return "Waxing Crescent";
  else if (V<0.3125) return "First Quarter";
  else if (V<0.4375) return "Waxing Gibbous";
  else if (V<0.5625) return "Fuul Moon";
  else if (V<0.6875) return "Waning Gibbous";
  else if (V<0.8125) return "Last Quarter";
  else if (V<0.9375) return "Waning Crescent";
  else return "New Moon";
}
You can draw on the screen with something like this:

Code: Select all

ReefAngel.LCD.DrawText(0,255,10,10,MoonPhaseLabel());

I get nothing but "not in slope" errors when doing these instructions. What do I need to do to the global.h ?
Out for now...but not over.

VISIT: Ethernet Module/Wifi Alternative
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Moonphase on custom main

Post by rimai »

"not in slope"???
There is no slope in there. Must be something else in your code generating that error.
There's nothing else that needs to be done.
Just put the whole function after the entire loop() section and call it in your custom main section.
Roberto.
User avatar
DrewPalmer04
Posts: 818
Joined: Tue May 29, 2012 2:12 pm
Location: Christopher, IL

Re: Moonphase on custom main

Post by DrewPalmer04 »

Sorry this:

Code: Select all

RA_060912_2037customNEW.cpp: In function 'void loop()':
RA_060912_2037customNEW:205: error: 'd' has not been declared
RA_060912_2037customNEW:205: error: 'y' has not been declared
RA_060912_2037customNEW:205: error: expected `)' before ';' token
RA_060912_2037customNEW:205: error: 'MoonPhaseLabel' declared as function returning a function
RA_060912_2037customNEW:210: error: 'm' was not declared in this scope
RA_060912_2037customNEW:211: error: 'd' was not declared in this scope
RA_060912_2037customNEW:212: error: 'y' was not declared in this scope
RA_060912_2037customNEW:223: error: return-statement with a value, in function returning 'void'
RA_060912_2037customNEW:224: error: return-statement with a value, in function returning 'void'
RA_060912_2037customNEW:225: error: return-statement with a value, in function returning 'void'
RA_060912_2037customNEW:226: error: return-statement with a value, in function returning 'void'
RA_060912_2037customNEW:227: error: return-statement with a value, in function returning 'void'
RA_060912_2037customNEW:228: error: return-statement with a value, in function returning 'void'
RA_060912_2037customNEW:229: error: return-statement with a value, in function returning 'void'
RA_060912_2037customNEW:230: error: return-statement with a value, in function returning 'void'
RA_060912_2037customNEW:231: error: return-statement with a value, in function returning 'void'
RA_060912_2037customNEW:232: error: expected primary-expression before ')' token
RA_060912_2037customNEW:232: error: expected `;' before ')' token
I'm assuming this is calling on the definition of "m" "y" etc etc...but it's not defined?
Out for now...but not over.

VISIT: Ethernet Module/Wifi Alternative
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Moonphase on custom main

Post by rimai »

You need to place after the loop() section and not inside of it.
Roberto.
User avatar
DrewPalmer04
Posts: 818
Joined: Tue May 29, 2012 2:12 pm
Location: Christopher, IL

Re: Moonphase on custom main

Post by DrewPalmer04 »

Oh wow. Sorry I'm still learning. What is the purpose of this? I understand the setup() and loop() but I'm still learning.
Out for now...but not over.

VISIT: Ethernet Module/Wifi Alternative
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Moonphase on custom main

Post by rimai »

setup() is the section that gets run when the controller boots up. It only runs once.
loop() is the section that keeps running over and over again.
http://arduino.cc/en/Tutorial/BareMinimum
Roberto.
User avatar
DrewPalmer04
Posts: 818
Joined: Tue May 29, 2012 2:12 pm
Location: Christopher, IL

Re: Moonphase on custom main

Post by DrewPalmer04 »

The testing has begun!

Image
Out for now...but not over.

VISIT: Ethernet Module/Wifi Alternative
User avatar
jsclownfish
Posts: 375
Joined: Mon Oct 24, 2011 7:52 pm
Location: Saint Louis

Re: Moonphase on custom main

Post by jsclownfish »

I've been using this code for a month or so in my custom main and it seems to work OK.

Code: Select all

// moonphase------------------------------------------------------------   
  YY = (year()) - floor((12 - (month())) / 10); 
  MM = (month()) + 9;
  if (MM >= 12)
  {
    MM = MM - 12;
  }
  K1 = floor(365.25 * (YY + 4712));
  K2 = floor(30.6 * MM + 0.5);
  K3 = floor(floor((YY / 100) + 49) * 0.75) - 38;
  JD = K1 + K2 + (day()) + 59;
  if (JD > 2299160)
  {
    JD = JD - K3;
  }
  IP = (JD - 2451550.1) / 29.530588853;
  IP = IP - floor(IP);
  if (IP < 0)
  {
    IP = IP + 1;
  }
  AG = IP*29.53;
  
  if (AG < 1.84) ReefAngel.LCD.DrawText(DPColor,DefaultBGColor, 5, 43,"New");
  else if (AG < 5.53) ReefAngel.LCD.DrawText(DPColor,DefaultBGColor, 5, 43,"Waxing Crescent");
  else if (AG < 9.92) ReefAngel.LCD.DrawText(DPColor,DefaultBGColor, 5, 43,"First Quarter");
  else if (AG < 12.91) ReefAngel.LCD.DrawText(DPColor,DefaultBGColor, 5, 43,"Waxing Gibbous");   
  else if (AG < 16.61) ReefAngel.LCD.DrawText(DPColor,DefaultBGColor, 5, 43,"Full");    
  else if (AG < 20.30) ReefAngel.LCD.DrawText(DPColor,DefaultBGColor, 5, 43,"Waning gibbous");    
  else if (AG < 23.99) ReefAngel.LCD.DrawText(DPColor,DefaultBGColor, 5, 43,"Last Quarter");    
  else if (AG < 27.68) ReefAngel.LCD.DrawText(DPColor,DefaultBGColor, 5, 43,"Waning Crescent");    
  else  ReefAngel.LCD.DrawText(DPColor,DefaultBGColor, 5, 43,"New") ;  
User avatar
DrewPalmer04
Posts: 818
Joined: Tue May 29, 2012 2:12 pm
Location: Christopher, IL

Re: Moonphase on custom main

Post by DrewPalmer04 »

Better than this one?

Code: Select all

char* MoonPhaseLabel()
{
  int m,d,y;
  int yy,mm;
  long K1,K2,K3,J;
  double V;
  byte PWMvalue;
  m = month();
  d = day();
  y = year();
  yy = y-((12-m)/10);
  mm = m+9;
  if (mm>=12) mm -= 12;
  K1 = 365.25*(yy+4712);
  K2 = 30.6*mm+.5;
  K3 = int(int((yy/100)+49)*.75)-38;
  J = K1+K2+d+59-K3;
  V = (J-2451550.1)/29.530588853;
  V -= floor(V);
  if (V<0) V++;
  if (V<0.0625) return "New Moon";
  else if (V<0.1875) return "Waxing Crescent";
  else if (V<0.3125) return "First Quarter";
  else if (V<0.4375) return "Waxing Gibbous";
  else if (V<0.5625) return "Fuul Moon";
  else if (V<0.6875) return "Waning Gibbous";
  else if (V<0.8125) return "Last Quarter";
  else if (V<0.9375) return "Waning Crescent";
  else return "New Moon";
}
Out for now...but not over.

VISIT: Ethernet Module/Wifi Alternative
User avatar
DrewPalmer04
Posts: 818
Joined: Tue May 29, 2012 2:12 pm
Location: Christopher, IL

Re: Moonphase on custom main

Post by DrewPalmer04 »

This code is working thus far! I'll keep everyone updated.

Code: Select all

char* MoonPhaseLabel()
{
  int m,d,y;
  int yy,mm;
  long K1,K2,K3,J;
  double V;
  byte PWMvalue;
  m = month();
  d = day();
  y = year();
  yy = y-((12-m)/10);
  mm = m+9;
  if (mm>=12) mm -= 12;
  K1 = 365.25*(yy+4712);
  K2 = 30.6*mm+.5;
  K3 = int(int((yy/100)+49)*.75)-38;
  J = K1+K2+d+59-K3;
  V = (J-2451550.1)/29.530588853;
  V -= floor(V);
  if (V<0) V++;
  if (V<0.0625) return "New Moon";
  else if (V<0.1875) return "Waxing Crescent";
  else if (V<0.3125) return "First Quarter";
  else if (V<0.4375) return "Waxing Gibbous";
  else if (V<0.5625) return "Fuul Moon";
  else if (V<0.6875) return "Waning Gibbous";
  else if (V<0.8125) return "Last Quarter";
  else if (V<0.9375) return "Waning Crescent";
  else return "New Moon";
}
[/quote]
Out for now...but not over.

VISIT: Ethernet Module/Wifi Alternative
psyrob
Posts: 242
Joined: Thu Sep 01, 2011 8:44 pm

Re: Moonphase on custom main

Post by psyrob »

any update? How is it working?
Image
User avatar
DrewPalmer04
Posts: 818
Joined: Tue May 29, 2012 2:12 pm
Location: Christopher, IL

Re: Moonphase on custom main

Post by DrewPalmer04 »

Still working great! Three more phases to watch for and after that I'll post back.
Out for now...but not over.

VISIT: Ethernet Module/Wifi Alternative
User avatar
DrewPalmer04
Posts: 818
Joined: Tue May 29, 2012 2:12 pm
Location: Christopher, IL

Re: Moonphase on custom main

Post by DrewPalmer04 »

Still working great. At this point. I'd say it's 100% good to go.
Out for now...but not over.

VISIT: Ethernet Module/Wifi Alternative
psyrob
Posts: 242
Joined: Thu Sep 01, 2011 8:44 pm

Re: Moonphase on custom main

Post by psyrob »

Im having trouble...in the code above, I paste it all after the loop and keep getting an error...Does the line
"char*MoonPhaseLabel" go somewhere else?
Image
User avatar
DrewPalmer04
Posts: 818
Joined: Tue May 29, 2012 2:12 pm
Location: Christopher, IL

Re: Moonphase on custom main

Post by DrewPalmer04 »

You have to make sure it is after the loop() section of the code. I did loop() {Your code here ReefAngel.ShowInterface(); } then the char*MoonPhaseLabel()


So.

Code: Select all

ReefAngel.LCD.DrawText(0,255,20,57,MoonPhaseLabel());
Goes in your custom main...(change location depending on what you have)

Then,

Code: Select all

void loop()
{
    // Specific functions that use Internal Memory values
    ReefAngel.StandardLights( Port1,19,0,6,30 );
    ReefAngel.StandardHeater( Port4,740,770 );
    ReefAngel.StandardLights( Port7,6,0,20,0 );
    ReefAngel.StandardLights( Port8,7,0,19,0 );
    //////// ReefAngel.Wavemaker1(Port5);
    /////// ReefAngel.Wavemaker2(Port6);
    //ReefAngel.PWM.SetActinic( MoonPhase ) Test for Meanwells
    ReefAngel.PWM.SetDaylight( PWMParabola(7,5,19,0,0,85,0) );
    ReefAngel.PWM.SetActinic( PWMParabola(6,5,21,0,0,85,0) );
   
  

    ///if ( ReefAngel.Timer[1].IsTriggered() )
         /// {
          ///  ReefAngel.Timer[1].SetInterval(random(15,35));
          ///  ReefAngel.Timer[1].Start();
           /// ReefAngel.Relay.Toggle(Port5);
          ///  ReefAngel.Relay.Toggle(Port6);
          /// }

    
    ////// Place your custom code below here
    
    if (hour()>=6 && hour()<20)
    analogWrite(lowATOPin,0);
    else
    analogWrite(lowATOPin,(int)MoonPhase()*2.55);
    
    //if ( ReefAngel.DisplayedMenu == DEFAULT_MENU ) //Dosing

   /* 
   Hours between 21 and 5
   minute must be 0 (top of the hour)
   seconds less than 4 (up to 5 seconds)
   */
   if ( ((hour()>=21) || (hour()<=5)) &&
       (minute()==0) && 
       (second()<4) )
   {
      ReefAngel.Relay.On(Port2);
   }
   else 
   {
     ReefAngel.Relay.Off(Port2); //End Dosing
   }



    

    ////// Place your custom code above here
  


    // This should always be the last line
    ReefAngel.ShowInterface();
}

char* MoonPhaseLabel()
{
  int m,d,y;
  int yy,mm;
  long K1,K2,K3,J;
  double V;
  byte PWMvalue;
  m = month();
  d = day();
  y = year();
  yy = y-((12-m)/10);
  mm = m+9;
  if (mm>=12) mm -= 12;
  K1 = 365.25*(yy+4712);
  K2 = 30.6*mm+.5;
  K3 = int(int((yy/100)+49)*.75)-38;
  J = K1+K2+d+59-K3;
  V = (J-2451550.1)/29.530588853;
  V -= floor(V);
  if (V<0) V++;
  if (V<0.0625) return "New Moon Time!";
  else if (V<0.1875) return "Waxing Crescent";
  else if (V<0.3125) return "First Quarter";
  else if (V<0.4375) return "Waxing Gibbous";
  else if (V<0.5625) return "Full Moon Time!";
  else if (V<0.6875) return "Waning Gibbous";
  else if (V<0.8125) return "Last Quarter";
  else if (V<0.9375) return "Waning Crescent";
  else return "New Moon Time!";
}
Out for now...but not over.

VISIT: Ethernet Module/Wifi Alternative
psyrob
Posts: 242
Joined: Thu Sep 01, 2011 8:44 pm

Re: Moonphase on custom main

Post by psyrob »

thanks
Image
User avatar
DrewPalmer04
Posts: 818
Joined: Tue May 29, 2012 2:12 pm
Location: Christopher, IL

Re: Moonphase on custom main

Post by DrewPalmer04 »

Good to go? It's still working great for me!
Out for now...but not over.

VISIT: Ethernet Module/Wifi Alternative
alexwbush
Posts: 327
Joined: Tue Mar 22, 2011 12:45 am
Location: San Diego, CA

Re: Moonphase on custom main

Post by alexwbush »

having some trouble...

here are the errors:

Code: Select all

Globals\Globals.cpp.o: In function `MoonPhaseLabel()':
C:\Users\orbitonit\Documents\Arduino\libraries\Globals/Globals.cpp:135: multiple definition of `MoonPhaseLabel()'
sketch_nov30b.cpp.o:C:\Users\ORBITO~1\AppData\Local\Temp\build6404265574585745318.tmp/sketch_nov30b.cpp:352: first defined here
e:/program files (x86)/reef angel controller/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/bin/ld.exe: Disabling relaxation: it will not work with multiple definitions
User avatar
lnevo
Posts: 5422
Joined: Fri Jul 20, 2012 9:42 am

Moonphase on custom main

Post by lnevo »

It's in the libraries now. You don't need to define it now :)
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Moonphase on custom main

Post by rimai »

Can you post your code?
Says you have two functions with same name.
Roberto.
alexwbush
Posts: 327
Joined: Tue Mar 22, 2011 12:45 am
Location: San Diego, CA

Re: Moonphase on custom main

Post by alexwbush »

it's still a work in progress. I need to clean it up a lot

Code: Select all

#include <ReefAngel_Features.h>
#include <Globals.h>
#include <RA_Wifi.h>
#include <Wire.h>
#include <OneWire.h>
#include <Time.h>
#include <DS1307RTC.h>
#include <InternalEEPROM.h>
#include <RA_NokiaLCD.h>
#include <RA_ATO.h>
#include <RA_Joystick.h>
#include <LED.h>
#include <RA_TempSensor.h>
#include <Relay.h>
#include <RA_PWM.h>
#include <Timer.h>
#include <Memory.h>
#include <InternalEEPROM.h>
#include <RA_Colors.h>
#include <RA_CustomColors.h>
#include <Salinity.h>
#include <RF.h>
#include <IO.h>
#include <ORP.h>
#include <AI.h>
#include <ReefAngel.h>

#include <WaterLevel.h> //Added for water level

// Initialize Buzzer variables
byte buzzer=0;
byte overheatflag=0;
byte atoflag=0;
////// Place global variable code below here

byte topofflevel;

byte starthr = 8; //start hour for radion cycle (0-23)
byte startmin = 0; //start minute for radion cycle (0-59)
byte endhr = 22; //end hour for radion cycle (0-23)
byte endmin = 0; //end min for radion cycle (0-59)
byte intensity = 80; //intensity of radion cycle (0-100)

////// Place global variable code above here

void setup()
{
  // This must be the first line
  ReefAngel.Init();  //Initialize controller
  // Ports toggled in Feeding Mode
  ReefAngel.FeedingModePorts = Port4Bit | Port7Bit | Port8Bit;
  ReefAngel.FeedingModePortsE[0] = 0;
  // Ports toggled in Water Change Mode
  ReefAngel.WaterChangePorts = Port3Bit | Port4Bit | Port5Bit | Port7Bit | Port8Bit;
  ReefAngel.WaterChangePortsE[0] = Port5Bit | Port6Bit;
  // Ports toggled when Lights On / Off menu entry selected
  ReefAngel.LightsOnPorts = Port1Bit | Port2Bit | Port6Bit;
  ReefAngel.LightsOnPortsE[0] = 0;
  // Ports turned off when Overheat temperature exceeded
  ReefAngel.OverheatShutoffPorts = Port1Bit | Port2Bit | Port3Bit | Port7Bit;
  ReefAngel.OverheatShutoffPortsE[0] = 0;
  // Use T1 probe as temperature and overheat functions
  ReefAngel.TempProbe = T1_PROBE;
  ReefAngel.OverheatProbe = T1_PROBE;

  // Ports that are always on
  ReefAngel.Relay.On( Port1 ); //left radion
  ReefAngel.Relay.On( Port2 ); //right radion
  ReefAngel.Relay.On( Port8 ); //return
//  ReefAngel.Relay.On( Box1_Port1 ); //TBD

  ////// Place additional initialization code below here
  InternalMemory.ATOHourInterval_write(0);
  ////// Place additional initialization code above here
}
void loop()
{
  ReefAngel.StandardHeater( Port3 );
  ReefAngel.DosingPumpRepeat1( Box1_Port7 );
  ReefAngel.DosingPumpRepeat2( Box1_Port8 );

  overheatflag = InternalMemory.read( Overheat_Exceed_Flag );
  atoflag = InternalMemory.read( ATO_Exceed_Flag );
  ////// Place your custom code below here
  
   /* Radion custom curve
    For testing:
    ReefAngel.RF.SetChannel( Radion_White, PWMParabola(10,0,21,0,0,75,0) );
    ReefAngel.RF.SetChannel( Radion_RoyalBlue, PWMParabola(8,0,22,0,0,100,0) );
    ReefAngel.RF.SetChannel( Radion_Red, PWMParabola(11,30,21,0,0,20,0) );
    ReefAngel.RF.SetChannel( Radion_Green, PWMParabola(12,0,19,0,0,30,0) );
    ReefAngel.RF.SetChannel( Radion_Blue, PWMParabola(9,0,21,0,0,45,0) );
    ReefAngel.RF.SetChannel( Radion_Intensity, PWMParabola(8,0,22,0,0,100,0) );
    
    ReefAngel.RF.SetChannel( Radion_RoyalBlue, MoonPhase() );
  */

  ReefAngel.RF.UseMemory = false;
    ReefAngel.RF.SetChannel( Radion_White, PWMParabola(starthr+2,startmin,endhr-1,endmin,0,intensity*.75,0) );
    ReefAngel.RF.SetChannel( Radion_Red, PWMParabola(starthr+3,startmin+30,endhr-1,endmin,0,intensity*.2,0) );
    ReefAngel.RF.SetChannel( Radion_Green, PWMParabola(starthr+4,startmin,endhr-3,endmin,0,intensity*.3,0) );
    ReefAngel.RF.SetChannel( Radion_Blue, PWMParabola(starthr+1,startmin,endhr-1,endmin,0,intensity*.45,0) );
        
    /* Radion moon cycle
      Currently controls RoyalBlue.  If normal daylight, run defined parabola based on start and end radion cycle parameters (aka day cycle).  If after hours, run moonlight.
    */
    if ( (hour() < starthr && (minute() < startmin || startmin == 0) ) || (hour() > endhr && minute() > endmin) ) // If time time is before or after normal daylight cycle
    {
      ReefAngel.RF.SetChannel( Radion_RoyalBlue, 100 ); // Run moonphase on RoyalBlue    
      ReefAngel.RF.SetChannel( Radion_Intensity, MoonPhase() );
    }
    else // Or else...
    {
      ReefAngel.RF.SetChannel( Radion_Intensity, PWMParabola(starthr,startmin,endhr,endhr,0,intensity,0) );
      ReefAngel.RF.SetChannel( Radion_RoyalBlue, PWMParabola(starthr,startmin,endhr,endmin,0,intensity,0) ); // Run day cycle parabola
      ReefAngel.Relay.On(Port4); // And turn on the Vortech
    }
      
    if ( second()==0 ) ReefAngel.RF.RadionWrite();

  /* Auto feeding mode starts.  
   Feeder set for 17:30, start feeding mode at 17:25. */
  if ( hour() == 17 && minute() == 25 && second() ==0 ) //if time is 17:25:00
  {
    ReefAngel.FeedingModeStart(); //start feeding mode
  }

  // Run Vortech during day only.  Vortech is on from 09:00-20:00.
  ReefAngel.StandardLights(Port4,9,0,20,0);
  
  // If in water change mode, turn on the light in the cabinet (so I can see!)
  if (ReefAngel.DisplayedMenu==WATERCHANGE_MODE) ReefAngel.Relay.On(Port6);
  
  /* Water level ATO
     Using memory locations:
     Location 258 (ATO Level Min Value)
     Location 259 (ATO Level Max Value)
     
     **NOTE: I am using the memory locations used on the PWM expansion module, so if you
     are using the PWM expansin module, I recommend you use another memory location.
     
     If the current water level is below the ATO Level Min Value, top off until
     you reach ATO Level Max Value, else don't.
     
     Also, if the current water level falls below the measureable amount (0) turn off
     the return and skimmer.
  */
  
  ReefAngel.WaterLevelATO(Port5,30,InternalMemory.read(258),InternalMemory.read(259));

/* Old ATO script  
  if (ReefAngel.WaterLevel.GetLevel()<topofflevel)
  {
     topofflevel=InternalMemory.read(259);
     ReefAngel.Relay.On(Port5);
  }
  else
  {
     topofflevel=InternalMemory.read(258);
     ReefAngel.Relay.Off(Port5);
  }
  */
  
  // If water level equals 0, turn off return relay; else, keep it on  
  if (ReefAngel.WaterLevel.GetLevel()==0)
  {
     ReefAngel.Relay.Off(Port7);
     ReefAngel.Relay.Off(Port8);
  }
  else
  {
     ReefAngel.Relay.On(Port8);
     if (ReefAngel.WaterLevel.GetLevel()<(InternalMemory.read(259)+2) && ReefAngel.WaterLevel.GetLevel()>(InternalMemory.read(259)-10))
       ReefAngel.Relay.DelayedOn( Port7 );
  }
  
  ////// Place your custom code above here
  // This should always be the last line
  ReefAngel.Portal( "alexwbush" );
  ReefAngel.ShowInterface();
}

char* MoonPhaseLabel()
{
  int m,d,y;
  int yy,mm;
  long K1,K2,K3,J;
  double V;
  byte PWMvalue;
  m = month();
  d = day();
  y = year();
  yy = y-((12-m)/10);
  mm = m+9;
  if (mm>=12) mm -= 12;
  K1 = 365.25*(yy+4712);
  K2 = 30.6*mm+.5;
  K3 = int(int((yy/100)+49)*.75)-38;
  J = K1+K2+d+59-K3;
  V = (J-2451550.1)/29.530588853;
  V -= floor(V);
  if (V<0) V++;
  if (V<0.0625) return "New Moon Time!";
  else if (V<0.1875) return "Waxing Crescent";
  else if (V<0.3125) return "First Quarter";
  else if (V<0.4375) return "Waxing Gibbous";
  else if (V<0.5625) return "Full Moon Time!";
  else if (V<0.6875) return "Waning Gibbous";
  else if (V<0.8125) return "Last Quarter";
  else if (V<0.9375) return "Waning Crescent";
  else return "New Moon Time!";
}

void DrawCustomMain()
{
  byte x = 6;
  byte y = 2;
  byte t;
  byte radionchannel=0;
  byte radiontext=0;
  byte radioncolor=0;
  char text[7];

  /* Drawing this:
   
   01/01/12 00:00:00 AM
   ----------------------
   Disp 79.9  pH     8.00
   Sump 79.9  Sal    0.60
   Room 77.7  WL     43
   
   1 2 3 4 5 6 7 8
   1 2 3 4 5 6 7 8
   
   Moon Waning Crescent
   Intensity 88%
   Sunrise   06:15
   Sunset    18:12
  */
   
  /* Colors used in this script:
     DefaultFGColor   - For basic font and line
     DefaultBGColor   - For background color
     PHColor          - For values that may change
     OutletOnBGColor  - For okay water level
     OutletOffBGColor - For low water level
     
     To change colors, modify these values in ReefAngel_CustomColors.h file
  */

  ReefAngel.LCD.DrawDate(6, 2);
  ReefAngel.LCD.Clear(DefaultFGColor, 1, 11, 128, 11);
  pingSerial();

  //ReefAngel.LCD.DrawText(fcolor,bcolor,x,y,"text");

  //Line 1 - Display Temp & pH
  x = 8;
  y = 15;
  ReefAngel.LCD.DrawText(DefaultFGColor,DefaultBGColor,x,y,"Disp");
  x += 30;
  ReefAngel.LCD.DrawSingleMonitor(ReefAngel.Params.Temp[T1_PROBE], PHColor, x, y, 10);
  x = 70; 
  ReefAngel.LCD.DrawText(DefaultFGColor,DefaultBGColor,x,y,"pH");
  x += 30;
  ReefAngel.LCD.DrawSingleMonitor(ReefAngel.Params.PH, PHColor, x, y, 100);

  //Line 2 - Sump & Salinity
  x = 8;
  y += 10; 
  ReefAngel.LCD.DrawText(DefaultFGColor,DefaultBGColor,x,y,"Sump");
  x += 30;
  ReefAngel.LCD.DrawSingleMonitor(ReefAngel.Params.Temp[T2_PROBE], PHColor, x, y, 10);
  x = 70; 
  ReefAngel.LCD.DrawText(DefaultFGColor,DefaultBGColor,x,y,"Sal");
  x += 30;
  ReefAngel.LCD.DrawSingleMonitor(ReefAngel.Params.Salinity, PHColor, x, y, 10);

  //Line 3 - Room
  x = 8;
  y += 10; 
  ReefAngel.LCD.DrawText(DefaultFGColor,DefaultBGColor,x,y,"Room");
  x += 30;
  ReefAngel.LCD.DrawSingleMonitor(ReefAngel.Params.Temp[T3_PROBE], PHColor, x, y, 10);
  x = 70;
  ReefAngel.LCD.DrawText(DefaultFGColor,DefaultBGColor,x,y,"WL");
  x += 30;
  ReefAngel.LCD.DrawSingleMonitor(ReefAngel.WaterLevel.GetLevel(), PHColor, x, y, 1);

  //Lines 4 and 5 - Relays
  x = 12; 
  y += 12;
  // draw main relay
  byte TempRelay = ReefAngel.Relay.RelayData;
  TempRelay &= ReefAngel.Relay.RelayMaskOff;
  TempRelay |= ReefAngel.Relay.RelayMaskOn;
//  ReefAngel.LCD.DrawOutletBox(x, y, TempRelay);
  ReefAngel.LCD.DrawCircleOutletBox(x, y, TempRelay);

  y +=12;
  // Relay Expansion
  TempRelay = ReefAngel.Relay.RelayDataE[0];
  TempRelay &= ReefAngel.Relay.RelayMaskOffE[0];
  TempRelay |= ReefAngel.Relay.RelayMaskOnE[0];
  ReefAngel.LCD.DrawOutletBox(x, y, TempRelay );
  pingSerial();

  //Line 3 - Sunrise
  x = 8;
  y += 18; 
  ReefAngel.LCD.DrawText(DefaultFGColor,DefaultBGColor,x,y,"Sunrise");
  x += 50;
  ReefAngel.LCD.DrawText(PHColor,DefaultBGColor,x,y,starthr);
  if(starthr<10) x-=6;
  x += 12;
  ReefAngel.LCD.DrawText(PHColor,DefaultBGColor,x,y,":");
  x += 5;
  if(startmin<10)
  {
    ReefAngel.LCD.DrawText(PHColor,DefaultBGColor,x,y,"0");
    x+=6;
  }
  ReefAngel.LCD.DrawText(PHColor,DefaultBGColor,x,y,startmin);
  
  //Line 4 - Sunset
  x = 8;
  y += 10; 
  ReefAngel.LCD.DrawText(DefaultFGColor,DefaultBGColor,x,y,"Sunset");
  x += 50;
  ReefAngel.LCD.DrawText(PHColor,DefaultBGColor,x,y,endhr);
  if(endhr<10) x-=6;
  x += 12;
  ReefAngel.LCD.DrawText(PHColor,DefaultBGColor,x,y,":");
  x += 5;
  if(endmin<10)
  {
    ReefAngel.LCD.DrawText(PHColor,DefaultBGColor,x,y,"0");
    x+=6;
  }
  ReefAngel.LCD.DrawText(PHColor,DefaultBGColor,x,y,endmin);
  
  if (second()==0 || second()==30)
  {
    //Draw Radion Coloration
    ReefAngel.LCD.Clear(COLOR_WHITE,0,100,130,130);
    x=0;
    y=120;
    while(radionchannel<=5)
    {
      if(radionchannel==0) radioncolor=255; //white
      if(radionchannel==1) radioncolor=37; //royalblue
      if(radionchannel==2) radioncolor=224; //red
      if(radionchannel==3) radioncolor=28; //green
      if(radionchannel==4) radioncolor=3; //blue
      if(radionchannel==5) radioncolor=252; //yellow(intensity)
    
      y=128-(ReefAngel.RF.GetChannel(radionchannel)*.15);
      ReefAngel.LCD.Clear(radioncolor,x,y,x+21,130);
      radiontext=x+2;
      if(radionchannel==0) ReefAngel.LCD.Clear(COLOR_BLACK,x,y,x+21,y);
      if(ReefAngel.RF.GetChannel(radionchannel)<100)
        radiontext=x+6;  
      if(ReefAngel.RF.GetChannel(radionchannel)<10)
        radiontext=x+8;
      ReefAngel.LCD.DrawText(DefaultFGColor,DefaultBGColor,radiontext,y-8,ReefAngel.RF.GetChannel(radionchannel));
      x+=22;   
      radionchannel+=1; 
    }
  }

  pingSerial();
}
void DrawCustomGraph()
{
}
User avatar
lnevo
Posts: 5422
Joined: Fri Jul 20, 2012 9:42 am

Moonphase on custom main

Post by lnevo »

You don't need the MoonPhaseLabel function. It's in the libraries now. I just checked my code and I'm using that function and do not have it defined. Try taking it out.
Post Reply