Here is my code so far. I'd like to get PWM happening with the lights like I say in the code comments. I'm also trying to make a function that lets me set the sync/antisync behavior of my 4 powerheads which face each other across the tank at the front and back and also lets me set what mode they're running in, ReefCrest, NutrientTransport, etc.
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 <Humidity.h>
#include <DCPump.h>
#include <ReefAngel.h>
////// Place global variable code below here
// define default argument of isPercent in function prototype instead of definition, maybe an Arduino bug?
void CustomExpansion(byte id, byte channel, int percentage, boolean isPercent=true);
#define antiSyncMode 0; // pumps on alternate sides alternating in speed
#define syncMode 1; // pumps on alternate sides on at same time and flow meeting in middle
#define gyreMode 2; // pumps on opposite corners on at same time so that flow turns in a circle. Opposite corners on at different times
////// Place global variable code above here
void setup()
{
// This must be the first line
ReefAngel.Init(); //Initialize controller
ReefAngel.Use2014Screen(); // Let's use 2014 Screen
// Ports toggled in Feeding Mode
ReefAngel.FeedingModePorts = Port6Bit;
// Ports toggled in Water Change Mode
ReefAngel.WaterChangePorts = 0;
// Ports toggled when Lights On / Off menu entry selected
ReefAngel.LightsOnPorts = Port3Bit;
// Ports turned off when Overheat temperature exceeded
ReefAngel.OverheatShutoffPorts = Port1Bit;
// Use T1 probe as temperature and overheat functions
ReefAngel.TempProbe = T1_PROBE;
ReefAngel.OverheatProbe = T1_PROBE;
// Set the Overheat temperature setting
InternalMemory.OverheatTemp_write( 830 );
// Feeeding and Water Change mode speed
ReefAngel.DCPump.FeedingSpeed=0;
ReefAngel.DCPump.WaterChangeSpeed=0;
// Ports that are always on
ReefAngel.Relay.On( Port5 );
ReefAngel.Relay.On( Port6 );
////// Place additional initialization code below here
//Custom Port Labels
ReefAngel.CustomLabels[0]="Heater";
ReefAngel.CustomLabels[1]="Skimmer";
ReefAngel.CustomLabels[2]="LEDPower";
ReefAngel.CustomLabels[3]="Fuge Light";
ReefAngel.CustomLabels[4]="Reeflo Return";
ReefAngel.CustomLabels[5]="PowerHeads";
ReefAngel.CustomLabels[6]="Alkdoser";
ReefAngel.CustomLabels[7]="Caldoser";
////// Place additional initialization code above here
}
/*
Want to use one float valve port for skimmate locker
Relay Ports:
1 = Heater
2 = Skimmer
3 = LEDPower
4 = Fuge Light
5 = Reeflo Return
6 = Powerheads, 2xTunze 2xJebao
7 = Alkdoser
8 = CalDoser
DC Pumps:
Actinic: Tunze Left
Daylight: Tunze Right
CustomDimmer: // Want lights with sinusoidal ramp up and down with center at 1pm starting and ending at 7am/7pm
// want Jebaos to operate in conjunction with Tunzes some of the time and opposite some of the time, so sometimes it will be
// pushing water at each other, sometimes it will be turning a gyre back and forth.
0 = Jebao Left
1 = Jebao Right
2 = Violet
3 = Royal Blue
4 = White
5 = Cool Blue
6 = Deep Red
7 = Cyan
8 = PWM fans
*/
void loop()
{
ReefAngel.StandardHeater( Port1,785,790 );
ReefAngel.Relay.DelayedOn( Port2,1 );
ReefAngel.StandardLights( Port3,7,0,19,0 ); // led power
ReefAngel.StandardLights( Port4,15,0,10,0 ); // fuge light
ReefAngel.DosingPumpRepeat( Port7,0,30,50 ); // alk doser
ReefAngel.DosingPumpRepeat( Port8,15,30,50 ); // cal doser
ReefAngel.DCPump.UseMemory = false;
ReefAngel.DCPump.SetMode( NutrientTransport,75,10 );
ReefAngel.DCPump.DaylightChannel = Sync; // Tunze right
ReefAngel.DCPump.ActinicChannel = AntiSync; // Tunze left
////// Place your custom code below here
CustomExpansion(0x41,0,NutrientTransportMode(0,75,500,false),true); // Jebao Left
CustomExpansion(0x41,1,NutrientTransportMode(0,75,500,true),true); // Jebao Right
// Turn off Skimmer if Locker is full
if(ReefAngel.HighATO.IsActive())
{
ReefAngel.Relay.Off(Port2);
}
else
{
ReefAngel.Relay.On(Port2);
}
////// Place your custom code above here
// This should always be the last line
ReefAngel.Portal( "AlanM" );
ReefAngel.ShowInterface();
}
void setPHModes(byte syncModeIn, byte waveModeIn)
{
switch (syncModeIn) {
case antiSyncMode:
ReefAngel.DCPump.DaylightChannel = Sync;
ReefAngel.DCPump.ActinicChannel = AntiSync;
// want to add code here to also set the daylight and actinic ones to the wave function/syncmode I set here
// custom port 0 left should be AntiSync, custom port 1 on right should be Sync and set to same wave function as DC pumps
break;
case syncMode:
ReefAngel.DCPump.DaylightChannel = Sync;
ReefAngel.DCPump.ActinicChannel - Sync;
// want to add code here to also set the daylight and actinic ones to the wave function/syncmode I set here
// custom port 0 on left should be Sync, custom port 1 on right should be Sync and set to same wave function as DC pumps
break;
case gyreMode:
ReefAngel.DCPump.DaylightChannel = Sync;
ReefAngel.DCPump.ActinicChannel - AntiSync;
// want to add code here to also set the daylight and actinic ones to the wave function/syncmode I set here
// custom port 0 on left should be Sync, custom port 1 on right should be AntiSync and set to same wave function as DC pumps
break;
}
}
void CustomExpansion(byte id, byte channel, int percentage, boolean isPercent)
{
Wire.beginTransmission(id);
Wire.write(0);
Wire.write(0xa1);
Wire.endTransmission();
int newdata = 0;
if (isPercent)
{
newdata=(int)(percentage*40.95);
}
else
{
newdata=percentage;
}
Wire.beginTransmission(id);
Wire.write(0x8+(4*channel));
Wire.write(newdata&0xff);
Wire.write(newdata>>8);
Wire.endTransmission();
}