Page 1 of 1

how to code "Lights ON" day or night

Posted: Sun Dec 02, 2012 8:03 pm
by bigHUN
"Lights ON" 100% regardsless of day or night and "Lights OFF" can jump back whatever it was last time.
I see that I have now DP=90 AP=0 on the RA+ controller but I don't know what that means, I was trying things not sure how supposto be....
I navigate to and turn "Lights ON", I can see my relay ports 3 and 4 came on, the LEDs just blink once and dark (10 at evening).
I would need this when I get home, the lights started dimming down but not entirely off yet, and I need to do things in the tank.....
here is what I have now:

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
  ReefAngel.SetTemperatureUnit( Celsius );  // set to Celsius Temperature

  ReefAngel.AddStandardMenu();  // Add Standard Menu

    // Ports toggled in Feeding Mode
  ReefAngel.FeedingModePorts = Port1Bit | Port8Bit;
  // Ports toggled in Water Change Mode
  ReefAngel.WaterChangePorts = Port1Bit | Port5Bit | Port6Bit | Port8Bit;
  // Ports toggled when Lights On / Off menu entry selected
  ReefAngel.LightsOnPorts = Port3Bit | Port4Bit | Port5Bit | Port6Bit | Port8Bit;
  // Ports turned off when Overheat temperature exceeded
  ReefAngel.OverheatShutoffPorts = 0;
  // Use T1 probe as temperature and overheat functions
  ReefAngel.TempProbe = T1_PROBE;
  ReefAngel.OverheatProbe = T1_PROBE;
  // Set the Overheat temperature setting
  InternalMemory.OverheatTemp_write( 270 );


  // Ports that are always on
  ReefAngel.Relay.On( Port7 );
  ReefAngel.Relay.On( Port8 );

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

  ReefAngel.Timer[1].SetInterval(60);

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

void loop()
{
//  ReefAngel.StandardATO( Port1,62 );
  ReefAngel.StandardHeater( Port2,240,255 );
  ReefAngel.StandardLights( Port3,8,55,20,5 );
  ReefAngel.StandardLights( Port4,9,55,17,05 );
  if (hour()>=10 && hour()<19)
  {
    ReefAngel.Wavemaker( Port5,5 );
    ReefAngel.Relay.Set(Port6,!ReefAngel.Relay.Status(Port5));
  }
  else
  {
    ReefAngel.Relay.Off(Port5);
    ReefAngel.Relay.Off(Port6);
  }
    ReefAngel.PWM.SetChannel( 0, PWMSlope(9,1,19,59,0,100,35,0) );
    ReefAngel.PWM.SetChannel( 1, PWMSlope(10,2,16,58,0,100,20,0) );
    ReefAngel.PWM.SetChannel( 2, PWMSlope(11,3,14,57,0,100,20,0) );
    ReefAngel.PWM.SetChannel( 3, PWMSlope(15,34,19,36,0,70,20,0) );
    ReefAngel.PWM.SetChannel( 4, PWMSlope(18,5,23,58,0,100,20,0) );
//  ReefAngel.PWM.SetChannel( 5, PWMSlope(10,0,19,45,90,100,1,90) );
  
  ////// Place your custom code below here

  //Float #1

  if (ReefAngel.IO.GetChannel(1)) // if float 1 is triggered
  {
    ReefAngel.Relay.Off(Port8); // Turn Return off
    ReefAngel.Relay.Off(Port7); // Turn Skimmer off
    BuzzerOn(); // Turn Buzzer on
  }

  //Float #2
  if (ReefAngel.IO.GetChannel(2)) // if float 2 is triggered
  {
    ReefAngel.Relay.On(Port1); // Turn AutoTopOff on
    ReefAngel.Timer[1].Start(); // Start/Trigger timer
  }

  // Float #3
  if (ReefAngel.IO.GetChannel(3)) // if float 3 is triggered
    BuzzerOn(); // Turn Buzzer on

    // Float #4
  // if (ReefAngel.IO.GetChannel(4)) // if float 4 is triggered
  //   ReefAngel.Relay.On(Port7); // Turn Skimmer off

  // Float #5
  // if (ReefAngel.IO.GetChannel(5)) // if float 5 is triggered
  {
  // ReefAngel.Relay.Off(Port8); // Turn Return off  
  //  BuzzerOn(); // Turn Buzzer on
  } 

  // Timer 1
  if (ReefAngel.Timer[1].IsTriggered())
    ReefAngel.Relay.Off(Port1); // Turn AutoTopOff off


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

  // This should always be the last line
  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();

  // I/O Expansion
  byte bkcolor;
  x = 14;
  y = 39;
  for ( int a=0;a<6;a++ )
  {
    ReefAngel.LCD.DrawCircleOutline( x+(a*20),y,4,COLOR_MEDIUMORCHID );
    if ( ReefAngel.IO.GetChannel(a) ) bkcolor=COLOR_WHITE; 
    else bkcolor=COLOR_GRAY;
    ReefAngel.LCD.FillCircle( x+(a*20),y,2,bkcolor );
  }
  pingSerial();

  // Parameters
#if defined DisplayLEDPWM && ! defined RemoveAllLights
  ReefAngel.LCD.DrawMonitor( 15, 53, ReefAngel.Params,
  ReefAngel.PWM.GetDaylightValue(), ReefAngel.PWM.GetActinicValue() );
#else // defined DisplayLEDPWM && ! defined RemoveAllLights
  ReefAngel.LCD.DrawMonitor( 15, 53, 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, 90, TempRelay );
  pingSerial();

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

void DrawCustomGraph()
{
}

void BuzzerOn()
{
  ReefAngel.PWM.SetActinic((now()%2)*100);
}

Re: how to code "Lights ON" day or night

Posted: Sun Dec 02, 2012 9:51 pm
by 00Warpig00
I did this with my controller, but I'm not sure what you are asking is the same as what I am doing.

... a little about my setup. I have RA+ and have PWM drivers connected to a dimming module and drive the brightness lights on/off completely via that module. My AC main power for my lights is plugged into an always on source so my lights do not use ports on my relay box, only ports on my PWM module.

It seems from your post that you are driving your lights brightmess on/off using the two analog\pwm ports on the relay box and not AC power relay ports. Is that correct?

If so what I did should work for you but only need to be modified to drive the correct pwm\analog ports on the RA+ instead of the dimming (pwm) module like I use.

The way I did this was to set a byte in the RA+ memory (I used memory location 199)
you will need a way to manipulate that byte in the memory location to change it's value. I went overboard and did a custom menu with override lights on/off/normal. My menu manipulates that byte of data in memory location 199 and I also use the android app to manipulate that byte.

Here is a link to my thread that covers this.

http://forum.reefangel.com/viewtopic.php?f=12&t=2142

Here is my code from that thread. I will try to comment it a bit for you to give you the idea but I don't have much time to comment it all out right now.

Take a look... Feel free to ask questions mind you my code below adds MY custom menu and the code to toggle my lights on/off/normal. If you want to use the android app to manipulate the byte it's pretty simple. If you want to change it from the controller I think you will need to do a custom menu.

CUSTOM MENU AND ANDROID CONTROL

Code: Select all


    //*****Begin Custom Menu Additions (DEFINITIONS)

    #include <avr/pgmspace.h>
    prog_char menu1_label[] PROGMEM = "Mask LED's On";
    prog_char menu2_label[] PROGMEM = "Mask LED's Off";
    prog_char menu3_label[] PROGMEM = "Mask LED's Clear";
    prog_char menu4_label[] PROGMEM = "Water Change";
    prog_char menu5_label[] PROGMEM = "Clear ATO Timeout";
    prog_char menu6_label[] PROGMEM = "Overheat Clear";
    prog_char menu7_label[] PROGMEM = "PH Calibration";
    prog_char menu8_label[] PROGMEM = "Date / Time";

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

    //*****End Custom Menu Additions


    //*****Begin Custom Menu Additions... Initialize Custom Menu (SETUP)

        ReefAngel.InitMenu(pgm_read_word(&(menu_items[0])),SIZE(menu_items));   
        InternalMemory.write(199, 0); //sets the controller to non masked LED mode upon boot.   

    //*****End Custom Menu Additions


    //*****Begin Custom Menu Additions (LOOP)

      // Removes LED's from a "MASKED" State
      if ( InternalMemory.read(199) == 0 )
        {
          ReefAngel.PWM.SetChannel( 0, PWMParabola(14,0,23,59,1,100,1) ); //Sets LED Drivers on Ch0 to Parabola math
          ReefAngel.PWM.SetChannel( 1, PWMParabola(14,0,23,59,1,100,1) ); //Sets LED Drivers on Ch1 to Parabola math
          ReefAngel.PWM.SetChannel( 3, PWMSlope(2,0,7,30,0,50,0,0) ); //Opens/closes 5V relay on Ch3 that shorts\opens dimmer leads on Ch0 LED driver to turn Driver on/off
          ReefAngel.PWM.SetChannel( 4, PWMSlope(0,0,14,0,0,50,0,0) ); //Opens/closes 5V relay on Ch4 that shorts\opens dimmer leads on Ch1 LED driver to turn Driver on/off
        }

      // MASKS LED's Off
      if ( InternalMemory.read(199) == 1 )
        {
          ReefAngel.PWM.SetChannel( 0, 0 ); //Sets LED Drivers on Ch0 to 0%
          ReefAngel.PWM.SetChannel( 1, 0 ); //Sets LED Drivers on Ch1 to 0%
          ReefAngel.PWM.SetChannel( 3, 50 ); //closes 5V relay on Ch3 that shorts dimmer leads on Ch0 LED driver to turn Driver off
          ReefAngel.PWM.SetChannel( 4, 50 ); //closes 5V relay on Ch4 that shorts dimmer leads on Ch1 LED driver to turn Driver off
        }

      if ( InternalMemory.read(199) == 2 )
        {
          ReefAngel.PWM.SetChannel( 0, 100 ); //Sets LED Drivers on Ch0 to 100%
          ReefAngel.PWM.SetChannel( 1, 100 ); //Sets LED Drivers on Ch1 to 100%
          ReefAngel.PWM.SetChannel( 3, 0 ); //Opens 5V relay on Ch3 that removes short on dimmer leads on Ch0 LED driver to turn Driver on
          ReefAngel.PWM.SetChannel( 4, 0 ); //Opens 5V relay on Ch4 that removes short on dimmer leads on Ch1 LED driver to turn Driver on
        }

      else
        {
        }
           
    //*****End Custom Menu Additions


    //*****Begin Custom Menu Additions (CUSTOM MENU FUNCTIONS)

    //Mask LED's On. Forces LED's On Full Blast
    void MenuEntry1()
      {
        InternalMemory.write(199, 2);
        ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "                      ");
        ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "Mask Lights On"); waitForTime(2);
        ReefAngel.DisplayedMenu = RETURN_MAIN_MODE;
      }

    //Mask LED's Off. Forces LED's Off
    void MenuEntry2()
      {
        InternalMemory.write(199, 1);
        ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "                      ");
        ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "Mask Lights Off"); waitForTime(2);
        ReefAngel.DisplayedMenu = RETURN_MAIN_MODE;
      }

    //Mask LED's Clear. Remove LED Masking Returns LED's To Normal Schedule
    void MenuEntry3()
      {
        InternalMemory.write(199, 0);
        ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "                      ");
        ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "Mask Lights Clear"); waitForTime(2);
        ReefAngel.DisplayedMenu = RETURN_MAIN_MODE;
      }
     
    //Start Waterchange Mode
    void MenuEntry4()
      {
        ReefAngel.WaterChangeModeStart();
      }

    //Clear ATO Timeout Flag
    void MenuEntry5()
      {
        ReefAngel.ATOClear();
        ReefAngel.DisplayMenuEntry("Clear ATO Timeout");
      }

    //Clear Overheat Flag
    void MenuEntry6()
      {
        ReefAngel.OverheatClear();
        ReefAngel.DisplayMenuEntry("Clear Overheat");
      }

    //Calibrate PH Probe
    void MenuEntry7()
      {
        ReefAngel.SetupCalibratePH();
        ReefAngel.DisplayedMenu = ALT_SCREEN_MODE;
      }

    //Set clock Date & Time
    void MenuEntry8()
      {
        ReefAngel.SetupDateTime();
        ReefAngel.DisplayedMenu = ALT_SCREEN_MODE;
      }
     
    void waitForTime(int seconds)
    {
        bool done = false;
        tm.SetInterval(seconds);
        tm.Start();
        int t = tm.Trigger - now();
        do
        {
          // check the wifi interface
          pingSerial();
          // wait for specified seconds
          if ( (t >= 0) && ! tm.IsTriggered() )
            {
              // TODO finish countdown on screen
              // show countdown on screen
              //LCD.Clear(DefaultBGColor,60+(intlength(t)*5),100,100,108);
              //LCD.DrawText(DefaultFGColor,DefaultBGColor,60,100,t);
              wdt_reset();
              delay(200);
            }
            else
            {
              done = true;
            }
        } while ( !done );
        return;
    }

    //*****End Custom Menu Additions


If you want to manipulate the memory location using android app or client you need much less code

Code: Select all


    //***** add to setup

        InternalMemory.write(199, 0); //sets the controller to non masked LED mode upon boot.   

    //*****End Additions


    //*****add to loop
   //***** this is the MEAT of the concept below Checks the Byte value of memory location 199
   //*****does an if/else based on the value. 0 = normal unmasked. 1 = masked off. 2 = Masked on.
   //*****your code will need to change based on your "normal lighting" as well as which ports are used but this
   //*****is the concept.  

      // Removes LED's from a "MASKED" State
      if ( InternalMemory.read(199) == 0 )
        {
          ReefAngel.PWM.SetChannel( 0, PWMParabola(14,0,23,59,1,100,1) ); //Sets LED Drivers on Ch0 to Parabola math
          ReefAngel.PWM.SetChannel( 1, PWMParabola(14,0,23,59,1,100,1) ); //Sets LED Drivers on Ch1 to Parabola math
          ReefAngel.PWM.SetChannel( 3, PWMSlope(2,0,7,30,0,50,0,0) ); //Opens/closes 5V relay on Ch3 that shorts\opens dimmer leads on Ch0 LED driver to turn Driver on/off
          ReefAngel.PWM.SetChannel( 4, PWMSlope(0,0,14,0,0,50,0,0) ); //Opens/closes 5V relay on Ch4 that shorts\opens dimmer leads on Ch1 LED driver to turn Driver on/off
        }

      // MASKS LED's Off
      if ( InternalMemory.read(199) == 1 )
        {
          ReefAngel.PWM.SetChannel( 0, 0 ); //Sets LED Drivers on Ch0 to 0%
          ReefAngel.PWM.SetChannel( 1, 0 ); //Sets LED Drivers on Ch1 to 0%
          ReefAngel.PWM.SetChannel( 3, 50 ); //closes 5V relay on Ch3 that shorts dimmer leads on Ch0 LED driver to turn Driver off
          ReefAngel.PWM.SetChannel( 4, 50 ); //closes 5V relay on Ch4 that shorts dimmer leads on Ch1 LED driver to turn Driver off
        }

      if ( InternalMemory.read(199) == 2 )
        {
          ReefAngel.PWM.SetChannel( 0, 100 ); //Sets LED Drivers on Ch0 to 100%
          ReefAngel.PWM.SetChannel( 1, 100 ); //Sets LED Drivers on Ch1 to 100%
          ReefAngel.PWM.SetChannel( 3, 0 ); //Opens 5V relay on Ch3 that removes short on dimmer leads on Ch0 LED driver to turn Driver on
          ReefAngel.PWM.SetChannel( 4, 0 ); //Opens 5V relay on Ch4 that removes short on dimmer leads on Ch1 LED driver to turn Driver on
        }

      else
        {
        }
           
    //*****End addition


Your code will vary because I dont know what ports you are using for what and how you are set up, but if you need to i may be able to help you with the details later. But this concept works. The top code box for custom menu manipulation AND android/client manipulation. The bottom code if you just want to manipulate the byte from the Android app/client.

What it does...

in the loop it checks the memory location constantly. It will be at 0 normally which if you look at the if/else statements in the code in my set up the 0 value tells my controller to do your normal PWM parabola thing which is calculated so going back to a 0 value for the byte will put your lights right back how they were. If the value is 1 it forces the lights to 0% (I also use two relays to open/short dimmer leads because my drivers are not really off when at 0% you may not need this) if the value is 2 if makes sure the dimmer leads are in the correct state and forces brightness to 100%. each time through the loop the value is checked and if manipulated and changed it sends you through the corresponding if/else statement. In the setup portion I also force the byte to be 0 or normal so if the controller resets the lights go back to normal non masked mode upon controller boot.



Nick

Re: how to code "Lights ON" day or night

Posted: Mon Dec 03, 2012 5:58 am
by bigHUN
Thanks 00 for the post, I see now what is missing:
- DIY LED with 60 LEDs; 4 dimmable meanwhel; 2+2 drivers connected to relay 5 and 6 (timing programmed); dimmable module (5 channels in use, timing programmed); getting DC power plugged to wall outlet (permanent); RA+ with stock menus generated by Wizzard. No Wifi and android, and right now I just have an issue the Client is not working again...
The purpose I am asking:
- I don't have time during day, only home for night, not much light to work with..
- when I built the DIY I didn't finished to finetune the milli Apms on drivers and I just swap the LED bundles around over the weekend, may happen that maxing out the 750 mA's ?
- last night finishing touch to wires, noticed my baby BT anemony got pcycho, last ime this happened my 12" anemony ran through the big Polario pump....the tank got nuked in a moment....so, now I will find a little bugger with flashlight or will have to remove 180 lbs or rock again?
- I don't need anything fancy, just a full light for emergency...
- there is a submenu on second screen, Lights ON/OFF, can that be modded in the way to have all dimming channels up to 100% regardless of daylight or night-dark is the current situation?
Thanks in advance

Re: how to code "Lights ON" day or night

Posted: Mon Dec 03, 2012 6:18 am
by rimai
No, that option only overrides the standard dimming channels automatically.
If you want to override the dimming expansion module, you need to create a custom menu just like it was posted above.

Re: how to code "Lights ON" day or night

Posted: Mon Dec 03, 2012 8:57 am
by bigHUN
Roberto? what the DP AP does? what numbers shall I have there? thanks

Re: how to code "Lights ON" day or night

Posted: Mon Dec 03, 2012 10:08 am
by rimai
Daylight PWM and Actinic PWM.
They are the 2 standard PWM channels on the side of the relay box.
I think you are using the actinic for your buzzer, right?

Re: how to code "Lights ON" day or night

Posted: Mon Dec 03, 2012 1:19 pm
by bigHUN
the buzzer is not connected yet.....
very first night when I did the first code from wizard, I had the "Lights ON/OFF" working, but is was dimm, about 15% ???
I didn't changed the wires, but I mess with the codes. Tried the parabola first than the slope.
as I sad, when I turn "Lights ON" now just a blink (all LEDs) and nothing happens further.

Re: how to code "Lights ON" day or night

Posted: Mon Dec 03, 2012 4:11 pm
by rimai
I think the easiest solution for you right now is this:
Replace this:

Code: Select all

    ReefAngel.PWM.SetChannel( 0, PWMSlope(9,1,19,59,0,100,35,0) );
    ReefAngel.PWM.SetChannel( 1, PWMSlope(10,2,16,58,0,100,20,0) );
    ReefAngel.PWM.SetChannel( 2, PWMSlope(11,3,14,57,0,100,20,0) );
    ReefAngel.PWM.SetChannel( 3, PWMSlope(15,34,19,36,0,70,20,0) );
    ReefAngel.PWM.SetChannel( 4, PWMSlope(18,5,23,58,0,100,20,0) );
//  ReefAngel.PWM.SetChannel( 5, PWMSlope(10,0,19,45,90,100,1,90) );
With this:

Code: Select all

    ReefAngel.PWM.SetChannel( 0, PWMSlope(9,1,19,59,0,100,35,100) );
    ReefAngel.PWM.SetChannel( 1, PWMSlope(10,2,16,58,0,100,20,100) );
    ReefAngel.PWM.SetChannel( 2, PWMSlope(11,3,14,57,0,100,20,100) );
    ReefAngel.PWM.SetChannel( 3, PWMSlope(15,34,19,36,0,70,20,100) );
    ReefAngel.PWM.SetChannel( 4, PWMSlope(18,5,23,58,0,100,20,100) );
//  ReefAngel.PWM.SetChannel( 5, PWMSlope(10,0,19,45,90,100,1,100) );
This will force the dimming channels to be at 100% when it is night period, but since the drivers are actually being turned off with the relay, you will get the lights on you wish when you turn them on.

Re: how to code "Lights ON" day or night

Posted: Tue Dec 04, 2012 7:35 am
by bigHUN
:)
thanks Roberto