Picking an Internal memory location for customized feature?

Do you have a question on how to do something.
Ask in here.
Post Reply
00Warpig00
Posts: 289
Joined: Wed May 16, 2012 9:52 pm

Picking an Internal memory location for customized feature?

Post by 00Warpig00 »

So I have set up a custom menu. On my custom menu I built in three options to mask various Dimming module ports.

Mask LED's On
Mask LED's Off
Remove LED Mask

This allows me to set a byte to 1/0 depending on whether I am masking or not. When I am masked on/off the byte is 1 when there is no mask the byte is 0. this works a treat from the controller menu but I would like to flip the mask on/off from the Android app using an internal memory location. I have searched and found the memory mapping of the locations and noticed some gaps in the memory location numbering. i do not want to mess with the current locations but need a location to control my byte remotely. I think i can handle all the coding to accomplish this but I have no idea what internal memory location to use. Do I just pick a number from the thin air? Again i do not want to mess up the controllers current function. are there any "User assigned" as opposed to "controller reserved" memory location's I can use for this?

Nick
180G FOWLR
20GH QT#1
29G QT#2

Image
binder
Posts: 2865
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
Contact:

Re: Picking an Internal memory location for customized featu

Post by binder »

Use any location under 200 (0 - 199). From 200 onward is for the system memory locations. The "old" locations were from 800 onward.
Anyways, under 200 wasn't / isn't designed for anything and I believe was left open for user locations.
00Warpig00
Posts: 289
Joined: Wed May 16, 2012 9:52 pm

Re: Picking an Internal memory location for customized featu

Post by 00Warpig00 »

Cool, thanks Curt for the quick response. Back to coding\testing I guess. This should be a quick and easy one I already have 95% of it coded and tested just needed to know about the memory locations.

:)

Nick

PS also just noticed my Salinity in my DT is finally below 30.0 ppt and my code that I tested to swap ATO ports from my RO topoff Brute to my SW Waterchange Brute flipped to the SW port without a hitch. It's one thing when you test for it and it works... quite another when you see it happen in a real environment. :)
180G FOWLR
20GH QT#1
29G QT#2

Image
binder
Posts: 2865
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
Contact:

Re: Picking an Internal memory location for customized featu

Post by binder »

awesome! :)
00Warpig00
Posts: 289
Joined: Wed May 16, 2012 9:52 pm

Re: Picking an Internal memory location for customized featu

Post by 00Warpig00 »

Ran into one snag. I broke my menu driven code but the update from the Android app works perfect.
Now that I read from the memory location 199 the Android app works perfectly. Problem is that now in my function that sets the byte from my custom menu needs to write that byte to the memory since I now read the memory location to initialize the variable. I figured this to be as easy as InternalMemory.write(199) but that does not work. I get a compile error. something... write does not exist... Is there no way to write to the memory from the arduino code or am i suffering from the Syntax blues again... lol

Nick
180G FOWLR
20GH QT#1
29G QT#2

Image
binder
Posts: 2865
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
Contact:

Re: Picking an Internal memory location for customized featu

Post by binder »

You are almost correct with the syntax. You need to specify a value to write to the location and not just the location. Try this instead:

Code: Select all

InternalMemory.write(199, 1);
Instead of 1, you can use any value from 0-255.
00Warpig00
Posts: 289
Joined: Wed May 16, 2012 9:52 pm

Re: Picking an Internal memory location for customized featu

Post by 00Warpig00 »

binder wrote:You are almost correct with the syntax. You need to specify a value to write to the location and not just the location. Try this instead:

Code: Select all

InternalMemory.write(199, 1);
Instead of 1, you can use any value from 0-255.
Thanks Curt, all is working perfectly now. yes I had the syntax wrong I was trying to set initialize a variable using...

InternalMemory.write(199) = LEDMask;

when the correct way was...

InternalMemory.write(199, LEDMask);

Cool thing is I realized I don't even need the variable LEDMask at all, I just use

InternalMemory.write(199, 0);
InternalMemory.write(199, 1);
InternalMemory.write(199, 2);
to set my appropriate value. for each menu item and then read that value on the fly in my

if/else statement.

for anyone interested here is the code I added. My custom menu code including my Dimming Module MASK code.

this gives me a custom menu and allows me to mask on/off/clear my LED's at any time from the controller menu or by manipulating internal memory location 199 from the Android app. NOTE: The AC cords on my Dimmers are NOT PLUGGED into my relay box but directly into constant power. I wanted it this way on purpose. Why waste two valuable relay ports. Now I can turn on/off my lights while on business trips and spy my tank at any hour via my webcam to be sure everything is looking normal as well as force the lights off when watching a movie on the projector in the next room. That actinic spectrum really reflects off my movie screen ;)

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


Nick
180G FOWLR
20GH QT#1
29G QT#2

Image
Post Reply