Machine Red-green colour Status Light Macro

This is where you talk about Macros, show examples of your macro scripting and SHARE handy segments of script code as examples.

Re: Machine Red-green colour Status Light Macro

Postby marben » Sat Nov 21, 2020 7:29 am

dezsoe wrote:OK, here is a macroloop for flashing the output if reset is on. Save it as M2xxxx.txt and set as autorun in config/general/macroloop. Don't forget to set OutPort and OutPin constants!

Code: Select all
bool ResetState = exec.GetLED(25);
bool NewPinState;

if (ResetState != LastState)
{
  LastState = ResetState;
  Cnt = CntMax - 1;
}

if (ResetState)
{
  if (++Cnt == CntMax)
  {
    Cnt = 0;
    NewPinState = !LastPinState;
  }
  else
    NewPinState = LastPinState;
}
else
  NewPinState = false;

if (NewPinState != LastPinState)
{
  LastPinState = NewPinState;
  if (NewPinState)
    exec.Setoutpin(OutPort, OutPin);
  else
    exec.Clroutpin(OutPort, OutPin);
}

#Events

const int CntMax = 10;    // Flash speed in 50ms steps

const int OutPort = 2;    // Output port
const int OutPin = 2;     // Output pin

static int Cnt = 0;
static bool LastState = false;
static bool LastPinState = false;



HI, I've used this code in my setup, but is there any way to make the flashing equal? (same amount of time on and off?)
marben
 
Posts: 4
Joined: Sun Sep 23, 2018 9:20 am

Re: Machine Red-green colour Status Light Macro

Postby dezsoe » Mon Nov 23, 2020 6:57 am

It should be equal. A macroloop is called 20 times per second, the macroloop is set to change the output every 10 loops. There's no difference, the same code turns it on and off.
dezsoe
 
Posts: 1219
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary

Previous

Return to Macros

Who is online

Users browsing this forum: No registered users and 2 guests