What's your favorite function?

Do you have a question on how to do something.
Ask in here.
Post Reply
User avatar
lnevo
Posts: 5422
Joined: Fri Jul 20, 2012 9:42 am

What's your favorite function?

Post by lnevo »

I've heard people refer to controllers as glorified timers, but the RA is so much more than that. Now that I've turned all my customized code into self contained functions, I thought of a nice way for people to share small snippets of code that they've written. A little change from all the how to or eureka DIY projects.

Anyway, share your favorite function, block of code, library call, whatever it is that you love, are happy with, etc. it doesn't even have to be custom or written by you. So if you love ReefAngel.StandardHeater(), let's hear about it!

Here's my contribution. I threw this together to automate my water changes and I'm quite pleased with how self contained and simple it became. It took a few tweaks to get working properly, but was pretty unchanged from the initial concept. If I had the right plumbing, I could make this a continuous gradual change.

Code: Select all

void autoWaterChange() {
  byte wcReady=InternalMemory.read(Mem_B_WaterChange); // Trigger to start
  int wcFillTime=InternalMemory.read_int(Mem_I_WCFillTime); 

  // Start automatic water change here.
  ReefAngel.SingleATOHigh(Extension); // refill from SW bucket
    
  // Find out if we are ready to start
  if(wcReady) 
  {
    wcTimer.SetInterval(wcFillTime); // One bucket at a time
    wcTimer.Start(); 
    InternalMemory.write(Mem_B_WaterChange, 0);
    bitSet(ReefAngel.Relay.RelayMaskOff,ReactorBit); // Start draining
  }
  if(wcTimer.IsTriggered()) 
  {
    bitClear(ReefAngel.Relay.RelayMaskOff,ReactorBit); // Stop draining
  }
}
So, let's see what you got!!
User avatar
DrewPalmer04
Posts: 818
Joined: Tue May 29, 2012 2:12 pm
Location: Christopher, IL

Re: What's your favorite function?

Post by DrewPalmer04 »

I believe I enjoy the simplicity of the PWMParabola and the many uses everyone has found for it. But that's my choice today...tomorrow it could be something else lol.
Out for now...but not over.

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

Re: What's your favorite function?

Post by rimai »

This is what I use on mine.
It allows you to create several screens and move through them using the joystick.
Mine in particular has all the parameter in the screen 0 using the large font.
Screen 1 has the relay statuses and graph.
You can increase the number of screens too, but I just need 2 :)

Code: Select all

#define NumScreens 2
int ScreenID=0;

void DrawCustomMain()
{
  switch (ScreenID)
  {
  case 0:
    {
      //Draw screen 0
      break;
    }
  case 1:
    {
      //Draw screen 1
      break;
    }
  }
  if (ReefAngel.Joystick.IsLeft())
  {
    ReefAngel.ClearScreen(DefaultBGColor);
    ScreenID--;
  }
  if (ReefAngel.Joystick.IsRight())
  {
    ReefAngel.ClearScreen(DefaultBGColor);
    ScreenID++;
  }
  if (ScreenID<0) ScreenID=NumScreens-1;
  if (ScreenID>=NumScreens) ScreenID=0; 
}
Roberto.
User avatar
lnevo
Posts: 5422
Joined: Fri Jul 20, 2012 9:42 am

What's your favorite function?

Post by lnevo »

That's awesome! You just made my day with that one :) I can have my graphs back and much more room for info!!!

Edit: I think we could make a screen class to manage the number of screens and scrolling through... Just a thought :)

Keep sharing people!!
binder
Posts: 2865
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
Contact:

Re: What's your favorite function?

Post by binder »

lnevo wrote: Edit: I think we could make a screen class to manage the number of screens and scrolling through... Just a thought :)
I'm not sure about creating a class for it, BUT I'm sure I can come up with something for the menu generator to allow for multiple screen creation based on that simple code logic. :geek: wouldn't that be nice??
00Warpig00
Posts: 289
Joined: Wed May 16, 2012 9:52 pm

Re: What's your favorite function?

Post by 00Warpig00 »

Couldn't that same concept be used for nested menu's? top menu has say 3 options screen ID 1/2/3 select (2) and have screen ID 2 show you more options with say screen ID's 6/7/8/9 etc. treat the programming portion as one. I'm guessing the hard part comes in with selecting an option from the joystick...

Nick
180G FOWLR
20GH QT#1
29G QT#2

Image
binder
Posts: 2865
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
Contact:

Re: What's your favorite function?

Post by binder »

00Warpig00 wrote:Couldn't that same concept be used for nested menu's? top menu has say 3 options screen ID 1/2/3 select (2) and have screen ID 2 show you more options with say screen ID's 6/7/8/9 etc. treat the programming portion as one. I'm guessing the hard part comes in with selecting an option from the joystick...
The big part of this would be to know which menu has a submenu. Not to mention that each submenu has to have its own skeleton for functions pre-created so you can override them. If you just allow for 1 submenu for each entry item (so there's only 1 level deep). That's a maximum of 90 function skeletons (9 per menu item * 9 items on main menu plus 9 for the main menu) that would have to be added.
I'm not saying it can't be done, it just needs to be looked into further to see if there is a simpler way of doing things. :?
User avatar
lnevo
Posts: 5422
Joined: Fri Jul 20, 2012 9:42 am

What's your favorite function?

Post by lnevo »

Bump! Lets see some cool stuff. Amazing the ideas from just a couple of posts!!! Keep em coming!
User avatar
jsclownfish
Posts: 375
Joined: Mon Oct 24, 2011 7:52 pm
Location: Saint Louis

Re: What's your favorite function?

Post by jsclownfish »

I'm a big fan of the multiple screens! :D

http://forum.reefangel.com/viewtopic.php?f=11&t=923

Jon
User avatar
lnevo
Posts: 5422
Joined: Fri Jul 20, 2012 9:42 am

What's your favorite function?

Post by lnevo »

binder wrote:
00Warpig00 wrote:Couldn't that same concept be used for nested menu's? top menu has say 3 options screen ID 1/2/3 select (2) and have screen ID 2 show you more options with say screen ID's 6/7/8/9 etc. treat the programming portion as one. I'm guessing the hard part comes in with selecting an option from the joystick...
The big part of this would be to know which menu has a submenu. Not to mention that each submenu has to have its own skeleton for functions pre-created so you can override them. If you just allow for 1 submenu for each entry item (so there's only 1 level deep). That's a maximum of 90 function skeletons (9 per menu item * 9 items on main menu plus 9 for the main menu) that would have to be added.
I'm not saying it can't be done, it just needs to be looked into further to see if there is a simpler way of doing things. :?
What Would make things simpler than submenus would be to have additional menu screens...the same as if you do with main screen you could just assign those menu items with more CustomMenu functions...

You could even do it right in the scrolling code

Code: Select all

    if ( Joystick.IsDown() )
    {
        // process DOWN press
        // > allows for selection of last item, >= skips it
        if ( (++SelectedMenuItem) > qty ) 
        {
            // add switch to page 2...

            // we've hit the bottom of the list
            // wrap around to the top of the list

            // maybe take away ability to wrap. 
            SelectedMenuItem = DEFAULT_MENU_ITEM;
        }
        redrawmenu = true;
        menutimeout = now();
    }
Would be nice to have another page of menus..
mls228
Posts: 19
Joined: Thu Mar 21, 2013 6:40 pm

Re: What's your favorite function?

Post by mls228 »

rimai wrote:This is what I use on mine.
It allows you to create several screens and move through them using the joystick.
Mine in particular has all the parameter in the screen 0 using the large font.
Screen 1 has the relay statuses and graph.
You can increase the number of screens too, but I just need 2 :)
First post here, sorry for the newbie question, how would I incorporate this function into my code. I need a little help to get started, then I'll be on my way I'm sure. Thanks everyone.
Here is my current code:

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 <PH.h>
#include <WaterLevel.h>
#include <ReefAngel.h>

////// Place global variable code below here


////// 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 = Port1Bit | Port4Bit | Port6Bit;
    // Ports toggled in Water Change Mode
    ReefAngel.WaterChangePorts = Port4Bit;
    // Ports toggled when Lights On / Off menu entry selected
    ReefAngel.LightsOnPorts = 0;
    // Ports turned off when Overheat temperature exceeded
    ReefAngel.OverheatShutoffPorts = Port2Bit;
    // Use T1 probe as temperature and overheat functions
    ReefAngel.TempProbe = T1_PROBE;
    ReefAngel.OverheatProbe = T1_PROBE;
    // Set the Overheat temperature setting
    InternalMemory.OverheatTemp_write( 820 );


    // Ports that are always on
    ReefAngel.Relay.On( Port1 );

    ////// Place additional initialization code below here
    

    ////// Place additional initialization code above here
}

void loop()
{
    ReefAngel.StandardHeater( Port2,771,781 );
    ReefAngel.StandardLights( Port3,22,0,14,0 );
    ReefAngel.StandardATO( Port4,60 );
    ReefAngel.Wavemaker( Port5,60 );
    ReefAngel.PWM.SetDaylight( PWMSlope(13,0,22,0,15,100,60,15) );
    ReefAngel.PWM.SetActinic( PWMSlope(14,0,21,0,15,100,60,15) );
    ////// Place your custom code below here
    

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

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

rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: What's your favorite function?

Post by rimai »

Are you trying to get several screens in your code?
Roberto.
mls228
Posts: 19
Joined: Thu Mar 21, 2013 6:40 pm

What's your favorite function?

Post by mls228 »

rimai wrote:Are you trying to get several screens in your code?
Yes
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: What's your favorite function?

Post by rimai »

May I suggest you start with with creating just one??
Then when you are familiar with creating the first one, we move to create additional ones?
http://forum.reefangel.com/viewtopic.php?f=14&t=109
Roberto.
Post Reply