Page 1 of 1

Button overide for the pwm parabola

Posted: Tue Mar 13, 2012 1:23 pm
by sceia
Ok, so here's the situation... Got my pwm's running in the following setup:
//Light Schedule
ReefAngel.PWM.SetChannel(NW1,PWMParabola(14,0,19,0,15,80,15));
ReefAngel.PWM.SetChannel(NW2,PWMParabola(14,30,19,30,15,90,15));
ReefAngel.PWM.SetChannel(NW3,PWMParabola(15,0,20,0,15,80,15));
ReefAngel.PWM.SetChannel(Blue,PWMParabola(13,30,20,30,15,85,15));
ReefAngel.PWM.SetChannel(RB,PWMParabola(12,00,22,0,15,90,15));
ReefAngel.PWM.SetChannel(Red,PWMParabola(14,0,20,0,15,85,15));
ReefAngel.PWM.SetActinic(PWMParabola(13,30,20,30,15,85,15));
ReefAngel.PWM.SetDaylight(PWMParabola(13,30,20,30,15,95,15));
What I'd like to do is write the menu functions to allow me to manually turn on the led channels then put them back to the state they were at before me touching them. This would allow me to turn the whites on for a bit if I needed to display something... I'd like to be able to do this from the joystick on the controller as well as on the android app...

My actinic leds are all on the pwm expansion. My refuge led is on a powered port (8 port multistrip). It just needs a toggle of sorts.

Here's the menu functions I'm working on...
void MenuEntry6() //"Actinic LEDs"
{

}

void MenuEntry7() //"Night LEDs"
{

}

void MenuEntry8() //"Refuge LEDs"
{

}

void MenuEntry9() //"100% Daylight LEDs"
{

}

Re: Button overide for the pwm parabola

Posted: Tue Mar 13, 2012 1:54 pm
by binder
It's going to be a little complicated to do that...but not impossible. The reason is that the controller executes the commands in the loop() every second. The PWMParabola function is called every second and returns a value that is set to the LED channel. The way you would have to do it would be something like this....

Code: Select all

static bool fOverride = false;

//  ... menu entries
void MenuEntry6()
{
    fOverride = true;
    // ... set the channels on
}

// one entry to clear the override
void MenuEntry9()
{
    fOverride = false;
}

// void setup()

void loop()
{
  // ... other code here
  if ( ! fOverride )
  {
    // ... regular PWMSlope function
  }
  //  ... rest of code
}
That code skeleton is doing this:
1. it's declaring an override variable that you can set when you want.
2. when you set the override, it allows you to do whatever you want with the LED channels and the PWM slope functions will not override as long as you are in override mode. The rest of the tank will operate as normal and you will be in override mode until you exit.
3. you must exit override mode manually to return to the normally set / programmed scheme.

That's just an outline and hopefully it makes sense.

Re: Button overide for the pwm parabola

Posted: Tue Mar 13, 2012 1:58 pm
by sceia
I wonder if this would be a better solution to make a toggle:

Code: Select all

static bool fOverride = false;

//  ... menu entries
void MenuEntry6()
{
    if(fOverride)
            fOverride = true;
    else
            fOverride = false;
    // ... set the channels on
}

// void setup()

void loop()
{
  // ... other code here
  if ( ! fOverride )
  {
    // ... regular PWMSlope function
  }
  //  ... rest of code
}

Re: Button overide for the pwm parabola

Posted: Tue Mar 13, 2012 2:03 pm
by sceia
To cut down code, I could function that out...

Code: Select all

void ToggleFlag()
{
  if(fOverride)
         fOverride = true;
  else
         fOverride = false;
}
Then make a call to it in the menu functions...

Code: Select all

void MenuEntry6() //"Actinic LEDs"
{
  ToggleFlag();
    // ... set the channels on
}

Re: Button overide for the pwm parabola

Posted: Tue Mar 13, 2012 2:04 pm
by binder
It would work too but you have the logic flipped. Also, there could be a momentary switch / change in the PWM values as you toggle it. And you would have to choose the selection again to toggle it off. You would also not be able to switch from each menu commands without having to toggle again. Meaning if item 6 was all actinics and item 7 was all whites, if you had all actinics on from 6, then you couldn't just easily choose all whites on 7 and have the whites turn on. you would have to toggle the actinics off and then toggle the whites on.

Here's your logic that would be updated:

Code: Select all

if ( fOverride )
  fOverride = false;
else
  fOverride = true;

Re: Button overide for the pwm parabola

Posted: Tue Mar 13, 2012 2:10 pm
by sceia
binder wrote:It would work too but you have the logic flipped. Also, there could be a momentary switch / change in the PWM values as you toggle it. And you would have to choose the selection again to ...
Right, I got that. But without the ability of doing submenus, I'd have to use one menu for a reset. I would at minimum need 10 to do what I want in the menus... With 9 being the max, I'm limited...

Re: Button overide for the pwm parabola

Posted: Tue Mar 13, 2012 3:34 pm
by binder
True. I'm not saying it couldn't be done, just letting you know of how things could operate and function....that's all. :)

Re: Button overide for the pwm parabola

Posted: Tue Mar 13, 2012 4:09 pm
by rimai
Not sure if I understood correctly.
How many of the 8 channels you would like to overide?
And you would also like to toggle on/off the refugium lights, which is on Port 8, right?

Re: Button overide for the pwm parabola

Posted: Tue Mar 13, 2012 7:59 pm
by sceia
Refuge lights are on 2....

This is what I was thinking...

Code: Select all

static bool fOverride = false;
static bool rOverride = false;

.
.
.

prog_char menu1_label[] PROGMEM = "Feed Fish";
prog_char menu2_label[] PROGMEM = "Feed Coral";
prog_char menu3_label[] PROGMEM = "Water Change";
prog_char menu4_label[] PROGMEM = "ATO Clear";
prog_char menu5_label[] PROGMEM = "PH Calibration";
prog_char menu6_label[] PROGMEM = "Actinic LEDs";
prog_char menu7_label[] PROGMEM = "100% Daylight LEDs";
prog_char menu8_label[] PROGMEM = "Refuge LEDs";
prog_char menu9_label[] PROGMEM = "Storm Mode";

.
.
.
void TogglefOverride()
{
    if ( fOverride )
      fOverride = false;
    else
      fOverride = true;
}
 
void TogglerOverride()
{
    if ( rOverride )
      rOverride = false;
    else
      rOverride = true;
}

.
.
.

void MenuEntry6() //"Actinic LEDs"
{
  TogglefOverride();
    // ... set the channels on
  ReefAngel.PWM.SetChannel(NW1,15);
  ReefAngel.PWM.SetChannel(NW2,15);
  ReefAngel.PWM.SetChannel(NW3,15);
  ReefAngel.PWM.SetChannel(Blue,15);
  ReefAngel.PWM.SetChannel(RB,100);
  ReefAngel.PWM.SetChannel(Red,15);
  ReefAngel.PWM.SetActinic(15);
  ReefAngel.PWM.SetDaylight(15);
}
 
void MenuEntry7() //"100% Daylight LEDs"
{
  TogglefOverride();
  ReefAngel.PWM.SetChannel(NW1,90);
  ReefAngel.PWM.SetChannel(NW2,90);
  ReefAngel.PWM.SetChannel(NW3,90);
  ReefAngel.PWM.SetChannel(Blue,90);
  ReefAngel.PWM.SetChannel(RB,90);
  ReefAngel.PWM.SetChannel(Red,90);
  ReefAngel.PWM.SetActinic(90);
  ReefAngel.PWM.SetDaylight(90);
}
 
void MenuEntry8() //"Refuge LEDs"
{
  TogglefOverride();
}
 
void MenuEntry9() //"Storm
{
 
}

.
.
.
  //Light Schedule 
 if ( ! fOverride )
  {
        ReefAngel.PWM.SetChannel(NW1,PWMParabola(14,0,19,0,15,80,15));
        ReefAngel.PWM.SetChannel(NW2,PWMParabola(14,30,19,30,15,90,15));
        ReefAngel.PWM.SetChannel(NW3,PWMParabola(15,0,20,0,15,80,15));
        ReefAngel.PWM.SetChannel(Blue,PWMParabola(13,30,20,30,15,85,15));
        ReefAngel.PWM.SetChannel(RB,PWMParabola(12,00,22,0,15,90,15));
        ReefAngel.PWM.SetChannel(Red,PWMParabola(14,0,20,0,15,85,15));
        ReefAngel.PWM.SetActinic(PWMParabola(13,30,20,30,15,85,15));
        ReefAngel.PWM.SetDaylight(PWMParabola(13,30,20,30,15,95,15));
  }
 
  if ( ! rOverride )
        ReefAngel.Relay.On(Refuge);
  else
        ReefAngel.Relay.Off(Refuge);