Hw adc input add

From Sim Innovations Wiki
Jump to navigation Jump to search

Description

hw_adc_input_id = hw_adc_input_add(name, callback) (from AM/AP 3.5)
hw_adc_input_id = hw_adc_input_add(name, hysteresis, callback) (from AM/AP 3.5)
hw_adc_input_id = hw_adc_input_add(hw_id, callback)
hw_adc_input_id = hw_adc_input_add(hw_id, hysteresis, callback)

hw_adc_input_add is used to add a hardware ADC input to your instrument.

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_adc_input_id = hw_adc_input_add(name, callback)
hw_adc_input_id = hw_adc_input_add(name, hysteresis, callback)
# Argument Type Description
1 hw_id name A functional name to define the ADC input.
2 hysteresis Number (Optional) Hysteresis value between 0.0 and 1.0. Increase the hysteresis if your ADC source is unstable. Default is 0.02.
3 callback Function This function will be called when the ADC input value changes. The callback will provide one argument, value, which ranged from 0.0 to 1.0 (in most cases ranges from GND -> VCC).

Return value

Argument Type Description
hw_adc_input_id ID This value can be used for further reference. Functions such as hw_adc_input_read can use this hw_adc_input_id. Its good practice to store this hw_input_id in your logic code.

Example

-- Callback function which is called when the ADC input state changes
-- 0.0 : GND (lowest voltage)
-- 1.0 : VCC (highest voltage)
function adc_input_change(value)
  print("new value= " .. tostring(value) )
end

-- Create a ADC input
hw_adc_input_add("Volume", adc_input_change)

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_adc_input_id = hw_adc_input_add(hw_id, callback)
hw_adc_input_id = hw_adc_input_add(hw_id, hysteresis, 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 hysteresis Number (Optional) Hysteresis value between 0.0 and 1.0. Increase the hysteresis if your ADC source is unstable. Default is 0.02.
3 callback Function This function will be called when the ADC input value changes. The callback will provide one argument, value, which ranged from 0.0 to 1.0 (in most cases ranges from GND -> VCC).

Return value

Argument Type Description
hw_adc_input_id ID This value can be used for further reference. Functions such as hw_adc_input_read can use this hw_adc_input_id. Its good practice to store this hw_input_id in your logic code.

Example

-- Callback function which is called when the ADC input state changes
-- 0.0 : GND (lowest voltage)
-- 1.0 : VCC (highest voltage)
function adc_input_change(value)
  print("new value= " .. tostring(value) )
end

-- Bind to the first pin of hardware port A
hw_adc_input_add("HW_PORT_A1", adc_input_change)