Hw button array add

From Sim Innovations Wiki
Jump to navigation Jump to search

Description

hw_button_array_id = hw_button_array_add(name, nr_rows, nr_columns, pressed_callback, released_callback) (from AM/AP 3.5)
hw_button_array_id = hw_button_array_add(nr_rows, nr_columns, hw_id_0, hw_id_1, ..., pressed_callback, released_callback)

hw_button_array_add is used to add a hardware button array to your instrument.

A button array is a way to connect a lot of buttons to your project with a reduces required pin count. Normally, every button would need a separate pin. With the button array, you can decrease the number of pins needed by arranging the buttons into a grid (see schematic below).

The grid has two different types of pins, rows and columns. Rows are set as an output and will be actively driven. Columns are set as input and are read to see if a button changed state.

Named

Info 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_array_id = hw_button_array_add(name, nr_rows, nr_columns, pressed_callback, released_callback)
# Argument Type Description
1 name String A functional name to define the button array.
2 nr_rows Number Number of rows. 8 is the maximum for the Arduino.
3 nr_columns Number Number of columns. 8 is the maximum for the Arduino.
4 pressed_callback Function This function will be called when a button is pressed.
5 released_callback Function (Optional) This function will be called when a button is released.

Return value

Argument Type Description
hw_button_array_id ID This value can be used for further reference.

Example

-- Callback function which is called when a button is pressed
function button_pressed(row, column)
  print("button pressed at " .. row .. ", " .. column)
end

-- Callback function which is called when a button is released
function button_released(row, column)
  print("button released at " .. row .. ", " .. column)
end

-- Create button array with name "my keypad" with 2 rows and 2 columns
hw_button_array_add("my keypad", 2, 2, button_pressed, button_released)

Hardware Id's

Info 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_array_id = hw_button_array_add(nr_rows, nr_columns, hw_id_0, hw_id_1, ..., pressed_callback, released_callback)
# Argument Type Description
1 nr_rows Number Number of rows.
2 nr_columns Number Number of columns
3 .. n hw_ids String The is the reference to the row and column pins. Start of with row pins, then column pins. You can choose to bind to an existing Hardware ID (Hardware_id_list).
n + 1 pressed_callback Function This function will be called when a button is pressed.
n + 2 released_callback Function This function will be called when a button is released.

Return value

Argument Type Description
hw_button_array_id ID This value can be used for further reference.

Example

-- Callback function which is called when a button is pressed
function button_pressed(row, column)
  print("button pressed at " .. row .. ", " .. column)
end

-- Callback function which is called when a button is released
function button_released(row, column)
  print("button released at " .. row .. ", " .. column)
end

-- Bind to Arduino MEGA2560
-- Rows are on pins D3 and D4 (outputs)
-- Columns are on pins D5 and D6 (inputs)
hw_button_array_add(2,2, "ARDUINO_MEGA2560_A_D3", "ARDUINO_MEGA2560_A_D4", "ARDUINO_MEGA2560_A_D5", "ARDUINO_MEGA2560_A_D6", button_pressed, button_released)

Schematic example

Button array schematic.png