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:
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