Hw switch add

From Sim Innovations Wiki
Revision as of 11:51, 2 October 2018 by Admin (talk | contribs)
Jump to navigation Jump to search

Description

hw_switch_id = hw_switch_add(name, nr_pins, callback) (from AM 3.5)
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