Description
hw_button_id = hw_button_add(name, pressed_callback, released_callback) (from AM/AP 3.5)
hw_button_id = hw_button_add(hw_id, pressed_callback, released_callback)
hw_button_add is used to add a hardware button to your instrument.
Named
Available from AM/AP 3.5.
Give your hardware objects a name (.e.g. 'Power button' or 'Strobe LED').
Air Manager will present the user with a view where the assignment of pins can be done.
Arguments
hw_button_id = hw_button_add(name, pressed_callback, released_callback)
# |
Argument |
Type |
Description
|
1 |
name |
String |
A functional name to define the button.
|
2 |
pressed_callback |
Function |
This function will be called when the button is pressed.
|
3 |
released_callback |
Function |
This function will be called when the button is released.
|
Return value
Argument |
Type |
Description
|
hw_button_id |
ID |
This value can be used for further reference.
|
Example
-- Callback function which is called when the button is pressed
function button_pressed()
print("button pressed")
end
-- Callback function which is called when the button is released
function button_released()
print("button released")
end
-- Create the button. The actual pin used can be configured in Air Manager.
hw_button_add("Power button", button_pressed, button_released)
Hardware Id's
Hardware Id's are not preferred, try to use named hardware instead.
Define the used pin(s) right away.
This is not preferred, since changing of pin assignment can only be done by changing the instrument/panel lua script.
Arguments
hw_button_id = hw_button_add(hw_id, pressed_callback, released_callback)
# |
Argument |
Type |
Description
|
1 |
hw_id |
String |
The is the reference to the input. You can choose to bind to an existing Hardware ID (Hardware_id_list).
|
2 |
pressed_callback |
Function |
This function will be called when the button is pressed.
|
3 |
released_callback |
Function |
This function will be called when the button is released.
|
Return value
Argument |
Type |
Description
|
hw_button_id |
ID |
This value can be used for further reference.
|
Example
-- Callback function which is called when the button is pressed
function button_pressed()
print("button pressed")
end
-- Callback function which is called when the button is released
function button_released()
print("button released")
end
-- Bind to Raspberry Pi 2, Header P1, Pin 40
hw_button_add("RPI_V2_P1_40", button_pressed, button_released)
Schematic example