Hello Guest it is July 12, 2020, 04:26:54 PM

Author Topic: Lua programming of voltage meter  (Read 2731 times)

0 Members and 1 Guest are viewing this topic.

Re: Lua programming of voltage meter
« Reply #20 on: February 19, 2018, 06:32:14 AM »
Hi,
could you not store, in a table, the last twenty results and average those, I think the average function can be built into the table.
Then on each run thru the PLC one new data point is added to the table and the oldest, the 21st, gets dropped. Running average?

Craig
My wife left with my best friend...
     and I miss him!
Re: Lua programming of voltage meter
« Reply #21 on: February 19, 2018, 06:46:45 AM »
Craig,

I set up an if statement with a new counter called sweep in the PLC script so that
each time it sweeps, it reads the analog input then if sweep is <=20 it adds that value to a new variable.
Then when sweeps is over 20, it averaged that variable zeros it then set thes sweep counter back to 0.

Seems to work great with the value set to another gauge.
Re: Lua programming of voltage meter
« Reply #22 on: February 19, 2018, 06:48:10 AM »
Having trouble with getting an LED to light up with these analog inputs.
Is there a trick here?
Re: Lua programming of voltage meter
« Reply #23 on: February 19, 2018, 07:07:45 AM »
Hi,
what LED? LEDs are on or off, an analogue value is in this case a 12 bit numerical value, how is an LED supposed to reflect that?

Craig
My wife left with my best friend...
     and I miss him!
Re: Lua programming of voltage meter
« Reply #24 on: February 19, 2018, 07:14:11 AM »
Ok, that makes sense.  I will try a work around to turn on the led if the value of the input is over 0.

Thanks!
Re: Lua programming of voltage meter
« Reply #25 on: February 19, 2018, 07:19:00 AM »
Hi,
you could turn the LED on if greater than 50% and off if less than 50%

if (value>=2048) then
     LED=on
else
     LED=off
end

Craig
My wife left with my best friend...
     and I miss him!

Offline DazTheGas

*
  •  752 752
  • DazTheGas
    • View Profile
Re: Lua programming of voltage meter
« Reply #26 on: February 19, 2018, 08:45:29 AM »
Think that should be if value ~= 0 then turn on LED

DazTheGas

Theres always time for a choccy biccy
Re: Lua programming of voltage meter
« Reply #27 on: February 19, 2018, 09:42:58 AM »
No matter what I do I can’t get an Led to turn on.  I am trying to set property value to “On” even with a separate button. I believe I saw a past discussion in the past about Leds being difficult.

I am happy with my new command of meters and guages though!  Thanks for the help!

Offline Chaoticone

*
  • *
  •  5,629 5,629
  • Precision Chaos
    • View Profile
Re: Lua programming of voltage meter
« Reply #28 on: February 19, 2018, 10:20:08 AM »
No problem toggling a LED here.

You want to set it to 1 or 0

Code: [Select]
local TestState = scr.GetProperty("ledTest1", "Value")

if TestState == "1" then
scr.SetProperty("ledTest1", "Value", "0")
else
scr.SetProperty("ledTest1", "Value", "1")
end
;D If you could see the things I have in my head, you would be laughing too. ;D

My guard dog is not what you need to worry about!

Offline DazTheGas

*
  •  752 752
  • DazTheGas
    • View Profile
Re: Lua programming of voltage meter
« Reply #29 on: February 19, 2018, 10:23:44 AM »
Try a different way,

1.  Add LED to screen.
2. Assign it to an output thats not being used IE Output 63
3. Turn On and Off using mc.mcSignalSetState (mc.mcSignalGetHandle ( inst ,mc.OSIG_OUTPUT63  ), 1) = ON and mc.mcSignalSetState (mc.mcSignalGetHandle ( inst,mc.OSIG_OUTPUT63  ), 0) = OFF

I have many LED`s setup in this way.

DazTheGas
Theres always time for a choccy biccy