Help with my definitions and modes

Do you have a question on how to do something.
Ask in here.
Post Reply
Smotz
Posts: 412
Joined: Sat Mar 30, 2013 5:02 pm
Location: CT, USA

Help with my definitions and modes

Post by Smotz »

Hey all,

Can someone advise why my modes (feeding, water change, etc) aren't working with my definitions?

Code: Select all

#define Heater Port1
#define Topoff Port2
#define Reactor Port3
#define Skimmer Port4
#define Return Port5
#define Wave Port6
#define UVlight Port7
#define Fugelight Port8

#define HeaterBit  0
#define TopoffBit  1
#define ReactorBit  2
#define SkimmerBit  3
#define ReturnBit  4
#define WaveBit  5
#define  UVlightBit  6
#define FugelightBit  7

////// 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 = TopoffBit | ReactorBit | SkimmerBit | ReturnBit | UVlightBit;
    // Ports toggled in Water Change Mode
   ReefAngel.WaterChangePorts = HeaterBit | TopoffBit | ReactorBit | SkimmerBit | ReturnBit | WaveBit | UVlightBit;
    
    // Ports toggled when Lights On / Off menu entry selected
    ReefAngel.LightsOnPorts = FugelightBit;
    // Ports turned off when Overheat temperature exceeded
   ReefAngel.OverheatShutoffPorts = HeaterBit | TopoffBit | ReactorBit | SkimmerBit | ReturnBit | WaveBit | UVlightBit;
    
binder
Posts: 2871
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
Contact:

Re: Help with my definitions and modes

Post by binder »

Your "BITS" need to be left shifted in order to work. Here's what the code looks like in the Globals.h file.

Code: Select all

// Port bits
#define Port8Bit   1<<7
#define Port7Bit   1<<6
#define Port6Bit   1<<5
#define Port5Bit   1<<4
#define Port4Bit   1<<3
#define Port3Bit   1<<2
#define Port2Bit   1<<1
#define Port1Bit   1<<0
So your code needs to be improved to be this:

Code: Select all

#define FugelightBit   1<<7
#define UVlightBit   1<<6
#define WaveBit   1<<5
#define ReturnBit   1<<4
#define SkimmerBit   1<<3
#define ReactorBit   1<<2
#define TopoffBit   1<<1
#define HeaterBit   1<<0
Using this will make it work properly. You were almost there just missing a small detail.
Smotz
Posts: 412
Joined: Sat Mar 30, 2013 5:02 pm
Location: CT, USA

Re: Help with my definitions and modes

Post by Smotz »

binder wrote:Your "BITS" need to be left shifted in order to work. Here's what the code looks like in the Globals.h file.

Code: Select all

// Port bits
#define Port8Bit   1<<7
#define Port7Bit   1<<6
#define Port6Bit   1<<5
#define Port5Bit   1<<4
#define Port4Bit   1<<3
#define Port3Bit   1<<2
#define Port2Bit   1<<1
#define Port1Bit   1<<0
So your code needs to be improved to be this:

Code: Select all

#define FugelightBit   1<<7
#define UVlightBit   1<<6
#define WaveBit   1<<5
#define ReturnBit   1<<4
#define SkimmerBit   1<<3
#define ReactorBit   1<<2
#define TopoffBit   1<<1
#define HeaterBit   1<<0
Using this will make it work properly. You were almost there just missing a small detail.
Not sure I understand completely. Are you saying that I should just have 1 space after the declaration?
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Help with my definitions and modes

Post by lnevo »

No, the values aren't just 0-7. I think that worked for me for a while because I was using it with the bitRead/bitWrite function which wanted the 0-7 as the argument.

The real values should be 1,2,4,8,16,32,64,128

so 1<<0, 1<<1, 1<<2, 1<<3, 1<<4, 1<<5, 1<<6, 1<<7 represents the bits properly.
Smotz
Posts: 412
Joined: Sat Mar 30, 2013 5:02 pm
Location: CT, USA

Re: Help with my definitions and modes

Post by Smotz »

I see. So I would literally type "1<<0" (without the quotes)
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Help with my definitions and modes

Post by lnevo »

Yep
Smotz
Posts: 412
Joined: Sat Mar 30, 2013 5:02 pm
Location: CT, USA

Re: Help with my definitions and modes

Post by Smotz »

You guys are always the best
binder
Posts: 2871
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
Contact:

Re: Help with my definitions and modes

Post by binder »

Smotz wrote:I see. So I would literally type "1<<0" (without the quotes)
or you could just copy and paste the code i provided for you. ;)
Smotz
Posts: 412
Joined: Sat Mar 30, 2013 5:02 pm
Location: CT, USA

Re: Help with my definitions and modes

Post by Smotz »

binder wrote:
Smotz wrote:I see. So I would literally type "1<<0" (without the quotes)
or you could just copy and paste the code i provided for you. ;)

Thank you - sometimes I am a bit dense :cry:
Smotz
Posts: 412
Joined: Sat Mar 30, 2013 5:02 pm
Location: CT, USA

Re: Help with my definitions and modes

Post by Smotz »

How would I represent the 2nd relay box?

2<<1
2<<2
2<<3

and so on?
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Help with my definitions and modes

Post by lnevo »

Its the same as the first relay box. You'd be addressing a different variable but the bit positions are the same. 0-7 = ports 1-8
Smotz
Posts: 412
Joined: Sat Mar 30, 2013 5:02 pm
Location: CT, USA

Re: Help with my definitions and modes

Post by Smotz »

lnevo wrote:Its the same as the first relay box. You'd be addressing a different variable but the bit positions are the same. 0-7 = ports 1-8

can you be more specific?

Code: Select all

#define Heater Port1
#define Topoff Port2
#define Reactor Port3
#define Skimmer Port4
#define Return Port5
#define Wave Port6
#define UVlight Port7
#define Fugelight Box1_Port8
#define FugelightBit   2<<7
#define UVlightBit   1<<6
#define WaveBit   1<<5
#define ReturnBit   1<<4
#define SkimmerBit   1<<3
#define ReactorBit   1<<2
#define TopoffBit   1<<1
#define HeaterBit   1<<0
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Help with my definitions and modes

Post by rimai »

Just use Box1_Port1 through Box1_Port8
Roberto.
Smotz
Posts: 412
Joined: Sat Mar 30, 2013 5:02 pm
Location: CT, USA

Re: Help with my definitions and modes

Post by Smotz »

rimai wrote:Just use Box1_Port1 through Box1_Port8

can you provide the code to define my FugeLightBit?
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Help with my definitions and modes

Post by rimai »

1<<7
Roberto.
Smotz
Posts: 412
Joined: Sat Mar 30, 2013 5:02 pm
Location: CT, USA

Re: Help with my definitions and modes

Post by Smotz »

rimai wrote:1<<7

Thank you
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Help with my definitions and modes

Post by lnevo »

Smotz wrote:
lnevo wrote:Its the same as the first relay box. You'd be addressing a different variable but the bit positions are the same. 0-7 = ports 1-8

can you be more specific?
Yes, the PortBit variables represent which bit in the RelayData byte and RelayMask byte. Since the bit positions are the same for relay box 1 and relay box 2 etc, the PortXBit is the same for all relay boxes.

ie Port1Bit is 1<<0 meaning we shift the bit 0 positions to represent the first bit.

The position is the same whether we are talking about RelayData or RelayDataE[0]
Smotz
Posts: 412
Joined: Sat Mar 30, 2013 5:02 pm
Location: CT, USA

Re: Help with my definitions and modes

Post by Smotz »

i think i got it. thank you all.
Smotz
Posts: 412
Joined: Sat Mar 30, 2013 5:02 pm
Location: CT, USA

Re: Help with my definitions and modes

Post by Smotz »

This didnt work.

When I set ReefAngel.LightsOnPorts = FugelightBit;
and press "lights on" the device on port 8 of my first relay box is activated (which is my fan).

Please advise..

Code: Select all

[code]////  Port 1			Heater
////  Port 2			ATO pump
////  Port 3			Reactor Pump
////  Port 4			Protien Skimmer
////  Port 5			Return Pump
////  Port 6			Wavemaker
////  Port 7                    UV Sterilizer
////  Port 8                    Fan
////  BOX 1 PORT 8              Fuge Light


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

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

#define Heater Port1
#define Topoff Port2
#define Reactor Port3
#define Skimmer Port4
#define Return Port5
#define Wave Port6
#define UVlight Port7
#define Fan  Port8
#define Fugelight Box1_Port8
#define FugelightBit   1<<7
#define UVlightBit   1<<6
#define WaveBit   1<<5
#define ReturnBit   1<<4
#define SkimmerBit   1<<3
#define ReactorBit   1<<2
#define TopoffBit   1<<1
#define HeaterBit   1<<0

static byte wpMode;
static byte wpWavStr;
static byte wpWavOff;

////// 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 = TopoffBit | ReactorBit | SkimmerBit | ReturnBit | UVlightBit;
  // Ports toggled in Water Change Mode
  ReefAngel.WaterChangePorts = HeaterBit | TopoffBit | ReactorBit | SkimmerBit | ReturnBit | WaveBit | UVlightBit;
  // Ports toggled when Lights On / Off menu entry selected
  ReefAngel.LightsOnPorts = FugelightBit;
  // Ports turned off when Overheat temperature exceeded
  ReefAngel.OverheatShutoffPorts = HeaterBit | TopoffBit | ReactorBit | SkimmerBit | ReturnBit | WaveBit | UVlightBit;

  // Use T1 (SUMP) probe as temperature and overheat functions
  ReefAngel.TempProbe = T1_PROBE;
  ReefAngel.OverheatProbe = T1_PROBE;

  // Ports that are always on
  ReefAngel.Relay.On( Return );
  ReefAngel.Relay.On( Reactor );
  ReefAngel.Relay.On( Wave );
  ReefAngel.Relay.On( Box1_Port1 );
  ReefAngel.Relay.On( Box1_Port2 );
  ReefAngel.Relay.On( Box1_Port3 );
  ReefAngel.Relay.On( Box1_Port4 );
  ReefAngel.Relay.On( Box1_Port5 );
  ReefAngel.Relay.On( Box1_Port6 );
  ReefAngel.Relay.On( Box1_Port7 );

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


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

void loop()
{
  ReefAngel.StandardHeater( Heater );
  ReefAngel.StandardATO( Topoff );
  ReefAngel.MoonLights( Fugelight );
  ReefAngel.StandardFan( Fan );
  ////// Place your custom code below here

  ReefAngel.LCD.DrawText(0,255,20,80,"Joe's Reef Tank");
  ReefAngel.Relay.DelayedOn(Skimmer,2);
  ReefAngel.Relay.DelayedOn(UVlight,1);

  ReefAngel.DCPump.FeedingSpeed=30;
  ReefAngel.DCPump.WaterChangeSpeed=0;
  ReefAngel.DCPump.DaylightChannel = Sync;
  ReefAngel.DCPump.ActinicChannel = Sync;

  //if (ReefAngel.DCPump.Mode==Custom) ReefAngel.DCPump.UseMemory = false;
  //else ReefAngel.DCPump.UseMemory = true; 
  // Custom Wave Routine 
  if (ReefAngel.DCPump.Mode==Custom) {  
    ReefAngel.DCPump.UseMemory = false;

    // set the wpMode
    if ( (hour() >= 5) && (hour() < 8) )   wpMode=1;       // from 5am - 8am
    if ( (hour() >= 8) && (hour() < 11) ) wpMode=2;      // from 8am - 11am
    if ( (hour() >= 11) && (hour() < 14) ) wpMode=3;     // from 11a - 2pm
    if ( (hour() >= 14) && (hour() < 17) ) wpMode=2;     // from 2pm - 5pm
    if ( (hour() >= 17) && (hour() < 20) ) wpMode=1;     // from 5pm - 8pm
    if ( (hour() >= 20) && (hour() < 23) ) wpMode=2;     // from 8pm - 11p
    if ( (hour() >= 23) && (hour() < 2) ) wpMode=3;      // from 11pm - 2am
    if ( (hour() >= 2) && (hour() < 5) ) wpMode=2;       // from 2am - 5am

    if (wpMode=1) wpWavStr=45;
    if (wpMode=2) wpWavStr=50;
    if (wpMode=3) wpWavStr=55;
    //Set the Wave OffSet
    wpWavOff=12;  

    //if (ReefAngel.DisplayedMenu==FEEDING_MODE) ReefAngel.PWM.SetDaylight(30);
    //else 
    ReefAngel.PWM.SetDaylight( ReefCrestMode(wpWavStr,wpWavOff,true) );
    ReefAngel.PWM.SetActinic(wpWavStr);     
  }
  else ReefAngel.DCPump.UseMemory = true;

  // end Custom Wave Routine

    //  Only turn on UV Sterilizer between 11pm and 5am
  if ( (hour() >= 5) && (hour() < 23) )  // from 5a - 11p
    ReefAngel.Relay.Off(UVlight);
  else ReefAngel.Relay.On(UVlight);

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

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

void DrawCustomMain()
{

  // Parameters
#if defined DisplayLEDPWM && ! defined RemoveAllLights
  ReefAngel.LCD.DrawMonitor( 15, 20, ReefAngel.Params,
  ReefAngel.PWM.GetDaylightValue(), ReefAngel.PWM.GetActinicValue() );
#else // defined DisplayLEDPWM && ! defined RemoveAllLights
  ReefAngel.LCD.DrawMonitor( 15, 20, ReefAngel.Params );
#endif // defined DisplayLEDPWM && ! defined RemoveAllLights
  pingSerial();

  // Salinity
  ReefAngel.LCD.DrawText( COLOR_DARKKHAKI,DefaultBGColor,15,66, "SAL:" );
  ReefAngel.LCD.DrawText( COLOR_DARKKHAKI,DefaultBGColor,39,66, ReefAngel.Params.Salinity );
  pingSerial();

  // Main Relay Box
  byte TempRelay = ReefAngel.Relay.RelayData;
  TempRelay &= ReefAngel.Relay.RelayMaskOff;
  TempRelay |= ReefAngel.Relay.RelayMaskOn;
  ReefAngel.LCD.DrawOutletBox( 12, 90, TempRelay );
  pingSerial();

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

  // Date and Time
  ReefAngel.LCD.DrawDate( 6, 122 );
  pingSerial();

  //draw the mode on the screen
  char buf[16];
  if (ReefAngel.DisplayedMenu==FEEDING_MODE) sprintf(buf,"Pumps at %d%%",ReefAngel.DCPump.FeedingSpeed);
  else sprintf(buf,"RC %d%% +/- %d%%",wpWavStr,wpWavOff);
  ReefAngel.LCD.DrawText(0,255,15,52,buf);
}

void DrawCustomGraph()
{
}


[/code]
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Help with my definitions and modes

Post by lnevo »

I'd have to check the code to confirm but try this

ReefAngel.LightsOnPortsE[0] = FugeLightBit;
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Help with my definitions and modes

Post by lnevo »

Yep, confirmed. And this is why the Port8Bit variable is the same because the variable you are assigning it to is different for the other relay box.
Smotz
Posts: 412
Joined: Sat Mar 30, 2013 5:02 pm
Location: CT, USA

Re: Help with my definitions and modes

Post by Smotz »

lnevo wrote:Yep, confirmed. And this is why the Port8Bit variable is the same because the variable you are assigning it to is different for the other relay box.
If I want to address expansion ports do I add E [0] to it?

Sent from my SCH-I605 using Tapatalk 4 Beta
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Help with my definitions and modes

Post by rimai »

Correct :)
And if you have more expansion relay boxes, it would be E[1], E[2] and so on.
Roberto.
Post Reply