Hello Guest it is May 11, 2021, 12:57:30 AM

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

0 Members and 1 Guest are viewing this topic.

#### joeaverage

• 6,406
##### 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!

#### thespindoctor

• 294
##### 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
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.

#### thespindoctor

• 294
##### 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?

#### joeaverage

• 6,406
##### 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!

#### thespindoctor

• 294
##### 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!

#### joeaverage

• 6,406
##### 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!

#### DazTheGas

• 753
• DazTheGas
##### 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

#### thespindoctor

• 294
##### 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!

#### Chaoticone

• 5,626
• Precision Chaos
##### 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`
If you could see the things I have in my head, you would be laughing too.

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

#### DazTheGas

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