Difference between revisions of "Hw switch add"

From Sim Innovations Wiki
Jump to navigation Jump to search
Line 11: Line 11:
! Argument !! Type !! Description
! Argument !! Type !! Description
|-
|-
| '''hw_switch_id ''' || ''Number'' || This value can be used for further reference.
| '''hw_switch_id ''' || ''ID'' || This value can be used for further reference.
|}
|}



Revision as of 14:22, 12 July 2018

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 ID This value can be used for further reference.

Arguments

# Argument Type Description
1 hw_id_0 String The is the reference to first switch input. You can choose to bind to an existing Hardware ID (Hardware_id_list).
2 hw_id_1 String The is the reference to the second switch input. You can choose to bind to an existing Hardware ID (Hardware_id_list).
n hw_id_n String The hw_id 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

-- 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)

Schematic example

Switch-pull-up.png