Did you guys ever figure this out some way other than the table way?
I have a PoKeys 57E. This is a lua file being run from the PLC script.
here is my code, and my analog pot works but goes DOWN to 0% and UP to 150%. Usable, but not perfect.
That 40*60 was derived by guess and by gosh!! Not the scientific method.
--Function to read value from analog register
function ReadRegister(device, analogPin)
local inst = mc.mcGetInstance()
local hreg = mc.mcRegGetHandle(inst, string.format("%s/Analog input %s", device, analogPin))
return mc.mcRegGetValueString(hreg)
end
--Function to set SRO value
function SetSRO(analog)
local percent = analog/40*60 --calculate percentage
local inst = mc.mcGetInstance()
mc.mcSpindleSetOverride(inst, percent)
end
--Main body -
local device = "PoKeys57" --Change this to the name of your PoKeys device
local analogPin = "44" --Analog input pin number on PoKeys
analogVal = ReadRegister(device, analogPin) --Save analog register value in variable
SetSRO(analogVal) -- Set SRO value in %
It seems the line that says:
local percent = analog/40*60 --calculate percentage
Should say something like:
local percent = analog/((1*100) +.5) --calculate percentage
Do the 0 to 100, add .5, inferred to in the post above, but it doesn't work. I've tried different ways of doing the math, but apparently I can't do that or there's another convention I haven't discovered.
I've tried:
local percent = analog/1*100+.5
local percent = .5 + analog/1*100
local percent = (.5) + (analog/1*100)
I probably have to do the math outside that line, but I tried a couple ways to do that and can't figure it out!!
I'm sure I'm missing some basic programming convention here, but.....I can't get it.
Any ideas?
Tom