Switch get position

From Sim Innovations Wiki
Jump to navigation Jump to search


position = switch_get_position(hw_switch_id)

switch_get_position is used to get the current position of a switch.

Return value

Argument Type Description
position Integer The switch position.


# Argument Type Description
1 switch_id Object The is the reference to the switch. You can get this reference from the switch_add function.


-- Callback function which is called when the switch position changes
function position_changed(position)
  print("new position = " .. tostring(position) )

-- Bind to Raspberry Pi 2, Header P1, Pin 40
switch_id = switch_add("off.png", "on.png", 100,100,100,100,position_changed)

-- Read the current position
position = switch_get_position(switch_id)