class Tinkerforge::BrickletSegmentDisplay4x7
Four 7-segment displays with switchable colon
Constants
- CALLBACK_COUNTER_FINISHED
This callback is triggered when the counter (see
BrickletSegmentDisplay4x7#start_counter
) is finished.
Public Class Methods
Creates an object with the unique device ID uid
and adds it to the IP Connection ipcon
.
# File lib/tinkerforge/bricklet_segment_display_4x7.rb, line 32 def initialize(uid, ipcon) super uid, ipcon, DEVICE_IDENTIFIER, DEVICE_DISPLAY_NAME @api_version = [2, 0, 0] @response_expected[FUNCTION_SET_SEGMENTS] = RESPONSE_EXPECTED_FALSE @response_expected[FUNCTION_GET_SEGMENTS] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_START_COUNTER] = RESPONSE_EXPECTED_FALSE @response_expected[FUNCTION_GET_COUNTER_VALUE] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE @callback_formats[CALLBACK_COUNTER_FINISHED] = [8, ''] @ipcon.add_device self end
Public Instance Methods
Returns the counter value that is currently shown on the display.
If there is no counter running a 0 will be returned.
# File lib/tinkerforge/bricklet_segment_display_4x7.rb, line 95 def get_counter_value check_validity send_request FUNCTION_GET_COUNTER_VALUE, [], '', 10, 'S' end
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|
# File lib/tinkerforge/bricklet_segment_display_4x7.rb, line 111 def get_identity send_request FUNCTION_GET_IDENTITY, [], '', 33, 'Z8 Z8 k C3 C3 S' end
Returns the segment, brightness and color data as set by BrickletSegmentDisplay4x7#set_segments
.
# File lib/tinkerforge/bricklet_segment_display_4x7.rb, line 69 def get_segments check_validity send_request FUNCTION_GET_SEGMENTS, [], '', 14, 'C4 C ?' end
Registers a callback with ID id
to the block block
.
# File lib/tinkerforge/bricklet_segment_display_4x7.rb, line 116 def register_callback(id, &block) callback = block @registered_callbacks[id] = callback end
The 7-segment display can be set with bitmaps. Every bit controls one segment:
- .. image
-
/Images/Bricklets/bricklet_segment_display_4x7_bit_order.png
:scale: 100 % :alt: Bit order of one segment :align: center
For example to set a “5” you would want to activate segments 0, 2, 3, 5 and 6. This is represented by the number 0b01101101 = 0x6d = 109.
The brightness can be set between 0 (dark) and 7 (bright). The colon parameter turns the colon of the display on or off.
# File lib/tinkerforge/bricklet_segment_display_4x7.rb, line 61 def set_segments(segments, brightness, colon) check_validity send_request FUNCTION_SET_SEGMENTS, [segments, brightness, colon], 'C4 C ?', 8, '' end
Starts a counter with the from value that counts to the to value with the each step incremented by increment. length is the pause between each increment.
Example: If you set from to 0, to to 100, increment to 1 and length to 1000, a counter that goes from 0 to 100 with one second pause between each increment will be started.
Using a negative increment allows to count backwards.
You can stop the counter at every time by calling BrickletSegmentDisplay4x7#set_segments
.
# File lib/tinkerforge/bricklet_segment_display_4x7.rb, line 86 def start_counter(value_from, value_to, increment, length) check_validity send_request FUNCTION_START_COUNTER, [value_from, value_to, increment, length], 's s s L', 8, '' end