I have not tried to attach code before, so hopefully this will work. [edit] OK it worked. The attached file is the same code that is in the scroll box. I don't know which is preferable, so I did both.
With kudos to Bodini for the ides of reading out the values, I took it a bit further and made what I call a 'code fragment' for my library. This is probably all that I will ever do with LEDs because I find the other stuff more interesting to mess with.
NOTE: this code only covers the colors for LED (plus on/off for practical reasons). It will seem disjointed because I am showing multiples ways of doing things instead of making nice tidy lists. There are many other parameters that can be manipulated in the same way by simply changing the parameter name and using appropriate values. Bodini has posted a method to determine the actual values . . which may or may not match what is in the input box for the particular screen control in the Mach4 screen editor.
This is my first posting of actual code, so I'll provide a 'blurb' on how to look at it and use it for those unfamiliar with such things.
This code is shared here for anyone to use. Note that it is not a finished code intended to be 'run'. It probably would but everything would happen so fast it would not be useful.
For those who are not familiar with the Lua editor, you can step thru code one line at a time using the F11 key. It doesn't seem completely stable to me as it often will just quit for no apparent reason, but just use the dropdown menu and pick 'start debugging and then you can step thru using the F11 key. A small green triangle marks the line the interpreter is running at any given moment and when the code 'calls' a function it will jump to where that function is which may be far away from the line that calls it, but it will return to where it started after the function has finished executing.
If you want to stop 'debugging' go back to the drop down and click the obvious choice. Note that you must stop the debugging before you can edit (cut and paste).
-- Lua Code Fragment
-- © 2015 www.theCUBEstudio.com
-- color codes and usage for Mach4 screen LED
--color = scr.GetProperty('led10','Color')
--wx.wxMessageBox (color)
-- NOTE: color numbers are exponents
-- NOTE: color names red/green for LEDs is a state change that follows the On/Off state
-- NOTE: Parameter named 'Value' in an LED is the On/Off switch -- usage example below
-- Observation: The exponent value (color number) for Red/green and Yellow colors have equal delta
---------------- therefor could be used to create a 'stoplight' effect by calculating the color value
---------------- the exponent values are 0,1,and 2, so by using a default, the control value can be booleani
-- USAGE: color numbers can be imput expressly in the function -or-
--------- intuitive variables can be pre-defined - see example below -or-
--------- color number can be calculated and then used by either method
-- SYNTAX: scr.SetProperty('NameOfScreenControl','NameOfParameter','NewStringValue');
-- ****************** creating and loading Variables for each Color **********
--******************* (these are the actual correct values ******************
red = "0";
amber = "2";
blue = "4";
green = "8";
nocolor = tostring(2^4); -- string value saved is "16"
purple = tostring(2^6); -- string value saved is "32"
white = 64; -- example using numeric value - musyt be converted to string in the screen call
yellow = 128;
-- odd duck:
green_red = "9";
-- ************************ Variables for ON and OFF
ledON = "1"; --example of storing the variable as a string
ledOFF = 0; --can also be stored as a number
-- see examples below for the proper syntax for each method
-- *************************
-- example usage by string variable
scr.SetProperty('led10', 'Color', blue);
scr.SetProperty('led10', 'Value', '1'); -- note that a string value can be created 'on the fly'
scr.SetProperty('led10', 'Value', '0');
-- if numeric formula is pre-coverter to a string, just use the variable name
scr.SetProperty('led10', 'Color', purple);
scr.SetProperty('led10', 'Value', ledON);
scr.SetProperty('led10', 'Value', tostring(ledOFF));
-- if the Color variable contains a number, it must be converted to a string in the function call
scr.SetProperty('led10', 'Color', tostring(white));
scr.SetProperty('led10', 'Value', '1');
scr.SetProperty('led10', 'Value', '0');
--************************* Example using exponents
local i = 0;
for i = 0,7,1 do
--- color string value can be calculated and coverted on the fly
scr.SetProperty('led10', 'Color', tostring(2^i));
scr.SetProperty('led10', 'Value', '1');
scr.SetProperty('led10', 'Value', '0');
end
--************************* stoplight example ********************
StopLightColor = "";
UserInput = 0;
-- ********************************* set up a function to change the light
function ChangeStopLight()
-- wx.wxMessageBox (tostring(UserInput));
if (UserInput > 1) then
StopLightColor = tostring(128);
elseif (UserInput == 1) then
StopLightColor = tostring(8);
else
StopLightColor = tostring(0);
end
scr.SetProperty('led10', 'Color', StopLightColor);
scr.SetProperty('led10', 'Value', '1');
end
-- ****************************** simulate user input
for i = 0,2,1 do
-- wx.wxMessageBox (tostring(i));
scr.SetProperty('led10', 'Value','0');
UserInput = i;
ChangeStopLight()
end