Class: Tinkerforge::BrickletAnalogIn
- Defined in:
- lib/tinkerforge/bricklet_analog_in.rb
Overview
Measures DC voltage between 0V and 45V
Constant Summary collapse
- DEVICE_IDENTIFIER =
:nodoc:
219
- DEVICE_DISPLAY_NAME =
:nodoc:
'Analog In Bricklet'
- CALLBACK_VOLTAGE =
This callback is triggered periodically with the period that is set by BrickletAnalogIn#set_voltage_callback_period. The parameter is the voltage of the sensor.
The CALLBACK_VOLTAGE callback is only triggered if the voltage has changed since the last triggering.
13
- CALLBACK_ANALOG_VALUE =
This callback is triggered periodically with the period that is set by BrickletAnalogIn#set_analog_value_callback_period. The parameter is the analog value of the sensor.
The CALLBACK_ANALOG_VALUE callback is only triggered if the voltage has changed since the last triggering.
14
- CALLBACK_VOLTAGE_REACHED =
This callback is triggered when the threshold as set by BrickletAnalogIn#set_voltage_callback_threshold is reached. The parameter is the voltage of the sensor.
If the threshold keeps being reached, the callback is triggered periodically with the period as set by BrickletAnalogIn#set_debounce_period.
15
- CALLBACK_ANALOG_VALUE_REACHED =
This callback is triggered when the threshold as set by BrickletAnalogIn#set_analog_value_callback_threshold is reached. The parameter is the analog value of the sensor.
If the threshold keeps being reached, the callback is triggered periodically with the period as set by BrickletAnalogIn#set_debounce_period.
16
- FUNCTION_GET_VOLTAGE =
:nodoc:
1
- FUNCTION_GET_ANALOG_VALUE =
:nodoc:
2
- FUNCTION_SET_VOLTAGE_CALLBACK_PERIOD =
:nodoc:
3
- FUNCTION_GET_VOLTAGE_CALLBACK_PERIOD =
:nodoc:
4
- FUNCTION_SET_ANALOG_VALUE_CALLBACK_PERIOD =
:nodoc:
5
- FUNCTION_GET_ANALOG_VALUE_CALLBACK_PERIOD =
:nodoc:
6
- FUNCTION_SET_VOLTAGE_CALLBACK_THRESHOLD =
:nodoc:
7
- FUNCTION_GET_VOLTAGE_CALLBACK_THRESHOLD =
:nodoc:
8
- FUNCTION_SET_ANALOG_VALUE_CALLBACK_THRESHOLD =
:nodoc:
9
- FUNCTION_GET_ANALOG_VALUE_CALLBACK_THRESHOLD =
:nodoc:
10
- FUNCTION_SET_DEBOUNCE_PERIOD =
:nodoc:
11
- FUNCTION_GET_DEBOUNCE_PERIOD =
:nodoc:
12
- FUNCTION_SET_RANGE =
:nodoc:
17
- FUNCTION_GET_RANGE =
:nodoc:
18
- FUNCTION_SET_AVERAGING =
:nodoc:
19
- FUNCTION_GET_AVERAGING =
:nodoc:
20
- FUNCTION_GET_IDENTITY =
:nodoc:
255
- THRESHOLD_OPTION_OFF =
:nodoc:
'x'
- THRESHOLD_OPTION_OUTSIDE =
:nodoc:
'o'
- THRESHOLD_OPTION_INSIDE =
:nodoc:
'i'
- THRESHOLD_OPTION_SMALLER =
:nodoc:
'<'
- THRESHOLD_OPTION_GREATER =
:nodoc:
'>'
- RANGE_AUTOMATIC =
:nodoc:
0
- RANGE_UP_TO_6V =
:nodoc:
1
- RANGE_UP_TO_10V =
:nodoc:
2
- RANGE_UP_TO_36V =
:nodoc:
3
- RANGE_UP_TO_45V =
:nodoc:
4
- RANGE_UP_TO_3V =
:nodoc:
5
Constants inherited from Device
Device::DEVICE_IDENTIFIER_CHECK_MATCH, Device::DEVICE_IDENTIFIER_CHECK_MISMATCH, Device::DEVICE_IDENTIFIER_CHECK_PENDING, 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, #high_level_callbacks, #registered_callbacks, #replaced, #uid
Instance Method Summary collapse
-
#get_analog_value ⇒ Object
Returns the value as read by a 12-bit analog-to-digital converter.
-
#get_analog_value_callback_period ⇒ Object
Returns the period as set by BrickletAnalogIn#set_analog_value_callback_period.
-
#get_analog_value_callback_threshold ⇒ Object
Returns the threshold as set by BrickletAnalogIn#set_analog_value_callback_threshold.
-
#get_averaging ⇒ Object
Returns the averaging configuration as set by BrickletAnalogIn#set_averaging.
-
#get_debounce_period ⇒ Object
Returns the debounce period as set by BrickletAnalogIn#set_debounce_period.
-
#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_range ⇒ Object
Returns the measurement range as set by BrickletAnalogIn#set_range.
-
#get_voltage ⇒ Object
Returns the voltage of the sensor.
-
#get_voltage_callback_period ⇒ Object
Returns the period as set by BrickletAnalogIn#set_voltage_callback_period.
-
#get_voltage_callback_threshold ⇒ Object
Returns the threshold as set by BrickletAnalogIn#set_voltage_callback_threshold.
-
#initialize(uid, ipcon) ⇒ BrickletAnalogIn
constructor
Creates an object with the unique device ID
uid
and adds it to the IP Connectionipcon
. -
#register_callback(id, &block) ⇒ Object
Registers a callback with ID
id
to the blockblock
. -
#set_analog_value_callback_period(period) ⇒ Object
Sets the period with which the CALLBACK_ANALOG_VALUE callback is triggered periodically.
-
#set_analog_value_callback_threshold(option, min, max) ⇒ Object
Sets the thresholds for the CALLBACK_ANALOG_VALUE_REACHED callback.
-
#set_averaging(average) ⇒ Object
Set the length of a averaging for the voltage value.
-
#set_debounce_period(debounce) ⇒ Object
Sets the period with which the threshold callbacks.
-
#set_range(range) ⇒ Object
Sets the measurement range.
-
#set_voltage_callback_period(period) ⇒ Object
Sets the period with which the CALLBACK_VOLTAGE callback is triggered periodically.
-
#set_voltage_callback_threshold(option, min, max) ⇒ Object
Sets the thresholds for the CALLBACK_VOLTAGE_REACHED callback.
Methods inherited from Device
#check_validity, #dequeue_response, #enqueue_response, #get_api_version, #get_response_expected, #send_request, #set_response_expected, #set_response_expected_all
Constructor Details
#initialize(uid, ipcon) ⇒ BrickletAnalogIn
Creates an object with the unique device ID uid
and adds it to the IP Connection ipcon
.
Instance Method Details
#get_analog_value ⇒ Object
Returns the value as read by a 12-bit analog-to-digital converter.
- .. note
-
The value returned by BrickletAnalogIn#get_voltage is averaged over several samples to yield less noise, while BrickletAnalogIn#get_analog_value gives back raw unfiltered analog values. The only reason to use BrickletAnalogIn#get_analog_value is, if you need the full resolution of the analog-to-digital converter.
If you want the analog value periodically, it is recommended to use the CALLBACK_ANALOG_VALUE callback and set the period with BrickletAnalogIn#set_analog_value_callback_period.
138 139 140 141 142 |
# File 'lib/tinkerforge/bricklet_analog_in.rb', line 138 def get_analog_value check_validity send_request FUNCTION_GET_ANALOG_VALUE, [], '', 10, 'S' end |
#get_analog_value_callback_period ⇒ Object
Returns the period as set by BrickletAnalogIn#set_analog_value_callback_period.
174 175 176 177 178 |
# File 'lib/tinkerforge/bricklet_analog_in.rb', line 174 def get_analog_value_callback_period check_validity send_request FUNCTION_GET_ANALOG_VALUE_CALLBACK_PERIOD, [], '', 12, 'L' end |
#get_analog_value_callback_threshold ⇒ Object
Returns the threshold as set by BrickletAnalogIn#set_analog_value_callback_threshold.
222 223 224 225 226 |
# File 'lib/tinkerforge/bricklet_analog_in.rb', line 222 def get_analog_value_callback_threshold check_validity send_request FUNCTION_GET_ANALOG_VALUE_CALLBACK_THRESHOLD, [], '', 13, 'k S S' end |
#get_averaging ⇒ Object
Returns the averaging configuration as set by BrickletAnalogIn#set_averaging.
- .. versionadded
-
2.0.3$nbsp;(Plugin)
293 294 295 296 297 |
# File 'lib/tinkerforge/bricklet_analog_in.rb', line 293 def get_averaging check_validity send_request FUNCTION_GET_AVERAGING, [], '', 9, 'C' end |
#get_debounce_period ⇒ Object
Returns the debounce period as set by BrickletAnalogIn#set_debounce_period.
246 247 248 249 250 |
# File 'lib/tinkerforge/bricklet_analog_in.rb', line 246 def get_debounce_period check_validity send_request FUNCTION_GET_DEBOUNCE_PERIOD, [], '', 12, 'L' end |
#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’, ‘d’, ‘e’, ‘f’, ‘g’ or ‘h’ (Bricklet Port). A Bricklet connected to an :ref:‘Isolator Bricklet <isolator_bricklet>` is always at position ’z’.
The device identifier numbers can be found :ref:‘here <device_identifier>`. |device_identifier_constant|
309 310 311 |
# File 'lib/tinkerforge/bricklet_analog_in.rb', line 309 def get_identity send_request FUNCTION_GET_IDENTITY, [], '', 33, 'Z8 Z8 k C3 C3 S' end |
#get_range ⇒ Object
Returns the measurement range as set by BrickletAnalogIn#set_range.
- .. versionadded
-
2.0.1$nbsp;(Plugin)
271 272 273 274 275 |
# File 'lib/tinkerforge/bricklet_analog_in.rb', line 271 def get_range check_validity send_request FUNCTION_GET_RANGE, [], '', 9, 'C' end |
#get_voltage ⇒ Object
Returns the voltage of the sensor. The resolution between 0 and 6V is about 2mV. Between 6 and 45V the resolution is about 10mV.
If you want to get the voltage periodically, it is recommended to use the CALLBACK_VOLTAGE callback and set the period with BrickletAnalogIn#set_voltage_callback_period.
121 122 123 124 125 |
# File 'lib/tinkerforge/bricklet_analog_in.rb', line 121 def get_voltage check_validity send_request FUNCTION_GET_VOLTAGE, [], '', 10, 'S' end |
#get_voltage_callback_period ⇒ Object
Returns the period as set by BrickletAnalogIn#set_voltage_callback_period.
156 157 158 159 160 |
# File 'lib/tinkerforge/bricklet_analog_in.rb', line 156 def get_voltage_callback_period check_validity send_request FUNCTION_GET_VOLTAGE_CALLBACK_PERIOD, [], '', 12, 'L' end |
#get_voltage_callback_threshold ⇒ Object
Returns the threshold as set by BrickletAnalogIn#set_voltage_callback_threshold.
198 199 200 201 202 |
# File 'lib/tinkerforge/bricklet_analog_in.rb', line 198 def get_voltage_callback_threshold check_validity send_request FUNCTION_GET_VOLTAGE_CALLBACK_THRESHOLD, [], '', 13, 'k S S' end |
#register_callback(id, &block) ⇒ Object
Registers a callback with ID id
to the block block
.
314 315 316 317 |
# File 'lib/tinkerforge/bricklet_analog_in.rb', line 314 def register_callback(id, &block) callback = block @registered_callbacks[id] = callback end |
#set_analog_value_callback_period(period) ⇒ Object
Sets the period with which the CALLBACK_ANALOG_VALUE callback is triggered periodically. A value of 0 turns the callback off.
The CALLBACK_ANALOG_VALUE callback is only triggered if the analog value has changed since the last triggering.
167 168 169 170 171 |
# File 'lib/tinkerforge/bricklet_analog_in.rb', line 167 def set_analog_value_callback_period(period) check_validity send_request FUNCTION_SET_ANALOG_VALUE_CALLBACK_PERIOD, [period], 'L', 8, '' end |
#set_analog_value_callback_threshold(option, min, max) ⇒ Object
Sets the thresholds for the CALLBACK_ANALOG_VALUE_REACHED callback.
The following options are possible:
"Option", "Description"
"'x'", "Callback is turned off"
"'o'", "Callback is triggered when the analog value is *outside* the min and max values"
"'i'", "Callback is triggered when the analog value is *inside* the min and max values"
"'<'", "Callback is triggered when the analog value is smaller than the min value (max is ignored)"
"'>'", "Callback is triggered when the analog value is greater than the min value (max is ignored)"
215 216 217 218 219 |
# File 'lib/tinkerforge/bricklet_analog_in.rb', line 215 def set_analog_value_callback_threshold(option, min, max) check_validity send_request FUNCTION_SET_ANALOG_VALUE_CALLBACK_THRESHOLD, [option, min, max], 'k S S', 8, '' end |
#set_averaging(average) ⇒ Object
Set the length of a averaging for the voltage value.
Setting the length to 0 will turn the averaging completely off. If the averaging is off, there is more noise on the data, but the data is without delay.
- .. versionadded
-
2.0.3$nbsp;(Plugin)
284 285 286 287 288 |
# File 'lib/tinkerforge/bricklet_analog_in.rb', line 284 def set_averaging(average) check_validity send_request FUNCTION_SET_AVERAGING, [average], 'C', 8, '' end |
#set_debounce_period(debounce) ⇒ Object
Sets the period with which the threshold callbacks
-
CALLBACK_VOLTAGE_REACHED,
-
CALLBACK_ANALOG_VALUE_REACHED
are triggered, if the thresholds
-
BrickletAnalogIn#set_voltage_callback_threshold,
-
BrickletAnalogIn#set_analog_value_callback_threshold
keep being reached.
239 240 241 242 243 |
# File 'lib/tinkerforge/bricklet_analog_in.rb', line 239 def set_debounce_period(debounce) check_validity send_request FUNCTION_SET_DEBOUNCE_PERIOD, [debounce], 'L', 8, '' end |
#set_range(range) ⇒ Object
Sets the measurement range. Possible ranges:
-
0: Automatically switched
-
1: 0V - 6.05V, ~1.48mV resolution
-
2: 0V - 10.32V, ~2.52mV resolution
-
3: 0V - 36.30V, ~8.86mV resolution
-
4: 0V - 45.00V, ~11.25mV resolution
-
5: 0V - 3.3V, ~0.81mV resolution, new in version 2.0.3$nbsp;(Plugin)
- .. versionadded
-
2.0.1$nbsp;(Plugin)
262 263 264 265 266 |
# File 'lib/tinkerforge/bricklet_analog_in.rb', line 262 def set_range(range) check_validity send_request FUNCTION_SET_RANGE, [range], 'C', 8, '' end |
#set_voltage_callback_period(period) ⇒ Object
Sets the period with which the CALLBACK_VOLTAGE callback is triggered periodically. A value of 0 turns the callback off.
The CALLBACK_VOLTAGE callback is only triggered if the voltage has changed since the last triggering.
149 150 151 152 153 |
# File 'lib/tinkerforge/bricklet_analog_in.rb', line 149 def set_voltage_callback_period(period) check_validity send_request FUNCTION_SET_VOLTAGE_CALLBACK_PERIOD, [period], 'L', 8, '' end |
#set_voltage_callback_threshold(option, min, max) ⇒ Object
Sets the thresholds for the CALLBACK_VOLTAGE_REACHED callback.
The following options are possible:
"Option", "Description"
"'x'", "Callback is turned off"
"'o'", "Callback is triggered when the voltage is *outside* the min and max values"
"'i'", "Callback is triggered when the voltage is *inside* the min and max values"
"'<'", "Callback is triggered when the voltage is smaller than the min value (max is ignored)"
"'>'", "Callback is triggered when the voltage is greater than the min value (max is ignored)"
191 192 193 194 195 |
# File 'lib/tinkerforge/bricklet_analog_in.rb', line 191 def set_voltage_callback_threshold(option, min, max) check_validity send_request FUNCTION_SET_VOLTAGE_CALLBACK_THRESHOLD, [option, min, max], 'k S S', 8, '' end |