Class: Tinkerforge::BrickletAnalogOut
- Defined in:
- lib/tinkerforge/bricklet_analog_out.rb
Overview
Generates configurable DC voltage between 0V and 5V
Constant Summary collapse
- DEVICE_IDENTIFIER =
:nodoc:
220- DEVICE_DISPLAY_NAME =
:nodoc:
'Analog Out Bricklet'- FUNCTION_SET_VOLTAGE =
:nodoc:
1- FUNCTION_GET_VOLTAGE =
:nodoc:
2- FUNCTION_SET_MODE =
:nodoc:
3- FUNCTION_GET_MODE =
:nodoc:
4- FUNCTION_GET_IDENTITY =
:nodoc:
255- MODE_ANALOG_VALUE =
:nodoc:
0- MODE_1K_TO_GROUND =
:nodoc:
1- MODE_100K_TO_GROUND =
:nodoc:
2- MODE_500K_TO_GROUND =
:nodoc:
3
Constants inherited from Device
Device::RESPONSE_EXPECTED_ALWAYS_FALSE, Device::RESPONSE_EXPECTED_ALWAYS_TRUE, Device::RESPONSE_EXPECTED_FALSE, Device::RESPONSE_EXPECTED_INVALID_FUNCTION_ID, Device::RESPONSE_EXPECTED_TRUE
Instance Attribute Summary
Attributes inherited from Device
#callback_formats, #expected_response_function_id, #expected_response_sequence_number, #registered_callbacks, #uid
Instance Method Summary collapse
-
#get_identity ⇒ Object
Returns the UID, the UID where the Bricklet is connected to, the position, the hardware and firmware version as well as the device identifier.
-
#get_mode ⇒ Object
Returns the mode as set by BrickletAnalogOut#set_mode.
-
#get_voltage ⇒ Object
Returns the voltage as set by BrickletAnalogOut#set_voltage.
-
#initialize(uid, ipcon) ⇒ BrickletAnalogOut
constructor
Creates an object with the unique device ID
uidand adds it to the IP Connectionipcon. -
#set_mode(mode) ⇒ Object
Sets the mode of the analog value.
-
#set_voltage(voltage) ⇒ Object
Sets the voltage in mV.
Methods inherited from Device
#dequeue_response, #enqueue_response, #get_api_version, #get_response_expected, #send_request, #set_response_expected, #set_response_expected_all
Constructor Details
#initialize(uid, ipcon) ⇒ BrickletAnalogOut
Creates an object with the unique device ID uid and adds it to the IP Connection ipcon.
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/tinkerforge/bricklet_analog_out.rb', line 31 def initialize(uid, ipcon) super uid, ipcon @api_version = [2, 0, 0] @response_expected[FUNCTION_SET_VOLTAGE] = RESPONSE_EXPECTED_FALSE @response_expected[FUNCTION_GET_VOLTAGE] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_SET_MODE] = RESPONSE_EXPECTED_FALSE @response_expected[FUNCTION_GET_MODE] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE end |
Instance Method Details
#get_identity ⇒ Object
Returns the UID, the UID where the Bricklet is connected to, the position, the hardware and firmware version as well as the device identifier.
The position can be ‘a’, ‘b’, ‘c’ or ‘d’.
The device identifier numbers can be found :ref:‘here <device_identifier>`. |device_identifier_constant|
85 86 87 |
# File 'lib/tinkerforge/bricklet_analog_out.rb', line 85 def get_identity send_request(FUNCTION_GET_IDENTITY, [], '', 25, 'Z8 Z8 k C3 C3 S') end |
#get_mode ⇒ Object
Returns the mode as set by BrickletAnalogOut#set_mode.
73 74 75 |
# File 'lib/tinkerforge/bricklet_analog_out.rb', line 73 def get_mode send_request(FUNCTION_GET_MODE, [], '', 1, 'C') end |
#get_voltage ⇒ Object
Returns the voltage as set by BrickletAnalogOut#set_voltage.
53 54 55 |
# File 'lib/tinkerforge/bricklet_analog_out.rb', line 53 def get_voltage send_request(FUNCTION_GET_VOLTAGE, [], '', 2, 'S') end |
#set_mode(mode) ⇒ Object
Sets the mode of the analog value. Possible modes:
-
0: Normal Mode (Analog value as set by BrickletAnalogOut#set_voltage is applied)
-
1: 1k Ohm resistor to ground
-
2: 100k Ohm resistor to ground
-
3: 500k Ohm resistor to ground
Setting the mode to 0 will result in an output voltage of 0. You can jump to a higher output voltage directly by calling BrickletAnalogOut#set_voltage.
The default mode is 1.
68 69 70 |
# File 'lib/tinkerforge/bricklet_analog_out.rb', line 68 def set_mode(mode) send_request(FUNCTION_SET_MODE, [mode], 'C', 0, '') end |
#set_voltage(voltage) ⇒ Object
Sets the voltage in mV. The possible range is 0V to 5V (0-5000). Calling this function will set the mode to 0 (see BrickletAnalogOut#set_mode).
The default value is 0 (with mode 1).
48 49 50 |
# File 'lib/tinkerforge/bricklet_analog_out.rb', line 48 def set_voltage(voltage) send_request(FUNCTION_SET_VOLTAGE, [voltage], 'S', 0, '') end |