16 channel custom board code

Do you have a question on how to do something.
Ask in here.
Post Reply
User avatar
heatdissipation
Posts: 52
Joined: Wed Aug 14, 2013 5:25 am

16 channel custom board code

Post by heatdissipation »

Roberto made me a 16 channel board, I got it a few weeks ago, but I am just now getting around to trying to set it up. I spliced it into my current light controller so that I can test and fine tune it before I use it as my only control of my lights.
I am trying to get a sunrise, sunset from east to west accordingly, lightning is great, but I want to work on the sunrise and sunset first, then later down the road I will try to incorporate storms when I am better at figuring out this RA language....
I also have the 6 channel dimming expansion already connected and running two wp60's and two wp 40's.

I have 214 LED's over an eight foot span, the Blue's and whites are grouped together in sequence, with eight to ten LED's of each color on individual channels. Then I have UV/Cyan spread out over the length of the heatsinks on a seperate channel, also I have a channel for red that is spread out over the length of the tank, and a channel for green spread out over the tank. These are the list of my channels, starting from east to west on my tank, (except for the reds, greens, and uv/cyan which are spread out on individual channels)

1. 1st Blue on east end
2. 1st white on east end
3. 2nd blue channel
4. 3rd blue channel
5. 2nd white channel
6. 4th blue channel
7.5th blue channel
8. 3rd white channel
9. 6th blue channel
10. 4th white channel
11. 7th blue channel
12. 5th white channel
13. 8th blue channel
14. UV/Cyan channel
15. Green Channel
16. Red channel


The colors are all mixed very well across 4 linear heatsinks, I dont have any color banding, or "rainbow effects" what so ever. I have been using these lights for over a year now and are growing coral very well.

I just got my DC Pump code figured out, and now its time to do this lighting. Ill paste my current code first, and then I will paste the test code Roberto sent me second.

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


////// 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 
    ReefAngel.AddSalinityExpansion();  // Salinity Expansion Module
    ReefAngel.AddPHExpansion();  // pH Expansion Module
    // Ports toggled in Feeding Mode
    ReefAngel.FeedingModePorts = Port4Bit;
    ReefAngel.FeedingModePortsE[0] = 0;
    // Ports toggled in Water Change Mode
    ReefAngel.WaterChangePorts = Port1Bit | Port4Bit;
    ReefAngel.WaterChangePortsE[0] = 0;
    // Ports toggled when Lights On / Off menu entry selected
    ReefAngel.LightsOnPorts = 0;
    ReefAngel.LightsOnPortsE[0] = 0;
    // Ports turned off when Overheat temperature exceeded
    ReefAngel.OverheatShutoffPorts = Port1Bit;
    ReefAngel.OverheatShutoffPortsE[0] = 0;
    // Use T1 probe as temperature and overheat functions
    ReefAngel.TempProbe = T1_PROBE;
    ReefAngel.OverheatProbe = T1_PROBE;

    // Feeeding and Water Change mode speed
    ReefAngel.DCPump.FeedingSpeed=0;
    ReefAngel.DCPump.WaterChangeSpeed=0;


    // Ports that are always on
    ReefAngel.Relay.On( Port4 );
    ReefAngel.Relay.On( Box1_Port3 );
    ReefAngel.Relay.On( Box1_Port4 );

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

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

void loop()
{
    ReefAngel.StandardHeater( Port1 );
    ReefAngel.MoonLights( Port5 );
    ReefAngel.DayLights( Port6 );
    ReefAngel.DosingPumpRepeat1( Box1_Port1 );
    ReefAngel.DosingPumpRepeat2( Box1_Port2 );
    ReefAngel.DCPump.UseMemory = true;
    ReefAngel.DCPump.DaylightChannel = None;
    ReefAngel.DCPump.ActinicChannel = None;
    ReefAngel.DCPump.ExpansionChannel[0] = None;
    ReefAngel.DCPump.ExpansionChannel[1] = Sync;
    ReefAngel.DCPump.ExpansionChannel[2] = AntiSync;
    ReefAngel.DCPump.ExpansionChannel[3] = AntiSync;
    ReefAngel.DCPump.ExpansionChannel[4] = None;
    ReefAngel.DCPump.ExpansionChannel[5] = None;
    ////// Place your custom code below here
    //Night Mode at 30%
     if (hour()<6 || hour()>=22) {
 ReefAngel.DCPump.UseMemory=false; 
ReefAngel.DCPump.Mode=Constant; 
ReefAngel.DCPump.Speed=30;
     }
    // Add random mode if we set to Mode to Custom in portal
static int rmode;
static boolean changeMode=true;

// Add Else Mode definition..
const int Else=16;

// These are the modes we can cycle through. You can add more and even repeat...
byte modes[] = { ReefCrest, Lagoon, Constant, TidalSwell, ShortPulse, LongPulse, Else };

if (now()%SECS_PER_DAY==0 || changeMode==true) { // Change at midnight or if controller rebooted
rmode=random(100)%sizeof(modes); // Change the mode once per day to pick from our array
changeMode=false;
}

// Set timer when in feeding mode
static unsigned long feeding;
if (ReefAngel.DisplayedMenu==FEEDING_MODE) feeding=now();

if (now()-feeding<9000) { 
  // Continue NTM for 150 minutes
  ReefAngel.DCPump.UseMemory=false;
  ReefAngel.DCPump.Duration=InternalMemory.DCPumpDuration_read();
  ReefAngel.DCPump.Mode=NutrientTransport;
} else if (now()%SECS_PER_DAY<21600 || now()%SECS_PER_DAY>=79200) { // 6AM / 10pm
  // Night mode (go to 30%)
  ReefAngel.DCPump.UseMemory=false;
  ReefAngel.DCPump.Duration=InternalMemory.DCPumpDuration_read();
  ReefAngel.DCPump.Mode=Constant;
  ReefAngel.DCPump.Speed=30;
} else if (InternalMemory.DCPumpMode_read()==11) { 
  // Custom Mode and nothing else going on
  ReefAngel.DCPump.UseMemory=false;
  ReefAngel.DCPump.Duration=InternalMemory.DCPumpDuration_read();
  if (rmode==Else) {
    ReefAngel.DCPump.UseMemory=false;
    ReefAngel.DCPump.Mode=Constant;
    ReefAngel.DCPump.Speed=ElseMode(InternalMemory.DCPumpSpeed_read(),20,true );    // ElseMode on sync mode, Portal Speed Setting +/- 20%
  } else {
    ReefAngel.DCPump.Mode=modes[rmode];  // Put the mode to the random mode :)
    ReefAngel.DCPump.Speed=InternalMemory.DCPumpSpeed_read(); // Set speed from portal
  }
} else {
  ReefAngel.DCPump.UseMemory=true; // Will reset all values from memory
}

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

    // This should always be the last line
    ReefAngel.Portal( "heatdissipation" );
    ReefAngel.ShowInterface();
}
byte ElseMode( byte MidPoint, byte Offset, boolean WaveSync )
{
 // Static's only initialize the first time they are called
 static unsigned long LastChange=millis(); // Set the inital time that the last change occurred
 static int Delay = random( 500, 3000); // Set the initial delay
 static int NewSpeed = MidPoint; // Set the initial speed
 static int AntiSpeed = MidPoint; // Set the initial anti sync speed
 if ((millis()-LastChange) > Delay) // Check if the delay has elapsed
 {
 Delay=random(500,5000); // If so, come up with a new delay
 int ChangeUp = random(Offset); // Amount to go up or down
 if (random(100)<50) // 50/50 chance of speed going up or going down
 {
 NewSpeed = MidPoint - ChangeUp;
 AntiSpeed = MidPoint + ChangeUp;
 }
 else
 {
 NewSpeed = MidPoint + ChangeUp;
 AntiSpeed = MidPoint - ChangeUp;
 }
 LastChange=millis(); // Reset the time of the last change
 }
 if (WaveSync)
 {
 return NewSpeed;
 }
 else
 {
 return AntiSpeed;
 }
}
This is the test code I have, I loaded it and it did light everything up after I got the board spliced into my current setup. It was quite dim, but I believe that the test code wasnt putting out 100%

Code: Select all

#include <Salinity.h>
#include <ReefAngel_Features.h>
#include <Globals.h>
#include <RA_Wifi.h>
#include <Wire.h>
#include <OneWire.h>
#include <Time.h>
#include <DS1307RTC.h>
#include <rtc_clock.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 <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>

void setup()
{
  ReefAngel.Init();    

}

void loop()
{
  for (int a=0;a<16;a++)
  {
    CustomExpansion(0x41,a,30);
  }
  ReefAngel.ShowInterface();
}

void CustomExpansion(byte id, byte channel, byte percentage)
{
  Wire.beginTransmission(id);
  Wire.write(0);
  Wire.write(0xa1);
  Wire.endTransmission();
  int newdata=(int)(percentage*40.95);
  Wire.beginTransmission(id);
  Wire.write(0x8+(4*channel));
  Wire.write(newdata&0xff);
  Wire.write(newdata>>8);
  Wire.endTransmission();
}
So I need help pointing me in the right direction on what, if anything I need to add to my libraries, and a rough draft on the code that it would take to light this up. Any and all help would be so appreciated, as I know this isnt really the run of the mill questions you are all used to getting. Thanks
User avatar
heatdissipation
Posts: 52
Joined: Wed Aug 14, 2013 5:25 am

Re: 16 channel custom board code

Post by heatdissipation »

I'm not sure if I can do this one on my own right now. Maybe in the future I will be able to, but right now I am still learning this code.
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: 16 channel custom board code

Post by rimai »

What is that you want to do with each channel?
We need a graph or something to know what each channel is going to be like for a 24hr period.
Roberto.
User avatar
heatdissipation
Posts: 52
Joined: Wed Aug 14, 2013 5:25 am

Re: 16 channel custom board code

Post by heatdissipation »

To start off I just want a default program that works. Just a parabola pattern starting at 0 ramping up to say 80% and then back to zero. I want to use this until I can put together the code that will do the more advanced functions. But this will be the program I can upload to run while I'm testing out other programs
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: 16 channel custom board code

Post by rimai »

Try this:

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


////// 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 
  ReefAngel.AddSalinityExpansion();  // Salinity Expansion Module
  ReefAngel.AddPHExpansion();  // pH Expansion Module
  // Ports toggled in Feeding Mode
  ReefAngel.FeedingModePorts = Port4Bit;
  ReefAngel.FeedingModePortsE[0] = 0;
  // Ports toggled in Water Change Mode
  ReefAngel.WaterChangePorts = Port1Bit | Port4Bit;
  ReefAngel.WaterChangePortsE[0] = 0;
  // Ports toggled when Lights On / Off menu entry selected
  ReefAngel.LightsOnPorts = 0;
  ReefAngel.LightsOnPortsE[0] = 0;
  // Ports turned off when Overheat temperature exceeded
  ReefAngel.OverheatShutoffPorts = Port1Bit;
  ReefAngel.OverheatShutoffPortsE[0] = 0;
  // Use T1 probe as temperature and overheat functions
  ReefAngel.TempProbe = T1_PROBE;
  ReefAngel.OverheatProbe = T1_PROBE;

  // Feeeding and Water Change mode speed
  ReefAngel.DCPump.FeedingSpeed=0;
  ReefAngel.DCPump.WaterChangeSpeed=0;


  // Ports that are always on
  ReefAngel.Relay.On( Port4 );
  ReefAngel.Relay.On( Box1_Port3 );
  ReefAngel.Relay.On( Box1_Port4 );

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


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

void loop()
{
  ReefAngel.StandardHeater( Port1 );
  ReefAngel.MoonLights( Port5 );
  ReefAngel.DayLights( Port6 );
  ReefAngel.DosingPumpRepeat1( Box1_Port1 );
  ReefAngel.DosingPumpRepeat2( Box1_Port2 );
  ReefAngel.DCPump.UseMemory = true;
  ReefAngel.DCPump.DaylightChannel = None;
  ReefAngel.DCPump.ActinicChannel = None;
  ReefAngel.DCPump.ExpansionChannel[0] = None;
  ReefAngel.DCPump.ExpansionChannel[1] = Sync;
  ReefAngel.DCPump.ExpansionChannel[2] = AntiSync;
  ReefAngel.DCPump.ExpansionChannel[3] = AntiSync;
  ReefAngel.DCPump.ExpansionChannel[4] = None;
  ReefAngel.DCPump.ExpansionChannel[5] = None;
  ////// Place your custom code below here
  //Night Mode at 30%
  if (hour()<6 || hour()>=22) {
    ReefAngel.DCPump.UseMemory=false; 
    ReefAngel.DCPump.Mode=Constant; 
    ReefAngel.DCPump.Speed=30;
  }
  // Add random mode if we set to Mode to Custom in portal
  static int rmode;
  static boolean changeMode=true;

  // Add Else Mode definition..
  const int Else=16;

  // These are the modes we can cycle through. You can add more and even repeat...
  byte modes[] = { 
    ReefCrest, Lagoon, Constant, TidalSwell, ShortPulse, LongPulse, Else   };

  if (now()%SECS_PER_DAY==0 || changeMode==true) { // Change at midnight or if controller rebooted
    rmode=random(100)%sizeof(modes); // Change the mode once per day to pick from our array
    changeMode=false;
  }

  // Set timer when in feeding mode
  static unsigned long feeding;
  if (ReefAngel.DisplayedMenu==FEEDING_MODE) feeding=now();

  if (now()-feeding<9000) { 
    // Continue NTM for 150 minutes
    ReefAngel.DCPump.UseMemory=false;
    ReefAngel.DCPump.Duration=InternalMemory.DCPumpDuration_read();
    ReefAngel.DCPump.Mode=NutrientTransport;
  } 
  else if (now()%SECS_PER_DAY<21600 || now()%SECS_PER_DAY>=79200) { // 6AM / 10pm
    // Night mode (go to 30%)
    ReefAngel.DCPump.UseMemory=false;
    ReefAngel.DCPump.Duration=InternalMemory.DCPumpDuration_read();
    ReefAngel.DCPump.Mode=Constant;
    ReefAngel.DCPump.Speed=30;
  } 
  else if (InternalMemory.DCPumpMode_read()==11) { 
    // Custom Mode and nothing else going on
    ReefAngel.DCPump.UseMemory=false;
    ReefAngel.DCPump.Duration=InternalMemory.DCPumpDuration_read();
    if (rmode==Else) {
      ReefAngel.DCPump.UseMemory=false;
      ReefAngel.DCPump.Mode=Constant;
      ReefAngel.DCPump.Speed=ElseMode(InternalMemory.DCPumpSpeed_read(),20,true );    // ElseMode on sync mode, Portal Speed Setting +/- 20%
    } 
    else {
      ReefAngel.DCPump.Mode=modes[rmode];  // Put the mode to the random mode :)
      ReefAngel.DCPump.Speed=InternalMemory.DCPumpSpeed_read(); // Set speed from portal
    }
  } 
  else {
    ReefAngel.DCPump.UseMemory=true; // Will reset all values from memory
  }

  CustomExpansion(0x41,0,PWMParabola(8,10,18,20,5,95,1)); // Set channel 0 to parabola from 8:10am to 6:20pm with % from 5 to 95 and 1% when at night cycle.
  
  ////// Place your custom code above here

  // This should always be the last line
  ReefAngel.Portal( "heatdissipation" );
  ReefAngel.ShowInterface();
}
byte ElseMode( byte MidPoint, byte Offset, boolean WaveSync )
{
  // Static's only initialize the first time they are called
  static unsigned long LastChange=millis(); // Set the inital time that the last change occurred
  static int Delay = random( 500, 3000); // Set the initial delay
  static int NewSpeed = MidPoint; // Set the initial speed
  static int AntiSpeed = MidPoint; // Set the initial anti sync speed
  if ((millis()-LastChange) > Delay) // Check if the delay has elapsed
  {
    Delay=random(500,5000); // If so, come up with a new delay
    int ChangeUp = random(Offset); // Amount to go up or down
    if (random(100)<50) // 50/50 chance of speed going up or going down
    {
      NewSpeed = MidPoint - ChangeUp;
      AntiSpeed = MidPoint + ChangeUp;
    }
    else
    {
      NewSpeed = MidPoint + ChangeUp;
      AntiSpeed = MidPoint - ChangeUp;
    }
    LastChange=millis(); // Reset the time of the last change
  }
  if (WaveSync)
  {
    return NewSpeed;
  }
  else
  {
    return AntiSpeed;
  }
}

void CustomExpansion(byte id, byte channel, byte percentage)
{
  Wire.beginTransmission(id);
  Wire.write(0);
  Wire.write(0xa1);
  Wire.endTransmission();
  int newdata=(int)(percentage*40.95);
  Wire.beginTransmission(id);
  Wire.write(0x8+(4*channel));
  Wire.write(newdata&0xff);
  Wire.write(newdata>>8);
  Wire.endTransmission();
}


Roberto.
User avatar
heatdissipation
Posts: 52
Joined: Wed Aug 14, 2013 5:25 am

Re: 16 channel custom board code

Post by heatdissipation »

That sketch compiled fine, but only lit up channel one
User avatar
lnevo
Posts: 5422
Joined: Fri Jul 20, 2012 9:42 am

Re: 16 channel custom board code

Post by lnevo »

You need to add the rest of the channels. I think he only gave you one as an example

Code: Select all

 CustomExpansion(0x41,0,PWMParabola(8,10,18,20,5,95,1)); // Set channel 0 to parabola from 8:10am to 6:20pm with % from 5 to 95 and 1% when at night cycle.
User avatar
heatdissipation
Posts: 52
Joined: Wed Aug 14, 2013 5:25 am

Re: 16 channel custom board code

Post by heatdissipation »

So I need to repeat that line of code 15 more times substituting the "0" for each channel
User avatar
lnevo
Posts: 5422
Joined: Fri Jul 20, 2012 9:42 am

Re: 16 channel custom board code

Post by lnevo »

You got it and you can adjust the parabola arguments for each channel then as well. for % or times, etc.
User avatar
heatdissipation
Posts: 52
Joined: Wed Aug 14, 2013 5:25 am

Re: 16 channel custom board code

Post by heatdissipation »

(0x41,0,PWMParabola(8,10,18,20,5,95,1));

Which of the zeros are specifying the channel? I know what everything else is, but I am not sure what (0x41,0, means
User avatar
heatdissipation
Posts: 52
Joined: Wed Aug 14, 2013 5:25 am

Re: 16 channel custom board code

Post by heatdissipation »

One more thing, "8,10,18,20". That is specifying the time. From 810 am - 620 pm. What increments can I increase the time, can I do one minute increments and stagger them to create the sunrise and sunset?
User avatar
lnevo
Posts: 5422
Joined: Fri Jul 20, 2012 9:42 am

Re: 16 channel custom board code

Post by lnevo »

The 0 right before PWMParabola is the one that specifies the channel.

The rest you have correct. The 8 is hour the 10 is minutes same for 18:20. You can specify exactly what time using those 4 fields.

One thing you'll want to change maybe is the last argument the ,1. That will make the default for all channels 1% when not in the specified times. You may want that to be 0%
User avatar
heatdissipation
Posts: 52
Joined: Wed Aug 14, 2013 5:25 am

Re: 16 channel custom board code

Post by heatdissipation »

Thank you so much guys, I finally have my default sketch, all channels are lit up, pumps working great, now I can start playing around and getting creative, I still have a couple small problems to work out, my PH reads 1 and my salinity reads 6, but I havent really tried dialing them in yet. I did calibrate both, but something isnt working right there, just havent dug into it yet to see what it is.
User avatar
heatdissipation
Posts: 52
Joined: Wed Aug 14, 2013 5:25 am

Re: 16 channel custom board code

Post by heatdissipation »

This is my default sketch, I have all the times set like I want them for my lights, I realize there is some code for my pumps that I am not using in this sketch at the end, but I forgot to delete it when I compiled this sketch, everything works like I want it to, so I am considering this my default sketch.

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


////// 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 
  ReefAngel.AddSalinityExpansion();  // Salinity Expansion Module
  ReefAngel.AddPHExpansion();  // pH Expansion Module
  // Ports toggled in Feeding Mode
  ReefAngel.FeedingModePorts = Port4Bit;
  ReefAngel.FeedingModePortsE[0] = 0;
  // Ports toggled in Water Change Mode
  ReefAngel.WaterChangePorts = Port1Bit | Port4Bit;
  ReefAngel.WaterChangePortsE[0] = 0;
  // Ports toggled when Lights On / Off menu entry selected
  ReefAngel.LightsOnPorts = 0;
  ReefAngel.LightsOnPortsE[0] = 0;
  // Ports turned off when Overheat temperature exceeded
  ReefAngel.OverheatShutoffPorts = Port1Bit;
  ReefAngel.OverheatShutoffPortsE[0] = 0;
  // Use T1 probe as temperature and overheat functions
  ReefAngel.TempProbe = T1_PROBE;
  ReefAngel.OverheatProbe = T1_PROBE;

  // Feeeding and Water Change mode speed
  ReefAngel.DCPump.FeedingSpeed=0;
  ReefAngel.DCPump.WaterChangeSpeed=0;


  // Ports that are always on
  ReefAngel.Relay.On( Port4 );
  ReefAngel.Relay.On( Box1_Port3 );
  ReefAngel.Relay.On( Box1_Port4 );

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


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

void loop()
{
  ReefAngel.StandardHeater( Port1 );
  ReefAngel.MoonLights( Port5 );
  ReefAngel.DayLights( Port6 );
  ReefAngel.DosingPumpRepeat1( Box1_Port1 );
  ReefAngel.DosingPumpRepeat2( Box1_Port2 );
  ReefAngel.DCPump.UseMemory = true;
  ReefAngel.DCPump.DaylightChannel = None;
  ReefAngel.DCPump.ActinicChannel = None;
  ReefAngel.DCPump.ExpansionChannel[0] = None;
  ReefAngel.DCPump.ExpansionChannel[1] = Sync;
  ReefAngel.DCPump.ExpansionChannel[2] = AntiSync;
  ReefAngel.DCPump.ExpansionChannel[3] = AntiSync;
  ReefAngel.DCPump.ExpansionChannel[4] = None;
  ReefAngel.DCPump.ExpansionChannel[5] = None;
  ////// Place your custom code below here
  //Night Mode at 30%
  if (hour()<6 || hour()>=22) {
    ReefAngel.DCPump.UseMemory=false; 
    ReefAngel.DCPump.Mode=Constant; 
    ReefAngel.DCPump.Speed=30;
  }
   CustomExpansion(0x41,0,PWMParabola(7,10,21,30,5,95,1)); // Set channel 0 to parabola from 8:10am to 6:20pm with % from 5 to 95 and 1% when at night cycle.
   CustomExpansion(0x41,1,PWMParabola(7,12,21,28,5,85,0));
   CustomExpansion(0x41,2,PWMParabola(7,14,21,26,5,95,0));
   CustomExpansion(0x41,3,PWMParabola(7,16,21,24,5,95,1));
   CustomExpansion(0x41,4,PWMParabola(7,17,21,25,5,85,0));
   CustomExpansion(0x41,5,PWMParabola(7,18,21,25,5,95,0));
   CustomExpansion(0x41,6,PWMParabola(7,20,21,23,5,95,1));
   CustomExpansion(0x41,7,PWMParabola(7,22,21,22,5,85,0));
   CustomExpansion(0x41,8,PWMParabola(7,23,21,21,5,95,0));
   CustomExpansion(0x41,9,PWMParabola(7,24,21,20,5,85,0));
   CustomExpansion(0x41,10,PWMParabola(7,25,21,19,5,95,1));
   CustomExpansion(0x41,11,PWMParabola(7,26,21,18,5,85,0));
   CustomExpansion(0x41,12,PWMParabola(7,27,21,17,5,95,1));
   CustomExpansion(0x41,13,PWMParabola(7,40,21,05,50,100,5));
   CustomExpansion(0x41,14,PWMParabola(7,30,21,25,20,60,0));
   CustomExpansion(0x41,15,PWMParabola(7,02,21,15,20,60,0));
  ////// Place your custom code above here

  // This should always be the last line
  ReefAngel.Portal( "heatdissipation" );
  ReefAngel.ShowInterface();
}
byte ElseMode( byte MidPoint, byte Offset, boolean WaveSync )
{
  // Static's only initialize the first time they are called
  static unsigned long LastChange=millis(); // Set the inital time that the last change occurred
  static int Delay = random( 500, 3000); // Set the initial delay
  static int NewSpeed = MidPoint; // Set the initial speed
  static int AntiSpeed = MidPoint; // Set the initial anti sync speed
  if ((millis()-LastChange) > Delay) // Check if the delay has elapsed
  {
    Delay=random(500,5000); // If so, come up with a new delay
    int ChangeUp = random(Offset); // Amount to go up or down
    if (random(100)<50) // 50/50 chance of speed going up or going down
    {
      NewSpeed = MidPoint - ChangeUp;
      AntiSpeed = MidPoint + ChangeUp;
    }
    else
    {
      NewSpeed = MidPoint + ChangeUp;
      AntiSpeed = MidPoint - ChangeUp;
    }
    LastChange=millis(); // Reset the time of the last change
  }
  if (WaveSync)
  {
    return NewSpeed;
  }
  else
  {
    return AntiSpeed;
  }
}

void CustomExpansion(byte id, byte channel, byte percentage)
{
  Wire.beginTransmission(id);
  Wire.write(0);
  Wire.write(0xa1);
  Wire.endTransmission();
  int newdata=(int)(percentage*40.95);
  Wire.beginTransmission(id);
  Wire.write(0x8+(4*channel));
  Wire.write(newdata&0xff);
  Wire.write(newdata>>8);
  Wire.endTransmission();
}
User avatar
lnevo
Posts: 5422
Joined: Fri Jul 20, 2012 9:42 am

Re: 16 channel custom board code

Post by lnevo »

Wise to back it up here :) Great job in getting everything going. The ElseMode is an unused function so no harm or foul to leave it there, unless you have a standard RA.
User avatar
heatdissipation
Posts: 52
Joined: Wed Aug 14, 2013 5:25 am

Re: 16 channel custom board code

Post by heatdissipation »

Thanks for the words of encouragement, what may seem easy now was once tough to learn for everyone. I struggled more than I thought I would just figuring out this simple sketch. I can write and troubleshoot CNC code in my sleep, but this is all new to me, now to keep the two separated. I find myself wanting to put "if" and "else" statements in CNC code at work now. :-)
Post Reply