RF Expansion Module

Expansion modules and attachments
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: RF Expansion Module

Post by rimai »

The mode is by default controlled by internal memory, so you can simply change it by using any app that can write to internal memory, such as status app, built-in webserver and pretty soon the iphone, android and Client.
The memory locations are:
855 - Mode
856 - Speed
857 - Duration

To override the internal memory mode, you can use the following code:

Code: Select all

      ReefAngel.RF.UseMemory=false;
      ReefAngel.RF.SetMode(ShortWave,100,6);
The function is SetMode(Mode,Speed,Duration) and the parameter are:

Mode can be one of the following modes:
* Constant
* Random1 (Lagoonal)
* Random2 (Reef Crest)
* ShortWave (Short Pulse)
* LongWave (Long Pulse)
* Smart_NTM (Nutrient Transport Mode)
* Smart_TSM (Tidal Swell Mode)
* Storm (will only be available on the upcoming Dev libraries update or by using 10 instead of Storm)
* Custom (will only be available on the upcoming Dev libraries update or by using 11 instead of Custom)

Speed is a number from 0 through 100

Duration is only applicable to ShortWave, LongWave and Smart_NTM and represent the following:
ShortWave - tenths of a second
LongWave - seconds
Smart_NTM - tenths of a second

The function for Custom mode is SetMode(Mode,Speed,Channel) and the parameter are:

Mode: Custom

Speed is a number from 0 through 100

Channel:
0 - Sync
1- Anti-Sync
2- Back of Tank
Roberto.
StuGotz
Posts: 95
Joined: Sat Oct 15, 2011 9:17 am

Re: RF Expansion Module

Post by StuGotz »

Awesome, thanks! I'm starting to get a Poseidon complex ;) I shall rule the seas of my 14 gal tank, LOL.
Deckoz2302
Posts: 149
Joined: Tue Nov 01, 2011 11:05 am

Re: RF Expansion Module

Post by Deckoz2302 »

how would one call the current mode for display on main? also i get the error RF class has no member named UseMemory when using this statement. Also trying my feed mode is 30min long...and I beleive Slave_Stop turns off/completely stops the pumps? Id like the pumps to stop during feed mode and then go into NTM for 30 minutes prior to feed then return to reef crest...lol man...im just confused haha

Code: Select all

		if ( hour() <= 6 || hour () >= 20 )
			{
				ReefAngel.PWM.SetActinic(MoonPhase());
                                ReefAngel.RF.UseMemory=false;
                                ReefAngel.RF.SetMode(Night,10,0);
			}
		else
			{
				ReefAngel.PWM.SetActinic(0);
                                
			}
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: RF Expansion Module

Post by rimai »

Slave_Stop is only used for Master/Slave assignment. You should be needing to use that ever again once the pumps are assigned as slaves.
Feeding mode should come automatically on your vortech pumps when you enter feeding mode on RA.
You can initiate feeding mode in 3 ways:
1. Using RA joystick and navigating to feeding mode menu option.
2. Pressing and Holding "Set" on your Ecotech driver
3. Using iPhone or Android app to start feeding mode.
Roberto.
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: RF Expansion Module

Post by rimai »

The compile error is most likely because you need to add this to the top of your code.

Code: Select all

#include <ReefAngel_RF.h>
[code]
Roberto.
Deckoz2302
Posts: 149
Joined: Tue Nov 01, 2011 11:05 am

Re: RF Expansion Module

Post by Deckoz2302 »

That is included which is why im confused :\ and im using the latest dev libraries. And I guess I could use relays to turn the vortech completely off.
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: RF Expansion Module

Post by rimai »

Sorry, I forgot you also need this on ReefAngel_Features.h file:

Code: Select all

#define RFEXPANSION
Roberto.
Deckoz2302
Posts: 149
Joined: Tue Nov 01, 2011 11:05 am

Re: RF Expansion Module

Post by Deckoz2302 »

Had that defined too. I just updated the dev libraries again(I updated a week ago) the lines

Code: Select all

ReefAngel_RFClass::ReefAngel_RFClass()
{
	UseMemory=true;
}
wasnt defined in reefangel_rf.cpp it works now

hmm now to figure out switching to nutrient transport for 30 minutes after feedmode then back to reefcrest
StuGotz
Posts: 95
Joined: Sat Oct 15, 2011 9:17 am

Re: RF Expansion Module

Post by StuGotz »

Is there a variable that stores the mode that the pump is currently in, so it can easily be displayed on a custom main?

When setting up the Custom Menu for a Storm Mode is it safe to just put in a delay and change the mode back to your default, or should it be more involved? I imagine what I have below would set the mode to storm indefinitely, unless there's something in my loop to change it at some specified time of day to something else.

Code: Select all

void MenuEntry4()
{
ForceCloud=true;
ReefAngel.RF.UseMemory=false; // Sets variable so default memory modes for RF Module are not used
ReefAngel.RF.SetMode(10,150,0); // Sets Storm mode (10) on Vortech pumps at 150/255 speed, and 0 duration since not applicable to this mode.
ReefAngel.DisplayedMenu=RETURN_MAIN_MODE;
}
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: RF Expansion Module

Post by rimai »

You can use these to display on custom main screen:

Code: Select all

InternalMemory.RFMode_read();
InternalMemory.RFSpeed_read();
InternalMemory.RFDuration_read();
To change the Vortech mode to Storm mode during cloud/lightining period, I think the best way is to incorportate the switch of modes into the CheckCloud() function itself.
What you want to do is look for the part of code that starts the cloud and add the RF change mode funtion:

Code: Select all

  if (cloudchance)
  {
    //is it time for cloud yet?
    if (NumMins(hour(),minute())>=cloudstart && NumMins(hour(),minute())<(cloudstart+cloudduration))
    {
       ReefAngel.RF.UseMemory=false; // Sets variable so default memory modes for RF Module are not used
       ReefAngel.RF.SetMode(10,50,0); // Sets Storm mode (10) on Vortech pumps at 50 speed, and 0 duration since not applicable to this mode.
Then look for the part of the code that happens when the cloud ends and change back to memory settings:

Code: Select all

    if (NumMins(hour(),minute())>(cloudstart+cloudduration))
    {
      cloudindex++;
      if (cloudindex < numclouds)
      {
         ReefAngel.RF.UseMemory=true; // Sets variable so default memory modes for RF Module are used
Try this method and let me know if it works for you.
Roberto.
Deckoz2302
Posts: 149
Joined: Tue Nov 01, 2011 11:05 am

Re: RF Expansion Module

Post by Deckoz2302 »

i know this might sound silly but...I was thinking how do you set the initial internal memory values, so i opened up the manual and it directs you to the download page to download VortechSetup.pde....however i dont see that on the downloadpage :/
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: RF Expansion Module

Post by rimai »

:(
So sorry, I forgot to update the page.
It's updated now.
http://www.reefangel.com/Download.ashx
Roberto.
Deckoz2302
Posts: 149
Joined: Tue Nov 01, 2011 11:05 am

Re: RF Expansion Module

Post by Deckoz2302 »

Haha no prob roberto, lol it happens to the best of us. Thanks. And just a side note - I love the capabilities and flexibility of this controller. I get to spend more time watching and less time doing - the value of having things do what you want at the push of a button and be exactly how you want it is amazing(had a rke before and didn't like the gerneralized prewrtten programs)
StuGotz
Posts: 95
Joined: Sat Oct 15, 2011 9:17 am

Re: RF Expansion Module

Post by StuGotz »

What about adding a new function to check stormchance and be able to limit the amount of times a storm can occur, so it doesn't storm every time it gets cloudy?
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: RF Expansion Module

Post by rimai »

The function already had that chance feature.
Look for this line:

Code: Select all

#define Lightning_Change_per_Cloud 100
Roberto.
StuGotz
Posts: 95
Joined: Sat Oct 15, 2011 9:17 am

Re: RF Expansion Module

Post by StuGotz »

Got my RF Module today! I went to compile and upload VortechSetup.pde from the download page, but it's giving me a compile error.

..\Documents\Arduino\libraries\ReefAngel_CustomColors/ReefAngel_CustomColors.h:20:30: error: ReefAngel_Colors.h: No such file or directory

It should be ..\My Documents\Arduino.... I don't have this problem compiling and uploading my normal PDE. Any suggestions?
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: RF Expansion Module

Post by rimai »

Seems like you are missing libraries.
It's looking for a file ReefAngel_Colors.h, which should be under "Document\Arduino\libraries\ReefAngel_Colors" folder.
Do you have that folder?
Maybe you should update the libraries just in case.
http://www.reefangel.com/update
Roberto.
StuGotz
Posts: 95
Joined: Sat Oct 15, 2011 9:17 am

Re: RF Expansion Module

Post by StuGotz »

I have that folder under "My Documents\Arduino\libraries\ReefAngel_Colors" not "Document\Arduino\libraries\ReefAngel_Colors. I've modified it to change the default temp colors for my main PDE a couple weeks ago, and compiles fine for my normal PDE.
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: RF Expansion Module

Post by rimai »

Can I see your features file?
Roberto.
StuGotz
Posts: 95
Joined: Sat Oct 15, 2011 9:17 am

Re: RF Expansion Module

Post by StuGotz »

#define DisplayLEDPWM
#define wifi
#define VersionMenu
#define CUSTOM_MAIN
#define NUMBERS_8x16
#define COLORS_PDE
#define CUSTOM_MENU
#define CUSTOM_MENU_ENTRIES 7
#define RFEXPANSION
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: RF Expansion Module

Post by rimai »

Found the problem.
It had missing includes on the PDE file.
I uploaded a corrected version.
Please go ahead and download it again.
Roberto.
StuGotz
Posts: 95
Joined: Sat Oct 15, 2011 9:17 am

Re: RF Expansion Module

Post by StuGotz »

That did it. As always you never cease to amaze me on how quick you respond!

So if after I "Press the joystick to finalize your pump setup" the vortech goes white, but the module keeps flashing blue and green do I have to try to sync them again?
Deckoz2302
Posts: 149
Joined: Tue Nov 01, 2011 11:05 am

Re: RF Expansion Module

Post by Deckoz2302 »

When you did it did you clear your vortech memory first? Also - in yoru setup() define the mode you want to use constantly, then if you want something to change it create an if/else statement in loop

Also white = sync, orange = antisync, blue = back of tank

other times vortech is solid white in feed at 0%. Night mode is breathing white @ 50% of internal memory speed
Last edited by Deckoz2302 on Thu Dec 29, 2011 5:43 pm, edited 1 time in total.
StuGotz
Posts: 95
Joined: Sat Oct 15, 2011 9:17 am

Re: RF Expansion Module

Post by StuGotz »

Yup, cleared the memory settings first. I have

Code: Select all

ReefAngel.RF.UseMemory=false;
ReefAngel.RF.SetMode(Smart_NTM,120,6);
defined in my setup(). The Vortech went white like it paired fine, the module just kept flashing blue and green, instead of going solid green.
Deckoz2302
Posts: 149
Joined: Tue Nov 01, 2011 11:05 am

Re: RF Expansion Module

Post by Deckoz2302 »

In setup - don't use

Code: Select all

ReefAngel.RF.UseMemory=false;
because you are declaring the internal memory value

also - if your trying to do nutrient transport module will turn purple
green = constant speed
StuGotz
Posts: 95
Joined: Sat Oct 15, 2011 9:17 am

Re: RF Expansion Module

Post by StuGotz »

Same issue so I reset the vortech again, uploaded the VortechSetup.PDE again, after I hit the joystick to finalize the settings, the vortech turns white, but the RF Module continues to blink blue and green instead of going to a solid green

Only thing in Setup is ReefAngel.RF.SetMode(Smart_NTM,120,6);

I've commented out everything else I had in my loop and custom menu. Here's a copy if anyone is interested.

Code: Select all

// Autogenerated file by RAGen (v1.0.4.92), (10/15/2011 12:40)
// RA_101511_1240.pde
//
// This version designed for v0.8.5 Beta 12 or later

// *********************************************************
// MANY THANKS TO BOTH ROBERTO AND CURT FOR ALL THEIR HELP!*
// *********************************************************

/* The following features are enabled for this PDE File: 
#define DisplayLEDPWM
#define wifi
#define VersionMenu
#define CUSTOM_MAIN
#define NUMBERS_8x16
#define COLORS_PDE
#define CUSTOM_MENU
#define CUSTOM_MENU_ENTRIES 6
#define RFEXPANSION
*/

#include <ReefAngel_Features.h>
#include <ReefAngel_Globals.h>
#include <ReefAngel_Wifi.h>
#include <Wire.h>
#include <OneWire.h>
#include <Time.h>
#include <DS1307RTC.h>
#include <ReefAngel_EEPROM.h>
#include <ReefAngel_NokiaLCD.h>
#include <ReefAngel_ATO.h>
#include <ReefAngel_Joystick.h>
#include <ReefAngel_LED.h>
#include <ReefAngel_TempSensor.h>
#include <ReefAngel_Relay.h>
#include <ReefAngel_PWM.h>
#include <ReefAngel_Timer.h>
#include <ReefAngel_Memory.h>
#include <ReefAngel.h>
#include <ReefAngel_Colors.h>
#include <ReefAngel_CustomColors.h>
#include <avr/pgmspace.h>
#include <ReefAngel_RF.h>

#define Sump                1
#define DosingPump2         2
#define Refugium            3
#define Daylight            4
#define Actinic             5
#define Skimmer             6
#define Heater              7
#define DosingPump1         8

//Cloud & Lightning effects
byte ActinicPWMValue=0;
byte DaylightPWMValue=0;
boolean ForceCloud=false;

// Create the menu entries
prog_char menu1_label[] PROGMEM = "Feeding";
prog_char menu2_label[] PROGMEM = "Water Change";
prog_char menu3_label[] PROGMEM = "Force Cloud";
prog_char menu4_label[] PROGMEM = "Force Storm";
prog_char menu5_label[] PROGMEM = "Overheat Clear";
prog_char menu6_label[] PROGMEM = "PH Calibration";
prog_char menu7_label[] PROGMEM = "Version";

// Group the menu entries together
PROGMEM const char *menu_items[] = {
menu1_label, menu2_label, menu3_label,
menu4_label, menu5_label, menu6_label, menu7_label
};

// Menu Item actions
void MenuEntry1()
{
ReefAngel.FeedingModeStart();
}
void MenuEntry2()
{
ReefAngel.WaterChangeModeStart();
}
void MenuEntry3()
{
ForceCloud=true;
ReefAngel.DisplayedMenu=RETURN_MAIN_MODE;
}
void MenuEntry4()
{
ForceCloud=true;
//ReefAngel.RF.UseMemory=false; // Sets variable so default memory modes for RF Module are not used
//ReefAngel.RF.SetMode(10,150,0); // Sets Storm mode (10) on Vortech pumps at 150/255 speed, and 0 duration since not applicable to this mode.
ReefAngel.DisplayedMenu=RETURN_MAIN_MODE;
}
void MenuEntry5()
{
ReefAngel.OverheatClear();
ReefAngel.DisplayMenuEntry("Clear Overheat");
}
void MenuEntry6()
{
ReefAngel.SetupCalibratePH();
ReefAngel.DisplayedMenu = ALT_SCREEN_MODE;
}
void MenuEntry7()
{
ReefAngel.DisplayVersion();
}

// Custom Main Screen

void DrawCustomMain()
{
  ReefAngel.LCD.DrawText(COLOR_WHITE, COLOR_CORNFLOWERBLUE, 0, 0, "                       "); //Top Banner
  ReefAngel.LCD.DrawText(COLOR_WHITE, COLOR_CORNFLOWERBLUE, 0, 2, " BioCube 14 Nano Reef  "); //Top Banner
  ReefAngel.LCD.DrawDate(6, 123);
  pingSerial();
  
  // Display Temp Text
  ReefAngel.LCD.DrawText(0,255,12,12,"Temp");
  
  // Display the T1 temp value 10,22
  char text[7];
  ConvertNumToString(text, ReefAngel.Params.Temp1, 10);
  ReefAngel.LCD.Clear(255, 0, 22, 50, 36);
  ReefAngel.LCD.DrawLargeText(COLOR_CORNFLOWERBLUE, 255, 10, 22, text, Num8x16);
  pingSerial();
  
  // Display pH Text
  ReefAngel.LCD.DrawText(0,255,100,12,"pH");
  
  // Display pH Value
  ConvertNumToString(text, ReefAngel.Params.PH, 100);
  ReefAngel.LCD.Clear(255, 90, 22, 98, 36);
  ReefAngel.LCD.DrawLargeText(COLOR_CORNFLOWERBLUE, 255, 90, 22, text, Num8x16);
  pingSerial();
   
  // Display Actinic Percentage Text
  ReefAngel.LCD.DrawText(0,255,8,40,"Actinic %");
  
  // Display the Actinic PWM channel value at 90,40
  ReefAngel.LCD.DrawSingleMonitor(ReefAngel.PWM.GetActinicValue(),COLOR_CORNFLOWERBLUE, 90, 40, 1);
  
  // Display Daylight Percentage Text
  ReefAngel.LCD.DrawText(0,255,8,50,"Daylight %");
    
  // Display the Daylight PWM channel value at 90,50
  ReefAngel.LCD.DrawSingleMonitor(ReefAngel.PWM.GetDaylightValue(),COLOR_CORNFLOWERBLUE, 90, 50, 1);
  
  // Display T2 Temp Text
  ReefAngel.LCD.DrawText(0,255,8,60,"Canopy Temp");
  
  // Display the T2 temperature value at 90,60
  ReefAngel.LCD.DrawSingleMonitor(ReefAngel.Params.Temp2, COLOR_CORNFLOWERBLUE, 90, 60, 10);
  
  // Display T3 Temp Text
  ReefAngel.LCD.DrawText(0,255,8,70,"Ambient Temp");
  
  // Display the T3 temperature at 90,70
  ReefAngel.LCD.DrawSingleMonitor(ReefAngel.Params.Temp3, COLOR_CORNFLOWERBLUE, 90, 70, 10);
  
  // Display Vortech MP10ew Mode Text at 90, 80
  ReefAngel.LCD.DrawText(0,255,8,80,"EcoSmart Mode");
  
  // Display EcoSmart Mode Value
  //ReefAngel.LCD.DrawText(COLOR_CORNFLOWERBLUE,255,90,80,"Storm");
  //ConvertNumToString(text, InternalMemory.RFMode_read(), 1);
  //ReefAngel.LCD.Clear(255, 90, 80, 98, 90);
  ReefAngel.LCD.DrawText(COLOR_CORNFLOWERBLUE, 255, 90, 80, InternalMemory.RFMode_read());
  //pingSerial();
  
  
  pingSerial();
  byte TempRelay = ReefAngel.Relay.RelayData;
  TempRelay &= ReefAngel.Relay.RelayMaskOff;
  TempRelay |= ReefAngel.Relay.RelayMaskOn;
  ReefAngel.LCD.DrawOutletBox(13, 97, TempRelay);
}
void DrawCustomGraph()
{
 // ReefAngel.LCD.DrawGraph(5,7);
}

void setup()
{
  ReefAngel.Init();  //Initialize controller
  ReefAngel.InitMenu(pgm_read_word(&(menu_items[0])),SIZE(menu_items)); //For Custom Menu
  ReefAngel.FeedingModePorts = B00100001; //Ports 6 & 1 turn off
  ReefAngel.WaterChangePorts = B00100001; //Ports 6 & 1 turn off
  ReefAngel.OverheatShutoffPorts = B00011000; //Ports 4 & 5 turn off
  ReefAngel.LightsOnPorts = B00011000; //Ports 4 & 5 turn on
  
 // ReefAngel.RF.UseMemory=false;
  ReefAngel.RF.SetMode(Smart_NTM,120,6);
      
  // Ports that are always on
  ReefAngel.Relay.On(Port1);
}

void loop()
{
  ReefAngel.ShowInterface();
  
  // Delay Skimmer port 5 minutes whenever turned on
  // From Curt - THANKS CURT!
  ReefAngel.Relay.DelayedOn(Port6, 5);
  
  //Heater    
  ReefAngel.StandardHeater(Heater,775,780);  // Setup Heater to turn on at 77.5F and off at 78.0F
 
  //Lighting schedule
  ReefAngel.MHLights(Daylight,9,0,17,0,0);  //Daylight schedule 9:00am - 5:00pm with 0min cool down
  ReefAngel.StandardLights(Actinic,7,0,19,0);  //Actinic schedule 7:00am - 7:00pm
  ReefAngel.StandardLights(Refugium,19,0,7,0);  //Refugium schedule 7:00pm - 7:00am
  
  // Dosing pumps (OLD DOSING METHOD OF PUMP ONE ON THE HOUR, THEN PUMP2 5 MIN LATER - to use when tank is more mature
  //From Roberto - THANKS ROBERTO!
   /* if (ReefAngel.DisplayedMenu==255 && minute()==0 && second()<1)  //Alk Doser - Only works if Main screen is showing
      ReefAngel.Relay.On(DosingPump1);  //Turn Alk Doser on
    else
      ReefAngel.Relay.Off(DosingPump1);  //Turn Alk Doser off
    if (ReefAngel.DisplayedMenu==255 && minute()==5 && second()<1)  //CA Doser - Only works if Main screen is showing
      ReefAngel.Relay.On(DosingPump2);  //Turn CA Doser on
    else
      ReefAngel.Relay.Off(DosingPump2);  //Turn CA Doser off 
   */
 
  // Dosing pumps
  // From Roberto - THANKS ROBERTO!
  
  if (ReefAngel.DisplayedMenu==255 && hour()%2==0 && minute()==0 && second()<1) // 1 sec dosing on even hours
    ReefAngel.Relay.On(DosingPump1);  //Turn DosingPump1 Doser on
  else
    ReefAngel.Relay.Off(DosingPump1);  //Turn DosingPump1 Doser off
  if (ReefAngel.DisplayedMenu==255 && hour()%2==1 && minute()==0 && second()<1) // 1 sec dosing on odd hours
    ReefAngel.Relay.On(DosingPump2);  //Turn DosingPump2 Doser on
  else
    ReefAngel.Relay.Off(DosingPump2);  //Turn DosingPump2 Doser off

  // Cloud & Lightning effects - Calculate your regular sunrise/sunset PWM value
  // From Roberto - THANKS ROBERTO!
  // byte PWMSlope(byte startHour, byte startMinute, byte endHour, byte endMinute, byte startPWM, byte endPWM, byte Duration, byte oldValue)
  if (hour()>=19 || hour()<7)
    {
      ReefAngel.PWM.SetActinic(MoonPhase());  //Moon phase schedule between 7:00pm - 7:00am
      //ReefAngel.RF.UseMemory=false; // Sets variable so default memory modes for RF Module are not used
      //ReefAngel.RF.SetMode(Smart_NTM,10,5); // Sets Night mode on Vortech pumps
    }
  else
    {
      ActinicPWMValue=PWMSlope(7,00,19,0,0,35,60,ActinicPWMValue); //Actinic turn on at 7am, off at 10am, and ramp up 0% to 50% PWM in 60 minutes
      //ActinicPWMValue=PWMSlope(16,00,19,0,0,50,60,ActinicPWMValue); //Actinic turn on at 4pm, off at 7pm, and ramp up 0% to 50% PWM in 60 minutes
      ReefAngel.PWM.SetActinic(ActinicPWMValue);
      //ReefAngel.RF.UseMemory=false; // Sets variable so default memory modes for RF Module are not used
      //ReefAngel.RF.SetMode(Smart_NTM,106,10); // Sets Day mode on Vortech pumps
    }
  DaylightPWMValue=PWMSlope(9,00,17,0,0,75,60,DaylightPWMValue); //Daylight turn on at 9am, off at 5pm, and ramp up 0% to 50% PWM in 60 minutes
  CheckCloud(); 
  ReefAngel.PWM.SetDaylight(DaylightPWMValue);
}

//*********************************************************************************************************************************
// Random Cloud/Thunderstorm effects function
// From Roberto - THANKS ROBERTO!
void CheckCloud()
{

  // ------------------------------------------------------------
  // Change the values below to customize your cloud/storm effect

  // Frequency in days based on the day of the month - number 2 means every 2 days, for example (day 2,4,6 etc)
  // For testing purposes, you can use 1 and cause the cloud to occur everyday
#define Clouds_Every_X_Days 1 

  // Percentage chance of a cloud happening today
  // For testing purposes, you can use 100 and cause the cloud to have 100% chance of happening
#define Cloud_Chance_per_Day 100

  // Minimum number of minutes for cloud duration.  Don't use max duration of less than 6
#define Min_Cloud_Duration 7

  // Maximum number of minutes for the cloud duration. Don't use max duration of more than 255
#define Max_Cloud_Duration 15

  // Minimum number of clouds that can happen per day
#define Min_Clouds_per_Day 3

  // Maximum number of clouds that can happen per day
#define Max_Clouds_per_Day 6

  // Only start the cloud effect after this setting
  // In this example, start could after 11:30am
#define Start_Cloud_After NumMins(11,30)

  // Always end the cloud effect before this setting
  // In this example, end could before 4:30pm
#define End_Cloud_Before NumMins(16,30)

  // Percentage chance of a lightning happen for every cloud
  // For testing purposes, you can use 100 and cause the lightning to have 100% chance of happening
#define Lightning_Change_per_Cloud 25

  // Note: Make sure to choose correct values that will work within your PWMSLope settings.
  // For example, in our case, we could have a max of 5 clouds per day and they could last for 50 minutes.
  // Which could mean 250 minutes of clouds. We need to make sure the PWMSlope can accomodate 250 minutes of effects or unforseen result could happen.
  // Also, make sure that you can fit double those minutes between Start_Cloud_After and End_Cloud_Before.
  // In our example, we have 510 minutes between Start_Cloud_After and End_Cloud_Before, so double the 250 minutes (or 500 minutes) can fit in that 510 minutes window.
  // It's a tight fit, but it did.

    //#define printdebug // Uncomment this for debug print on Serial Monitor window
#define forcecloudcalculation // Uncomment this to force the cloud calculation to happen in the boot process. 


  // Change the values above to customize your cloud/storm effect
  // ------------------------------------------------------------
  // Do not change anything below here

  static byte cloudchance=255;
  static byte cloudduration=0;
  static int cloudstart=0;
  static byte numclouds=0;
  static byte lightningchance=0;
  static byte cloudindex=0;
  static byte lightningstatus=0;
  static int LastNumMins=0;
  // Every day at midnight, we check for chance of cloud happening today
  if (hour()==0 && minute()==0 && second()==0) cloudchance=255;

#ifdef forcecloudcalculation
  if (cloudchance==255)
#else
    if (hour()==0 && minute()==0 && second()==1 && cloudchance==255) 
#endif
    {
      //Pick a random number between 0 and 99
      cloudchance=random(100); 
      // if picked number is greater than Cloud_Chance_per_Day, we will not have clouds today
      if (cloudchance>Cloud_Chance_per_Day) cloudchance=0;
      // Check if today is day for clouds. 
      if ((day()%Clouds_Every_X_Days)!=0) cloudchance=0; 
      // If we have cloud today
      if (cloudchance)
      {
        // pick a random number for number of clouds between Min_Clouds_per_Day and Max_Clouds_per_Day
        numclouds=random(Min_Clouds_per_Day,Max_Clouds_per_Day);
        // pick the time that the first cloud will start
        // the range is calculated between Start_Cloud_After and the even distribuition of clouds on this day. 
        cloudstart=random(Start_Cloud_After,Start_Cloud_After+((End_Cloud_Before-Start_Cloud_After)/(numclouds*2)));
        // pick a random number for the cloud duration of first cloud.
        cloudduration=random(Min_Cloud_Duration,Max_Cloud_Duration);
        //Pick a random number between 0 and 99
        lightningchance=random(100);
        // if picked number is greater than Lightning_Change_per_Cloud, we will not have lightning today
        if (lightningchance>Lightning_Change_per_Cloud) lightningchance=0;
      }
    }
  
  //When custom menu Force cloud is selected
  if (ForceCloud)
  {
    ForceCloud=false;
    cloudchance=1;
    cloudduration=10;
    lightningchance=1;
    cloudstart=NumMins(hour(),minute())+1;
  }
  
  // Now that we have all the parameters for the cloud, let's create the effect
  if (cloudchance)
  {
    //is it time for cloud yet?
    if (NumMins(hour(),minute())>=cloudstart && NumMins(hour(),minute())<(cloudstart+cloudduration))
    {
      DaylightPWMValue=ReversePWMSlope(cloudstart,cloudstart+cloudduration,DaylightPWMValue,0,180);
      if (lightningchance && (NumMins(hour(),minute())==(cloudstart+(cloudduration/2))) && second()<5) 
      {
        if (random(100)<20) lightningstatus=1; 
        else lightningstatus=0;
        if (lightningstatus)
        {
          DaylightPWMValue=100; 
          ActinicPWMValue=100;
        }
        else 
        {
          DaylightPWMValue=0;
          ActinicPWMValue=0;
        }
        delay(1);
      }
    }
    if (NumMins(hour(),minute())>(cloudstart+cloudduration))
    {
      cloudindex++;
      if (cloudindex < numclouds)
      {
        cloudstart=random(Start_Cloud_After+(((End_Cloud_Before-Start_Cloud_After)/(numclouds*2))*cloudindex*2),(Start_Cloud_After+(((End_Cloud_Before-Start_Cloud_After)/(numclouds*2))*cloudindex*2))+((End_Cloud_Before-Start_Cloud_After)/(numclouds*2)));
        // pick a random number for the cloud duration of first cloud.
        cloudduration=random(Min_Cloud_Duration,Max_Cloud_Duration);
        //Pick a random number between 0 and 99
        lightningchance=random(100);
        // if picked number is greater than Lightning_Change_per_Cloud, we will not have lightning today
        if (lightningchance>Lightning_Change_per_Cloud) lightningchance=0;
      }
    }
  }

  if (LastNumMins!=NumMins(hour(),minute()))
  {
    LastNumMins=NumMins(hour(),minute());
    ReefAngel.LCD.Clear(255,0,113,132,121);
    ReefAngel.LCD.DrawText(0,255,12,113,"C");
    ReefAngel.LCD.DrawText(0,255,18,113,"00:00");
    ReefAngel.LCD.DrawText(0,255,52,113,"L");
    ReefAngel.LCD.DrawText(0,255,58,113,"00:00");
    ReefAngel.LCD.DrawText(0,255,93,113,"DUR");
    if (cloudchance && (NumMins(hour(),minute())<cloudstart))
    {
      int x=0;
      if ((cloudstart/60)>=10) x=18; 
      else x=24;
      ReefAngel.LCD.DrawText(0,255,x,113,(cloudstart/60));
      if ((cloudstart%60)>=10) x=36; 
      else x=42;
      ReefAngel.LCD.DrawText(0,255,x,113,(cloudstart%60));
    }
    ReefAngel.LCD.DrawText(0,255,114,113,cloudduration);
    if (lightningchance) 
    {
      int x=0;
      if (((cloudstart+(cloudduration/2))/60)>=10) x=88; 
      else x=94;
      ReefAngel.LCD.DrawText(0,255,x,113,((cloudstart+(cloudduration/2))/60));
      if (((cloudstart+(cloudduration/2))%60)>=10) x=109; 
      else x=112;
      ReefAngel.LCD.DrawText(0,255,x,113,((cloudstart+(cloudduration/2))%60));
    }
  }   
}

byte ReversePWMSlope(long cstart,long cend,byte PWMStart,byte PWMEnd, byte clength)
{
  long n=elapsedSecsToday(now());
  cstart*=60;
  cend*=60;
  if (n<cstart) return PWMStart;
  if (n>=cstart && n<=(cstart+clength)) return map(n,cstart,cstart+clength,PWMStart,PWMEnd);
  if (n>(cstart+clength) && n<(cend-clength)) return PWMEnd;
  if (n>=(cend-clength) && n<=cend) return map(n,cend-clength,cend,PWMEnd,PWMStart);
  if (n>cend) return PWMStart;
  //End Cloud & Lighting 
}
Deckoz2302
Posts: 149
Joined: Tue Nov 01, 2011 11:05 am

Re: RF Expansion Module

Post by Deckoz2302 »

I feel as though you need to declare something in your loop somewhere - perfect placeis in your moonphase if statement.... try adding lines similar to this and see if it changes anything >.<

if ( hour() <= 6 || hour () >= 19 ) // Moonlights on from 7PM to 7AM
{
ReefAngel.PWM.SetActinic(MoonPhase());
ReefAngel.RF.UseMemory=false;
ReefAngel.RF.SetMode(Night,15,0);
}
else
{
ReefAngel.PWM.SetActinic(0);
ReefAngel.RF.UseMemory=true;
}
StuGotz
Posts: 95
Joined: Sat Oct 15, 2011 9:17 am

Re: RF Expansion Module

Post by StuGotz »

No change. Does your RF Module constantly blink blue and green? The manual says it should go solid green after a successful sync, so I'm wondering if it's even sending RF commands to the Vortech.
StuGotz
Posts: 95
Joined: Sat Oct 15, 2011 9:17 am

Re: RF Expansion Module

Post by StuGotz »

OK unplugged everything, let is sit for about 30 secs and plugged it all back in. Now the vortech is breathing white, so must be in night mode. The RF Module is breathing white too. <shrug> works for me!
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: RF Expansion Module

Post by rimai »

I'll double check, but I think after you described what you experienced, I may have forgotten something on the vortechsetup.pde file.
I have always used a controller with internal memory already initialized, so that's why it would turn green (constant mode), because it was what I had already set on my internal memory.
I think what happened in here was that your internal memory has an unknown value.
I can't remember if you have wifi. If you do, would you please browse to http://youripaddress:2000/mb855 and let me know what you see on the browser?
Roberto.
Post Reply