JEBO WP-40

Basic / Standard Reef Angel hardware
Post Reply
Paulturner911
Posts: 288
Joined: Wed Jan 23, 2013 12:36 pm

Re: JEBO WP-40

Post by Paulturner911 »

lnevo wrote:You could leverage the memory locations used by the rf module for the vortechs and use the dropdown on the portal :)
This is what I would like to do. How would I do it? You gave me a quick lesson on Memloc and Values last night. Is it possible to assign different wave patters to specific momlocs and then activate them buy selecting the vortech pattern you would like? If so would you specify your range in your code? I would like to know what the easiest way to find my max power % on the WP40 for my tank. After last night I was thinking MB220,xxx until I feel its too strong. Any other suggestion of how to do this with out constant uploading?
Image
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: JEBO WP-40

Post by lnevo »

So, you would just use the functions InternalMemory.RFMode_read(), InternalMemory.RFSpeed_read(), InternalMemory.RFDuration_read() to get the values you want. Then you can set them from the portal drop down.

You can assign variables to the result of those functions and use that in your wavemaker functions. When you change it on the portal, your function will reflect it. Then you wouldn't need to constantly change your URL and you could use the Vortech memory locations so you get the nice interface..

The location your referring to is the stock locations for the WaveMaker() functions which you can certainly use as well. But you basically have the idea.
Paulturner911
Posts: 288
Joined: Wed Jan 23, 2013 12:36 pm

Re: JEBO WP-40

Post by Paulturner911 »

Im not sure I follow. Good new is I just ordered a 50ft USB extension so I will no longer have to unhook my RA and have my tank offline!! AND my pump just arrived!! WHOOT!!

Im not at all familiar with the modes. I think I would like it to ramp up and down over random periods with the shortest being 90sec.

InternalMemory.RFMode_read(ReefCrestMode)
InternalMemory.RFSpeed_read(50) Im guessing 50 percent is a good place to start for me?
InternalMemory.RFDuration_read(90,900) Im sure there needs to be something that says random. But then again im not sure about much in this post :)

Then call the code with
ReefAngel.PWM.SetDaylight( ReefCrestModeRandom1(90,900) );
??
Image
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: JEBO WP-40

Post by lnevo »

No.

Your going to use the RF- Vortech interface in the portal to set your speed...

Then your going to do something like this.

int mode=InternalMemory.RFMode_read();
int speed=InternalMemory.RFSpeed_read();
int duration=InternalMemory.RFDuration_read();

if (mode=ReefCrest) {
ReefAngel.PWM.SetDaylight( ReefCrestMode(speed,duration) );
} else if (mode=...
...
}

ReefCrest function already produces random output... if you want more randomness you'll need to set a range and do a randomization on the number you are setting your speed at... now when you want to adjust your speed, you can just use the portal and change the speed and implement whatever modes you want. You just tie them to the vortech menu for ease of use.
Paulturner911
Posts: 288
Joined: Wed Jan 23, 2013 12:36 pm

Re: JEBO WP-40

Post by Paulturner911 »

Exactly what I was looking for. Ill have to spend some time messing with it.
Set the portal RF to reefcrest, speed to 50ish, duration 180.
I would need your reef crest code posted on page 7 after the last } in my code inorder to reference the mode?
Then cut and paste the above code in void loop?
What other modes are available?

Thats it?
Trial and error
Image
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

JEBO WP-40

Post by lnevo »

The "duration" for ReefCrestMode mode is used as the speed variable argument...meaning how man percent up or down from the default speed. You don't want 180!!

Yes you'll need the ReefCrestMode function for it to work. There's a thread that Roberto compiled with all the current wave patterns we have. You can setup your function to use any / all. :)

Oh and I forgot the current reef crest function takes sync and anti sync args. Don't use the function on page 7, find the thread with the latest versions..
Paulturner911
Posts: 288
Joined: Wed Jan 23, 2013 12:36 pm

Re: JEBO WP-40

Post by Paulturner911 »

Found it! Cut/Pasted and Labeled all modes and emailed them to myself from work!! Once I set the RF setting with in portal I wont have to change anything in the code?
I adjust the names in both the first 2 lines to reflect the proper mode?

//Reefcrest
if (mode=ReefCrest) {
ReefAngel.PWM.SetDaylight( ReefCrestMode(speed,duration) );
} else if (mode=...
...
}

You guys must get tired of being told how helpful you are! The truth is I would have sold this thing in the first week if you and Roberto werent so helpful! Thanks yet AGAIN!
Image
topjimmy
Posts: 146
Joined: Tue May 08, 2012 8:16 am

Re: JEBO WP-40

Post by topjimmy »

Why not use switch case instead of if else statements? Seems much cleaner.
Image
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

JEBO WP-40

Post by lnevo »

Yes...trying not to confuse him :)
Paulturner911
Posts: 288
Joined: Wed Jan 23, 2013 12:36 pm

Re: JEBO WP-40

Post by Paulturner911 »

lnevo wrote:Yes...trying not to confuse him :)
AND I thank you for that!!
Image
Paulturner911
Posts: 288
Joined: Wed Jan 23, 2013 12:36 pm

Re: JEBO WP-40

Post by Paulturner911 »

topjimmy wrote:Why not use switch case instead of if else statements? Seems much cleaner.
I am grasping the if/else. Could you provide an example of switch case?
Image
topjimmy
Posts: 146
Joined: Tue May 08, 2012 8:16 am

Re: JEBO WP-40

Post by topjimmy »

switch (var) {
case 1:
//do something when var equals 1
break;
case 2:
//do something when var equals 2
break;
default:
// if nothing else matches, do the default
// default is optional
}
Image
Paulturner911
Posts: 288
Joined: Wed Jan 23, 2013 12:36 pm

Re: JEBO WP-40

Post by Paulturner911 »

lol pass! Im just being able to read if/then :)
Image
topjimmy
Posts: 146
Joined: Tue May 08, 2012 8:16 am

Re: JEBO WP-40

Post by topjimmy »

Well really that is all it is.

If case =true do that, else check the next one in line. So if the var = reef mode do what is in that section, if the var is set to tidal do what is in that section.

Much cleaner to read when you are trying to debug then nested if else with all the brackets and such.
Image
Paulturner911
Posts: 288
Joined: Wed Jan 23, 2013 12:36 pm

Re: JEBO WP-40

Post by Paulturner911 »

So, anyone wanna buy a jeabo controller box? :)
I have the pump at 20% right now.

It seems that I have to reboot the controller if I want to change memloc values. Is this always the case?

I haven't put any modes in yet, just figuring where I can go on the high end with the pump to start figuring my duration. Thanks a ton guys!!
Image
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: JEBO WP-40

Post by lnevo »

Post your code, let's see what your doing. You should not have to reboot the controller if the code to read your memory locations is within the loop() function.
Paulturner911
Posts: 288
Joined: Wed Jan 23, 2013 12:36 pm

Re: JEBO WP-40

Post by Paulturner911 »

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


// Ports that are always on

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


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

void loop()
{
ReefAngel.Relay.On( Port1 );
ReefAngel.StandardFan( Port2 );
ReefAngel.ActinicLights( Port3 );
ReefAngel.WavemakerRandom1( Port5,180,900 );
ReefAngel.WavemakerRandom2( Port6,90,900 );
ReefAngel.DayLights( Port7 );
ReefAngel.DayLights( Port8 );
//Moonlight Phase 9pm-10am (CH4-CH5)
if ( (hour() >=10) && (hour() <21) )
ReefAngel.PWM.SetChannel( 4,(0) );
else
ReefAngel.PWM.SetChannel( 4, MoonPhase() );
if ( (hour() >=10) && (hour() <21) )
ReefAngel.PWM.SetChannel( 5,(0) );
else
ReefAngel.PWM.SetChannel( 5, MoonPhase() );
//Pump Delay and Over Flow Protection
if (ReefAngel.HighATO.IsActive())
ReefAngel.Relay.On(Port1);
else
ReefAngel.Relay.Off(Port1);
//ATO Protection
if (ReefAngel.LowATO.IsActive())
ReefAngel.Relay.On(Port4);
else
ReefAngel.Relay.Off(Port4);
//Kalk Dose 20sec @ 8pm-12pm (every 15min)
if (hour() >=20 || hour() < 12)
ReefAngel.Relay.Set(Port4, now()%900<22);
else
ReefAngel.Relay.Off(Port4);
//Feed Mode Delay on Pump
static boolean feeding=false;
static unsigned long feedingstarted = now();
if (ReefAngel.DisplayedMenu==FEEDING_MODE)
{
if (!feeding)
{
feeding=true;
feedingstarted = now();
}
else
{
if (now()-feedingstarted>900)
{
bitSet(ReefAngel.Relay.RelayMaskOff,Port5-1);
bitSet(ReefAngel.Relay.RelayMaskOff,Port6-1);
}
}
}


////// Place your custom code below here


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

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

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();

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

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

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

void DrawCustomGraph()
{
}
Image
Paulturner911
Posts: 288
Joined: Wed Jan 23, 2013 12:36 pm

Re: JEBO WP-40

Post by Paulturner911 »

I will be removing the port5-6 wavemaker functions since I have free relays :)

I will also be posting all of the RF modes in the next few days.

Roberto created this to make my return pump stay off for 15min after my feedmode is complete. I dont see port 1 noted in here and I no longer have port5-6. My WP40 is on my PWMDaylight.
Could you help me fix this?
Image
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: JEBO WP-40

Post by rimai »

So, do we have the first person reporting RA controlling Jebao pump ??? :mrgreen:
Roberto.
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

JEBO WP-40

Post by lnevo »

What memory location are you trying to change that isn't working and you need to reboot?
Paulturner911
Posts: 288
Joined: Wed Jan 23, 2013 12:36 pm

Re: JEBO WP-40

Post by Paulturner911 »

rimai wrote:So, do we have the first person reporting RA controlling Jebao pump ??? :mrgreen:
Roger that!
Only with you guys holding my hand!
Image
Paulturner911
Posts: 288
Joined: Wed Jan 23, 2013 12:36 pm

Re: JEBO WP-40

Post by Paulturner911 »

lnevo wrote:What memory location are you trying to change that isn't working and you need to reboot?
Both 220&221 would not reflect the change last night.
I am currently working with 220 (PWMDaytime). I am now up to 70% its running nice. Im not sure I want to go more :) but ofcourse i will! Yeah, Just pushed it to 100. Its a nice pump! no water on my floor, crazy flow in the tank! Ill prob run it around 50 with a 30ish duration! sweet thing is I should be able to tune it up via the portal (once I tie the modes in) correct? Lee did reefcrest for an example, I think I get what I should do:

Portal-Internal Memory-RF-Tidal Wave/ strength 50/ duration 30
NOW this goes AFTER LAST }

//Tidal Swell
byte TidalSwellMode(byte WaveMaxSpeed, boolean PulseSync)
{
static unsigned long lastwavemillis=millis();
static byte WavePhase=0;
static time_t WaveStart=0;
static byte speed=0;
static byte anti_speed=0;

if (WavePhase==0)
{
WavePhase++;
WaveStart=now();
}
else if (WavePhase==1)
{
if (now()-WaveStart>900) WavePhase++;
speed=(WaveMaxSpeed*sin(radians(map(now()-WaveStart,0,900,0,90))))/10;
speed+=WaveMaxSpeed/2;

anti_speed=(WaveMaxSpeed*2*sin(radians(map(now()-WaveStart,0,900,0,90))))/5;
anti_speed+=WaveMaxSpeed/2;
}
else if (WavePhase==2)
{
if (now()-WaveStart>1800) WavePhase++;
speed=(WaveMaxSpeed*sin(radians(map(now()-WaveStart,900,1800,90,180))))/20;
speed+=WaveMaxSpeed/2;
speed+=WaveMaxSpeed/20;

anti_speed=(WaveMaxSpeed*3*sin(radians(map(now()-WaveStart,900,1800,90,180))))/20;
anti_speed+=WaveMaxSpeed/2;
anti_speed+=WaveMaxSpeed/4;

}
else if (WavePhase==3)
{
if (now()-WaveStart>2700) WavePhase++;
speed=(WaveMaxSpeed*3*sin(radians(map(now()-WaveStart,1800,2700,0,90))))/20;
speed+=WaveMaxSpeed/2;
speed+=WaveMaxSpeed/20;

anti_speed=(WaveMaxSpeed*sin(radians(map(now()-WaveStart,1800,2700,0,90))))/20;
anti_speed+=WaveMaxSpeed/2;
anti_speed+=WaveMaxSpeed/4;
}
else if (WavePhase==4)
{
if (now()-WaveStart>3600) WavePhase++;
speed=(WaveMaxSpeed*sin(radians(map(now()-WaveStart,2700,3600,90,180))))/20;
speed+=WaveMaxSpeed/2;
speed+=(WaveMaxSpeed*3)/20;

anti_speed=(WaveMaxSpeed*3*sin(radians(map(now()-WaveStart,2700,3600,90,180))))/20;
anti_speed+=WaveMaxSpeed/2;
anti_speed+=(WaveMaxSpeed*3)/20;
}
else if (WavePhase==5)
{
if (now()-WaveStart>4500) WavePhase++;
speed=(WaveMaxSpeed*3*sin(radians(map(now()-WaveStart,3600,4500,0,90))))/20;
speed+=WaveMaxSpeed/2;
speed+=(WaveMaxSpeed*3)/20;

anti_speed=(WaveMaxSpeed*sin(radians(map(now()-WaveStart,3600,4500,0,90))))/20;
anti_speed+=WaveMaxSpeed/2;
anti_speed+=(WaveMaxSpeed*3)/20;
}
else if (WavePhase==6)
{
if (now()-WaveStart>5400) WavePhase++;
speed=(WaveMaxSpeed*sin(radians(map(now()-WaveStart,4500,5400,90,180))))/20;
speed+=WaveMaxSpeed/2;
speed+=(WaveMaxSpeed*5)/20;

anti_speed=(WaveMaxSpeed*3*sin(radians(map(now()-WaveStart,4500,5400,90,180))))/20;
anti_speed+=WaveMaxSpeed/2;
anti_speed+=WaveMaxSpeed/20;
}
else if (WavePhase==7)
{
if (now()-WaveStart>6300) WavePhase++;
speed=(WaveMaxSpeed*3*sin(radians(map(now()-WaveStart,5400,6300,0,90))))/20;
speed+=WaveMaxSpeed/2;
speed+=(WaveMaxSpeed*5)/20;

anti_speed=(WaveMaxSpeed*sin(radians(map(now()-WaveStart,5400,6300,0,90))))/20;
anti_speed+=WaveMaxSpeed/2;
anti_speed+=WaveMaxSpeed/20;
}
else if (WavePhase==8)
{
if (now()-WaveStart>7200) WavePhase++;
speed=(WaveMaxSpeed*sin(radians(map(now()-WaveStart,6300,7200,90,180))))/20;
speed+=WaveMaxSpeed/2;
speed+=(WaveMaxSpeed*7)/20;

anti_speed=(WaveMaxSpeed*sin(radians(map(now()-WaveStart,6300,7200,90,180))))/10;
anti_speed+=WaveMaxSpeed/2;
}
else if (WavePhase==9)
{
if (now()-WaveStart>8100) WavePhase++;
speed=(WaveMaxSpeed*3*sin(radians(map(now()-WaveStart,7200,8100,0,90))))/20;
speed+=WaveMaxSpeed/2;
speed+=(WaveMaxSpeed*7)/20;

anti_speed=(WaveMaxSpeed*sin(radians(map(now()-WaveStart,7200,8100,0,90))))/2;
anti_speed+=WaveMaxSpeed/2;
}
else if (WavePhase==10)
{
if (now()-WaveStart>9000) WavePhase=0;
speed=(WaveMaxSpeed*sin(radians(map(now()-WaveStart,8100,9000,90,180))))/2;
speed+=WaveMaxSpeed/2;

anti_speed=speed;
}

if (PulseSync)
return speed;
else
return anti_speed;
}


THEN THIS GOES IN VOID LOOP
//Tidal Swell
int mode=InternalMemory.RFMode_read();
int speed=InternalMemory.RFSpeed_read();
int duration=InternalMemory.RFDuration_read();

if (mode=Tidal Swell) {
ReefAngel.PWM.SetDaylight( TidalSwellMode(speed,duration) );
} else if (mode=...
...
}

Is that remotely close???
Image
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: JEBO WP-40

Post by rimai »

If you don't code the ap/dp channels to pull settings from the memory, it will only change on reboot because it reads those memory settings as default settings.
That's why you have to reboot the controller everytime.
Add this to your loop():

Code: Select all

ReefAngel.PWM.SetActinic(InternalMemory.LEDPWMActinic_read());
ReefAngel.PWM.SetDaylight(InternalMemory.LEDPWMDaylight_read());
Roberto.
Piper
Posts: 296
Joined: Fri Jul 20, 2012 7:13 am
Location: Oakley, CA

Re: JEBO WP-40

Post by Piper »

rimai wrote:So, do we have the first person reporting RA controlling Jebao pump ??? :mrgreen:
#2 here! Have it running opposite my MP-10 with both pumps using the wave patters from the other thread.

~Charlie
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: JEBO WP-40

Post by rimai »

Cool!!
Are those functions working as intended???
I already added them to the libraries, but wanted to confirm they are working before I release.
Roberto.
Paulturner911
Posts: 288
Joined: Wed Jan 23, 2013 12:36 pm

Re: JEBO WP-40

Post by Paulturner911 »

Got it! Ive added it to my code Im compiling for the next upload.

Can anyone confirm if my "guess" on how to code the RF/Portal was going to work as intended? I dont want to do all 7 and find that Im COMPLETELY wrong :)
Image
Piper
Posts: 296
Joined: Fri Jul 20, 2012 7:13 am
Location: Oakley, CA

Re: JEBO WP-40

Post by Piper »

rimai wrote:Cool!!
Are those functions working as intended???
I already added them to the libraries, but wanted to confirm they are working before I release.
So far, yes. I was saving the output for each pump in a customer var for the last 4 or 5 days now. I got some weird numbers at first (130% - 550%) but I think it had to do with the way I was assigning the variables. I made a couple of changes and it seems to have a normal output now.

I plan on getting it to work utilizing internal memory this weekend so I can adjust it form one of the various apps. (Although, maybe using the Vortech modes like Lee suggested would work better. Hadn't though about it like that.) I'll take a closer look at all the various patterns this weekend after I do that.

~Charlie
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

JEBO WP-40

Post by lnevo »

Paulturner911 wrote:Got it! Ive added it to my code Im compiling for the next upload.

Can anyone confirm if my "guess" on how to code the RF/Portal was going to work as intended? I dont want to do all 7 and find that Im COMPLETELY wrong :)
You are close. But you will need to use numerical values for mode or the defined nickname in Globals.h. Also, i would pass duration%2 which would change whatever duration is set to either 0/1 for even/odd numbers since the second arg in Tidal Swell is a boolean.

But looks like you have the idea.
Paulturner911
Posts: 288
Joined: Wed Jan 23, 2013 12:36 pm

Re: JEBO WP-40

Post by Paulturner911 »

lnevo wrote:
Paulturner911 wrote:Got it! Ive added it to my code Im compiling for the next upload.

Can anyone confirm if my "guess" on how to code the RF/Portal was going to work as intended? I dont want to do all 7 and find that Im COMPLETELY wrong :)
You are close. But you will need to use numerical values for mode or the defined nickname in Globals.h. Also, i would pass duration%2 which would change whatever duration is set to either 0/1 for even/odd numbers since the second arg in Tidal Swell is a boolean.

But looks like you have the idea.
I dont.... All I do is ask, ask and ask again. Could you modify the code I posted to be correct so that I could then take the changes and make them to the other codes?
Also do I add this to feedmode toggles | LEDPWMDaylight |?? its not blue so its not right

Thanks, Im just trying to get this dialed in before POKER NIGHT!!
Image
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: JEBO WP-40

Post by lnevo »

Here you go.

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


// Ports that are always on

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


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

void loop()
{
ReefAngel.Relay.On( Port1 );
ReefAngel.StandardFan( Port2 );
ReefAngel.ActinicLights( Port3 );
ReefAngel.WavemakerRandom1( Port5,180,900 );
ReefAngel.WavemakerRandom2( Port6,90,900 );
ReefAngel.DayLights( Port7 );
ReefAngel.DayLights( Port8 );
//Moonlight Phase 9pm-10am (CH4-CH5)
if ( (hour() >=10) && (hour() <21) )
ReefAngel.PWM.SetChannel( 4,(0) );
else
ReefAngel.PWM.SetChannel( 4, MoonPhase() );
if ( (hour() >=10) && (hour() <21) )
ReefAngel.PWM.SetChannel( 5,(0) );
else
ReefAngel.PWM.SetChannel( 5, MoonPhase() );
//Pump Delay and Over Flow Protection
if (ReefAngel.HighATO.IsActive())
ReefAngel.Relay.On(Port1);
else
ReefAngel.Relay.Off(Port1);
//ATO Protection
if (ReefAngel.LowATO.IsActive())
ReefAngel.Relay.On(Port4);
else
ReefAngel.Relay.Off(Port4);
//Kalk Dose 20sec @ 8pm-12pm (every 15min)
if (hour() >=20 || hour() < 12)
ReefAngel.Relay.Set(Port4, now()%900<22);
else
ReefAngel.Relay.Off(Port4);
//Feed Mode Delay on Pump
static boolean feeding=false;
static unsigned long feedingstarted = now();
if (ReefAngel.DisplayedMenu==FEEDING_MODE)
{
if (!feeding)
{
feeding=true;
feedingstarted = now();
}
else
{
if (now()-feedingstarted>900)
{
bitSet(ReefAngel.Relay.RelayMaskOff,Port5-1);
bitSet(ReefAngel.Relay.RelayMaskOff,Port6-1);
}
}
}


////// Place your custom code below here

/* Reference for possible modes...

#define Constant      0
#define Lagoon            1
#define Random1       1 // Lagoonal
#define ReefCrest         2
#define Random2       2 // Reef Crest
#define ShortPulse        3
#define ShortWave     3
#define LongPulse         4
#define LongWave      4
#define NutrientTransport       5
#define Smart_NTM     5 // Nutrient Transport Mode
#define TidalSwell        6
#define Smart_TSM     6 // Tidal Swell Mode

*/
// Read memory for RF Wave Settings
int mode=InternalMemory.RFMode_read();
int speed=InternalMemory.RFSpeed_read();
int duration=InternalMemory.RFDuration_read();

if (mode=TidalSwell) {
ReefAngel.PWM.SetDaylight( TidalSwellMode(speed,duration%2) );
} else {
ReefAngel.PWM.SetDaylight( speed / 2 );
}

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

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

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();

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

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

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

void DrawCustomGraph()
{
}

//Tidal Swell
byte TidalSwellMode(byte WaveMaxSpeed, boolean PulseSync)
{
static unsigned long lastwavemillis=millis();
static byte WavePhase=0;
static time_t WaveStart=0;
static byte speed=0;
static byte anti_speed=0;

if (WavePhase==0)
{
WavePhase++;
WaveStart=now();
}
else if (WavePhase==1)
{
if (now()-WaveStart>900) WavePhase++;
speed=(WaveMaxSpeed*sin(radians(map(now()-WaveStart,0,900,0,90))))/10;
speed+=WaveMaxSpeed/2;

anti_speed=(WaveMaxSpeed*2*sin(radians(map(now()-WaveStart,0,900,0,90))))/5;
anti_speed+=WaveMaxSpeed/2;
}
else if (WavePhase==2)
{
if (now()-WaveStart>1800) WavePhase++;
speed=(WaveMaxSpeed*sin(radians(map(now()-WaveStart,900,1800,90,180))))/20;
speed+=WaveMaxSpeed/2;
speed+=WaveMaxSpeed/20;

anti_speed=(WaveMaxSpeed*3*sin(radians(map(now()-WaveStart,900,1800,90,180))))/20;
anti_speed+=WaveMaxSpeed/2;
anti_speed+=WaveMaxSpeed/4;

}
else if (WavePhase==3)
{
if (now()-WaveStart>2700) WavePhase++;
speed=(WaveMaxSpeed*3*sin(radians(map(now()-WaveStart,1800,2700,0,90))))/20;
speed+=WaveMaxSpeed/2;
speed+=WaveMaxSpeed/20;

anti_speed=(WaveMaxSpeed*sin(radians(map(now()-WaveStart,1800,2700,0,90))))/20;
anti_speed+=WaveMaxSpeed/2;
anti_speed+=WaveMaxSpeed/4;
}
else if (WavePhase==4)
{
if (now()-WaveStart>3600) WavePhase++;
speed=(WaveMaxSpeed*sin(radians(map(now()-WaveStart,2700,3600,90,180))))/20;
speed+=WaveMaxSpeed/2;
speed+=(WaveMaxSpeed*3)/20;

anti_speed=(WaveMaxSpeed*3*sin(radians(map(now()-WaveStart,2700,3600,90,180))))/20;
anti_speed+=WaveMaxSpeed/2;
anti_speed+=(WaveMaxSpeed*3)/20;
}
else if (WavePhase==5)
{
if (now()-WaveStart>4500) WavePhase++;
speed=(WaveMaxSpeed*3*sin(radians(map(now()-WaveStart,3600,4500,0,90))))/20;
speed+=WaveMaxSpeed/2;
speed+=(WaveMaxSpeed*3)/20;

anti_speed=(WaveMaxSpeed*sin(radians(map(now()-WaveStart,3600,4500,0,90))))/20;
anti_speed+=WaveMaxSpeed/2;
anti_speed+=(WaveMaxSpeed*3)/20;
}
else if (WavePhase==6)
{
if (now()-WaveStart>5400) WavePhase++;
speed=(WaveMaxSpeed*sin(radians(map(now()-WaveStart,4500,5400,90,180))))/20;
speed+=WaveMaxSpeed/2;
speed+=(WaveMaxSpeed*5)/20;

anti_speed=(WaveMaxSpeed*3*sin(radians(map(now()-WaveStart,4500,5400,90,180))))/20;
anti_speed+=WaveMaxSpeed/2;
anti_speed+=WaveMaxSpeed/20;
}
else if (WavePhase==7)
{
if (now()-WaveStart>6300) WavePhase++;
speed=(WaveMaxSpeed*3*sin(radians(map(now()-WaveStart,5400,6300,0,90))))/20;
speed+=WaveMaxSpeed/2;
speed+=(WaveMaxSpeed*5)/20;

anti_speed=(WaveMaxSpeed*sin(radians(map(now()-WaveStart,5400,6300,0,90))))/20;
anti_speed+=WaveMaxSpeed/2;
anti_speed+=WaveMaxSpeed/20;
}
else if (WavePhase==8)
{
if (now()-WaveStart>7200) WavePhase++;
speed=(WaveMaxSpeed*sin(radians(map(now()-WaveStart,6300,7200,90,180))))/20;
speed+=WaveMaxSpeed/2;
speed+=(WaveMaxSpeed*7)/20;

anti_speed=(WaveMaxSpeed*sin(radians(map(now()-WaveStart,6300,7200,90,180))))/10;
anti_speed+=WaveMaxSpeed/2;
}
else if (WavePhase==9)
{
if (now()-WaveStart>8100) WavePhase++;
speed=(WaveMaxSpeed*3*sin(radians(map(now()-WaveStart,7200,8100,0,90))))/20;
speed+=WaveMaxSpeed/2;
speed+=(WaveMaxSpeed*7)/20;

anti_speed=(WaveMaxSpeed*sin(radians(map(now()-WaveStart,7200,8100,0,90))))/2;
anti_speed+=WaveMaxSpeed/2;
}
else if (WavePhase==10)
{
if (now()-WaveStart>9000) WavePhase=0;
speed=(WaveMaxSpeed*sin(radians(map(now()-WaveStart,8100,9000,90,180))))/2;
speed+=WaveMaxSpeed/2;

anti_speed=speed;
}

if (PulseSync)
return speed;
else
return anti_speed;
}
This gives you TidalSwell mode and I also set the condition that if it's not set to TidalSwell, you'll be at constant speed, but at 50%. Just so you can visibly see the change. Feel free to build your own now. I pasted a comment block with all the RF mode names. You just need to add the function and the condition. Keep in mind some functions require different arguments, so you won't always be able to just pass in duration for anything.
Post Reply