Hw switch add
Jump to navigation
Jump to search
Description
hw_switch_id = hw_switch_add(hw_id_0, hw_id_1, hw_pos_n,callback)
switch_add is used to add a hardware switch. Every position on the switch should use one hardware input.
Return value
Argument | Type | Description |
---|---|---|
hw_switch_id | Number | This value can be used for further reference. |
Arguments
# | Argument | Type | Description |
---|---|---|---|
1 | hw_id_0 | String | The image for the first position. Note that this is both filename and extension. Its good practice to always use PNG format for images. JPG and BMP are also supported, but not recommended. |
2 | hw_id_1 | String | The image for the second position |
n | hw_id_n | String | The image for all other positions you might need. This is limitless |
n+1 | callback | Function | This function will be called when the switch changed position. |
Example 1 (X-plane determines switch position, recommended!)
-- This function is called every time the switch has a new position
function switch_callback(position)
print("The switch got changed to position " .. position)
end
-- Bind to Raspberry Pi 2, Header P1, Pin 38 and 40
hw_switch_add("RPI_V2_P1_38", "RPI_V2_P1_40", switch_callback)