Class: Tinkerforge::BrickletSegmentDisplay4x7
- Defined in:
- lib/tinkerforge/bricklet_segment_display_4x7.rb
Overview
Four 7-segment displays with switchable colon
Constant Summary collapse
- DEVICE_IDENTIFIER =
:nodoc:
237
- DEVICE_DISPLAY_NAME =
:nodoc:
'Segment Display 4x7 Bricklet'
- CALLBACK_COUNTER_FINISHED =
This callback is triggered when the counter (see BrickletSegmentDisplay4x7#start_counter) is finished.
5
- FUNCTION_SET_SEGMENTS =
:nodoc:
1
- FUNCTION_GET_SEGMENTS =
:nodoc:
2
- FUNCTION_START_COUNTER =
:nodoc:
3
- FUNCTION_GET_COUNTER_VALUE =
:nodoc:
4
- FUNCTION_GET_IDENTITY =
:nodoc:
255
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_counter_value ⇒ Object
Returns the counter value that is currently shown on the display.
-
#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_segments ⇒ Object
Returns the segment, brightness and color data as set by BrickletSegmentDisplay4x7#set_segments.
-
#initialize(uid, ipcon) ⇒ BrickletSegmentDisplay4x7
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_segments(segments, brightness, colon) ⇒ Object
The 7-segment display can be set with bitmaps.
-
#start_counter(value_from, value_to, increment, length) ⇒ Object
Starts a counter with the from value that counts to the to value with the each step incremented by increment.
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) ⇒ BrickletSegmentDisplay4x7
Creates an object with the unique device ID uid
and adds it to the IP Connection ipcon
.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/tinkerforge/bricklet_segment_display_4x7.rb', line 33 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 |
Instance Method Details
#get_counter_value ⇒ Object
Returns the counter value that is currently shown on the display.
If there is no counter running a 0 will be returned.
96 97 98 99 100 |
# File 'lib/tinkerforge/bricklet_segment_display_4x7.rb', line 96 def get_counter_value check_validity send_request FUNCTION_GET_COUNTER_VALUE, [], '', 10, 'S' 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|
112 113 114 |
# File 'lib/tinkerforge/bricklet_segment_display_4x7.rb', line 112 def get_identity send_request FUNCTION_GET_IDENTITY, [], '', 33, 'Z8 Z8 k C3 C3 S' end |
#get_segments ⇒ Object
Returns the segment, brightness and color data as set by BrickletSegmentDisplay4x7#set_segments.
70 71 72 73 74 |
# File 'lib/tinkerforge/bricklet_segment_display_4x7.rb', line 70 def get_segments check_validity send_request FUNCTION_GET_SEGMENTS, [], '', 14, 'C4 C ?' end |
#register_callback(id, &block) ⇒ Object
Registers a callback with ID id
to the block block
.
117 118 119 120 |
# File 'lib/tinkerforge/bricklet_segment_display_4x7.rb', line 117 def register_callback(id, &block) callback = block @registered_callbacks[id] = callback end |
#set_segments(segments, brightness, colon) ⇒ Object
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.
62 63 64 65 66 |
# File 'lib/tinkerforge/bricklet_segment_display_4x7.rb', line 62 def set_segments(segments, brightness, colon) check_validity send_request FUNCTION_SET_SEGMENTS, [segments, brightness, colon], 'C4 C ?', 8, '' end |
#start_counter(value_from, value_to, increment, length) ⇒ Object
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.
87 88 89 90 91 |
# File 'lib/tinkerforge/bricklet_segment_display_4x7.rb', line 87 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 |