fooled around with this toady and using the internal memory for me does not work.
my "InternalMemory.read(10)" ALWAYS = 255. Never goes to any other value that I can tell.
I've got the water change code working well and fully tested. I added a bunch of screen draws along the road so the controller tells me what is going on at any moment during the water change. I did notice that my controller stops responding to my wifi mod and any refreshes over the android app to see what is going on during the process with the relay ports IO ports etc. All queries to the controller during water change are met with a XML Parser error. When the mode is finished I need to press the joystick button to return to the main menu and they wifi can communicate again. not a huge problem since I am planning fully attended waterchanges for the indefinite future but it would be cool to still have the wifi mod working during the water change.
I also would like to change my buzzer function to have the buzzer beep/chirp for a quarter of a second every two minutes or so instead of just wailing about constantly. any ideas on how to do this would be welcomed.
here is my current test code in case anyone is interested.
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>
// Initialize Buzzer variables
byte buzzer=0;
byte overheatflag=0;
byte atoflag=0;
byte iochannel0flag=0;
byte iochannel1flag=0;
byte iochannel2flag=0;
byte iochannel3flag=0;
byte iochannel4flag=0;
byte iochannel5flag=0;
////// Place global variable code below here
//*****Begin WC Additions
// Ports associated with ATO Ports
// can be multiple ports
byte ATOPorts = 0;
// skimmer port
byte SkimmerPort = Port4;
// return port
byte ReturnPort = Port3;
// sump drain port
byte SumpDrainPort = Port8;
// SaltWater brute pump
byte SWBrutePort = Port7;
// Timer for countdowns
TimerClass tm;
//*****End WC Additions
////// 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 = 0;
ReefAngel.FeedingModePortsE[0] = 0;
// Ports toggled in Water Change Mode
//*****WC ReefAngel.WaterChangePorts = Port3Bit | Port4Bit;
//*****WC ReefAngel.WaterChangePortsE[0] = 0;
// Ports toggled when Lights On / Off menu entry selected
ReefAngel.LightsOnPorts = 0;
ReefAngel.LightsOnPortsE[0] = Port1Bit | Port2Bit;
// Ports turned off when Overheat temperature exceeded
ReefAngel.OverheatShutoffPorts = Port4Bit | Port5Bit | Port6Bit;
ReefAngel.OverheatShutoffPortsE[0] = 0;
// Use T1 probe as temperature and overheat functions
ReefAngel.TempProbe = T1_PROBE;
ReefAngel.OverheatProbe = T1_PROBE;
// Set the Overheat temperature setting
InternalMemory.OverheatTemp_write( 850 );
// Ports that are always on
ReefAngel.Relay.On( Port3 );
ReefAngel.Relay.On( Box1_Port5 );
ReefAngel.Relay.On( Box1_Port6 );
ReefAngel.Relay.On( Box1_Port7 );
////// Place additional initialization code below here
//*****Begin WC Additions
// ATOPorts = Port1 | Port2; // ports 1 & 2
//*****End WC Additions
ReefAngel.CustomVar[0]=0;
ReefAngel.CustomVar[1]=0;
ReefAngel.CustomVar[2]=0;
ReefAngel.CustomVar[3]=0;
ReefAngel.CustomVar[4]=0;
ReefAngel.CustomVar[5]=0;
ReefAngel.CustomVar[6]=0;
ReefAngel.CustomVar[7]=255;
////// Place additional initialization code above here
}
void loop()
{
ReefAngel.StandardFan( Port1,790,820 );
ReefAngel.StandardATO( Port2,40 );
ReefAngel.Relay.DelayedOn( Port4,1 );
// ReefAngel.WavemakerRandom( Port5,30,100 );
ReefAngel.StandardHeater( Port6,750,760 );
ReefAngel.StandardLights( Box1_Port1,13,0,23,0 );
ReefAngel.StandardLights( Box1_Port2,13,0,23,0 );
ReefAngel.StandardHeater( Box1_Port3,750,760 );
ReefAngel.StandardHeater( Box1_Port4,750,760 );
ReefAngel.PWM.SetChannel( 0, PWMParabola(14,0,23,59,1,100,1) );
ReefAngel.PWM.SetChannel( 1, PWMParabola(14,0,23,59,1,100,1) );
ReefAngel.PWM.SetChannel( 3, PWMSlope(2,0,7,30,0,50,0,0) );
ReefAngel.PWM.SetChannel( 4, PWMSlope(0,0,14,0,0,50,0,0) );
overheatflag = InternalMemory.read( Overheat_Exceed_Flag );
atoflag = InternalMemory.read( ATO_Exceed_Flag );
iochannel0flag = ! ReefAngel.IO.GetChannel( 0 );
iochannel1flag = ! ReefAngel.IO.GetChannel( 1 );
iochannel2flag = ! ReefAngel.IO.GetChannel( 2 );
iochannel3flag = ! ReefAngel.IO.GetChannel( 3 );
iochannel4flag = ! ReefAngel.IO.GetChannel( 4 );
iochannel5flag = ! ReefAngel.IO.GetChannel( 5 );
buzzer = overheatflag + atoflag + iochannel0flag + iochannel1flag + iochannel2flag + iochannel3flag + iochannel4flag + iochannel5flag;
if ( buzzer >= 1 ) buzzer = 40;
ReefAngel.PWM.SetDaylight( buzzer );
ReefAngel.PWM.SetActinic( buzzer );
////// Place your custom code below here
ReefAngel.CustomVar[0]=InternalMemory.read(ATO_Exceed_Flag);
ReefAngel.CustomVar[1]=InternalMemory.read(Overheat_Exceed_Flag);
ReefAngel.CustomVar[2]=InternalMemory.read(10);
ReefAngel.CustomVar[3]=0;
ReefAngel.CustomVar[4]=0;
ReefAngel.CustomVar[5]=0;
ReefAngel.CustomVar[6]=0;
ReefAngel.CustomVar[7]=255;
if ( ReefAngel.CustomVar[0]== 1 )
{
ReefAngel.Relay.RelayMaskOff=~(Port4Bit);
}
//*****Begin WC Additions
// If memory location 10 equals 1
// then we start the automatic water change
// Otherwise we ignore and proceed
if (ReefAngel.DisplayedMenu==WATERCHANGE_MODE)
// if ( InternalMemory.read(10) == 1 )
{
AutoWaterChange();
}
//*****End WC Additions
////// Place your custom code above here
// This should always be the last line
ReefAngel.Portal( "00Warpig00" );
ReefAngel.ShowInterface();
}
//*****Begin WC Additions
void AutoWaterChange()
{
// auto water change mode
//display internal memory location 10 water change mode
// ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 50, " ");
// ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 50, "internal Memory 10");
// ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 60, ReefAngel.CustomVar[2] ); waitForTime(3);
// Display Starting Water Change"
ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, " ");
ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "Starting Water Change"); waitForTime(3);
// Check Saltwater BRUTE for sufficient saltwater on IO Module Port2
if ( isSWBruteEmpty() )
{
ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, " ");
ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "Not Enough Saltwater"); waitForTime(3);
//Abort Water Change if insufficient saltwater
ReefAngel.DisplayedMenu = RETURN_MAIN_MODE;
return;
}
//Display Disabling ATO Pump
ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, " ");
ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "Disabling ATO Pump"); waitForTime(3);
// turn off ATO pump port to prevent ATO from trying to fill a sump being drained intentionally
// ReefAngel.Relay.RelayMaskOff = ~ATOPorts;
ReefAngel.Relay.RelayMaskOff=~(Port2Bit);
//ReefAngel.Relay.Write();
//Display Stopping Skimmer
ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, " ");
ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "Stopping Skimmer"); waitForTime(3);
// turn off the skimmer port
ReefAngel.Relay.Off(SkimmerPort);
ReefAngel.Relay.Write();
//Display Skimmer Draining
ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, " ");
ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "Skimmer Draining"); waitForTime(3);
// wait for 1 minute
waitForTime(60);
//Display Skimmer Done Draining
ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, " ");
ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "Skimmer Done Draining"); waitForTime(3);
//display Stopping Return Pump
ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, " ");
ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "Stopping Return Pump"); waitForTime(3);
//Stop Return Pump
ReefAngel.Relay.Off(ReturnPort);
ReefAngel.Relay.Write();
//Display Draining To Sump
ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, " ");
ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "Draining To Sump"); waitForTime(3);
//display Sump Filling
ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, " ");
ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "Sump Filling"); waitForTime(3);
// wait for IO Mod Port 1 to be active
waitForIOChannel(1);
//display Sump Is Full
ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, " ");
ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "Sump Is Full"); waitForTime(3);
//Display Sump Settling
ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, " ");
ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "Sump Settling"); waitForTime(3);
// wait for sump to settle
waitForTime(30);
ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, " ");
ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "Sump Settled"); waitForTime(3);
// display Draining Sump
ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, " ");
ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "Start Draining Sump"); waitForTime(3);
//turn on sump drain pump
ReefAngel.Relay.On(SumpDrainPort);
ReefAngel.Relay.Write();
//display Sump Draining
ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, " ");
ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "Sump Draining"); waitForTime(3);
// wait for sump empty port active, IO Mod Port 0
waitForIOChannel(0);
ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, " ");
ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "Sump Is Empty"); waitForTime(3);
//display Stopping Sump Draining
ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, " ");
ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "Stopping Sump Drain"); waitForTime(3);
// turn off sump drain
ReefAngel.Relay.Off(SumpDrainPort);
ReefAngel.Relay.Write();
//Display Sump Settling
ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, " ");
ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "Sump Settling"); waitForTime(3);
// wait for sump to settle
waitForTime(30);
//display Sump Settled
ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, " ");
ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "Sump Settled"); waitForTime(3);
//display Starting Saltwater Pump
ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, " ");
ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "Start Saltwater Pump"); waitForTime(3);
//turn on Saltwater Pump
ReefAngel.Relay.On(SWBrutePort);
ReefAngel.Relay.Write();
//display Saltwater Pumping
ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, " ");
ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "Saltwater Pumping"); waitForTime(3);
// wait for sump full float switch active, IO Mod Port 1
waitForIOChannel(1);
//display Stop Saltwater Pump
ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, " ");
ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "Stop Saltwater Pump"); waitForTime(3);
// turn off sw brute pump
ReefAngel.Relay.Off(SWBrutePort);
ReefAngel.Relay.Write();
//diasplay Sump is Full
ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, " ");
ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "Sump Is Full"); waitForTime(3);
//Display Sump Settling
ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, " ");
ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "Sump Settling"); waitForTime(3);
// wait for sump to settle
waitForTime(30);
//display Sump Settled
ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, " ");
ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "Sump Settled"); waitForTime(3);
//display Starting Return Pump
ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, " ");
ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "Starting Return Pump"); waitForTime(3);
// turn on return pump
ReefAngel.Relay.On(ReturnPort);
ReefAngel.Relay.Write();
//display Return Pump Started
ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, " ");
ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "Return Pump Started"); waitForTime(3);
//display Normalizing Waterlevel
ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, " ");
ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "Normalizing Waterlevel"); waitForTime(3);
//waiting 2 minutes for waterlevel to normalize
waitForTime(120);
//display Starting Skimer
ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, " ");
ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "Starting Skimmer"); waitForTime(3);
//turn on skimmer
ReefAngel.Relay.On(SkimmerPort);
ReefAngel.Relay.Write();
//display Normalizing Skimmer
ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, " ");
ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "Normalizing Skimmer"); waitForTime(3);
//wait for 2 minutes for skimmer to normalize
waitForTime(120);
//display Skimmer Normalized
ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, " ");
ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "Skimmer Normalized"); waitForTime(3);
//display Enabling ATO Pump
ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, " ");
ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "Enabling ATO Pump"); waitForTime(3);
//Enable ATO pump
ReefAngel.Relay.RelayMaskOff = B11111111;
ReefAngel.Relay.Write();
//display Water Change Complete
ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, " ");
ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "Water Change Complete"); waitForTime(3);
ReefAngel.DisplayedMenu = RETURN_MAIN_MODE;
}
bool isSWBruteEmpty()
{
// check status of IO Mod Port 2
if ( ! ReefAngel.IO.GetChannel(2) )
return true;
return false;
}
void waitForTime(int seconds)
{
bool done = false;
tm.SetInterval(seconds);
tm.Start();
int t = tm.Trigger - now();
do
{
// wait for specified seconds
if ( (t >= 0) && ! tm.IsTriggered() )
{
// TODO finish countdown on screen
// show countdown on screen
//LCD.Clear(DefaultBGColor,60+(intlength(t)*5),100,100,108);
//LCD.DrawText(DefaultFGColor,DefaultBGColor,60,100,t);
wdt_reset();
delay(200);
}
else
{
done = true;
}
} while ( !done );
return;
}
void waitForIOChannel(byte channel)
{
// TODO complete this function
do
{
wdt_reset();
// display something on screen
delay(200);
// TODO check the IO channel logic
} while ( ReefAngel.IO.GetChannel(channel) );
}
//*****End WC Additions
void DrawCustomMain()
{
int x,y;
char text[10];
// Dimming Expansion
x = 15;
y = 2;
for ( int a=0;a<6;a++ )
{
if ( a>2 ) x = 75;
if ( a==3 ) y = 2;
ReefAngel.LCD.DrawText( COLOR_DARKGOLDENROD,DefaultBGColor,x,y,"Ch :" );
ReefAngel.LCD.DrawText( COLOR_DARKGOLDENROD,DefaultBGColor,x+12,y,a );
ReefAngel.LCD.DrawText( COLOR_DARKGOLDENROD,DefaultBGColor,x+24,y,ReefAngel.PWM.GetChannelValue(a) );
y += 10;
}
pingSerial();
// I/O Expansion
byte bkcolor;
x = 14;
y = 34;
for ( int a=0;a<6;a++ )
{
ReefAngel.LCD.DrawCircleOutline( x+(a*20),y,4,COLOR_MEDIUMORCHID );
if ( ReefAngel.IO.GetChannel(a) ) bkcolor=COLOR_WHITE; else bkcolor=COLOR_GRAY;
ReefAngel.LCD.FillCircle( x+(a*20),y,2,bkcolor );
}
pingSerial();
// Parameters
#if defined DisplayLEDPWM && ! defined RemoveAllLights
ReefAngel.LCD.DrawMonitor( 15, 44, ReefAngel.Params,
ReefAngel.PWM.GetDaylightValue(), ReefAngel.PWM.GetActinicValue() );
#else // defined DisplayLEDPWM && ! defined RemoveAllLights
ReefAngel.LCD.DrawMonitor( 15, 44, ReefAngel.Params );
#endif // defined DisplayLEDPWM && ! defined RemoveAllLights
pingSerial();
// Salinity
ReefAngel.LCD.DrawText( COLOR_DARKKHAKI,DefaultBGColor,15,76, "SAL:" );
ReefAngel.LCD.DrawText( COLOR_DARKKHAKI,DefaultBGColor,39,76, 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, 104, TempRelay );
pingSerial();
// Date and Time
ReefAngel.LCD.DrawDate( 6, 122 );
pingSerial();
}
void DrawCustomGraph()
{
}