I’m trying to set up an analog input in Mach4hobby by following this well written tutorial from Poscope.
https://blog.poscope.com/mach4-tutorial-fro-using-analog-input/ The registers are setup and showing the analog value as 0 to 1 for 0 to 3.3 volts.
The device name = PokeysCNC_41744. Analog pin = 41.
I have this code in the screen load script.
--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 FRO value
function SetFRO(analog)
local percent = analog/1*250 --calculate percentage from 0% to 250%
local inst = mc.mcGetInstance()
mc.mcCntlSetFRO(inst, percent)
end
--Main
local device = "PokeysCNC_41744" --Change this to the name of your PoKeys device
local analogPin = "41" --Analog input pin number
analogVal = ReadRegister(device, analogPin) --Save analog register value in variable
SetFRO(analogVal) -- Set FRO value in %
This is the error I get when saving the screen edit. See picture
It looks like it’s trying to do arithmetic on a string. How can I correct this?
This post seems to use the same code with no problem.
https://www.machsupport.com/forum/index.php?topic=34051.msg238477#msg238477Thanks for any help.