Difference between revisions of "Hw button add"
Jump to navigation
Jump to search
(→Named) |
|||
Line 18: | Line 18: | ||
{{tip| Available from AM/AP 3.5.}} | {{tip| Available from AM/AP 3.5.}} | ||
Give your hardware objects a name (.e.g. 'Power button' or 'Strobe LED'). | Give your hardware objects a name (.e.g. 'Power button' or 'Strobe LED').<br/> | ||
Air Manager will present the user with a view where the assignment of pins can be done. | Air Manager will present the user with a view where the assignment of pins can be done. | ||
Revision as of 19:11, 11 October 2018
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.
Return value
Argument | Type | Description |
---|---|---|
hw_button_id | ID | This value can be used for further reference. |
Named
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
# | 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. |
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
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
# | 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. |
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)