Difference between revisions of "Hw dial add"

From Sim Innovations Wiki
Jump to navigation Jump to search
Line 2: Line 2:


  '''hw_dial_id = hw_dial_add(hw_id_a, hw_id_b, callback)'''
  '''hw_dial_id = hw_dial_add(hw_id_a, hw_id_b, callback)'''
'''hw_dial_id = hw_dial_add(hw_id_a, hw_id_b, type, callback)'''
  '''hw_dial_id = hw_dial_add(hw_id_a, hw_id_b, acceleration, callback)'''
  '''hw_dial_id = hw_dial_add(hw_id_a, hw_id_b, acceleration, callback)'''
'''hw_dial_id = hw_dial_add(hw_id_a, hw_id_b, type, acceleration, callback)'''


'''hw_dial_id''' is used to add a hardware rotary encoder to your instrument.
'''hw_dial_id''' is used to add a hardware rotary encoder to your instrument.

Revision as of 15:00, 7 May 2018

Description

hw_dial_id = hw_dial_add(hw_id_a, hw_id_b, callback)
hw_dial_id = hw_dial_add(hw_id_a, hw_id_b, type, callback)
hw_dial_id = hw_dial_add(hw_id_a, hw_id_b, acceleration, callback)
hw_dial_id = hw_dial_add(hw_id_a, hw_id_b, type, acceleration, callback)

hw_dial_id is used to add a hardware rotary encoder to your instrument.

Return value

Argument Type Description
hw_dial_id String This value can be used for further reference. Its good practice to store this hw_input_id in your logic code.

Arguments

# Argument Type Description
1 hw_id_a String The is the reference to first (A) rotary encoder pin. You can choose to bind to an existing Hardware ID (Hardware_id_list).
2 hw_id_b String The is the reference to second (B) rotary encoder pin. You can choose to bind to an existing Hardware ID (Hardware_id_list).
4 acceleration Number (Optional) A multiplier that will make the dial generate extra callbacks when the dial is being rotated faster. The multiplier is the maximum number of callbacks of one dial tick when this dial is being rotated at maximum speed.
3 callback Function This function will be called when the rotary encoder rotates (both ways). The callback will provide one argument, direction, which is 1 for clockwise rotation, and -1 for counterclockwise rotation.

Example

-- Callback function which is called when the rotary encoder is turned
-- direction 1 : The dial turned clockwise
-- direciton -1: The dial turned counterclockwise
function dial_change(direction)

  if direction == 1 then
    print("The dial turned clockwise")
  end

  if direction == -1 then
    print("The dial turned counterclockwise")
  end

end

-- Bind to Raspberry Pi 2, Header P1, Pin 38 and 40
hw_dial_add("RPI_V2_P1_38", "RPI_V2_P1_40", dial_change)

Schematic example

Rotary-encoder.png