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::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_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
uidand adds it to the IP Connectionipcon. -
#register_callback(id, &block) ⇒ Object
Registers a callback with ID
idto 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
#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.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/tinkerforge/bricklet_segment_display_4x7.rb', line 31 def initialize(uid, ipcon) super uid, ipcon @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[CALLBACK_COUNTER_FINISHED] = RESPONSE_EXPECTED_ALWAYS_FALSE @response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE @callback_formats[CALLBACK_COUNTER_FINISHED] = '' 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.
90 91 92 |
# File 'lib/tinkerforge/bricklet_segment_display_4x7.rb', line 90 def get_counter_value send_request(FUNCTION_GET_COUNTER_VALUE, [], '', 2, '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’ or ‘d’.
The device identifier numbers can be found :ref:‘here <device_identifier>`. |device_identifier_constant|
102 103 104 |
# File 'lib/tinkerforge/bricklet_segment_display_4x7.rb', line 102 def get_identity send_request(FUNCTION_GET_IDENTITY, [], '', 25, 'Z8 Z8 k C3 C3 S') end |
#get_segments ⇒ Object
Returns the segment, brightness and color data as set by BrickletSegmentDisplay4x7#set_segments.
65 66 67 |
# File 'lib/tinkerforge/bricklet_segment_display_4x7.rb', line 65 def get_segments send_request(FUNCTION_GET_SEGMENTS, [], '', 6, 'C4 C ?') end |
#register_callback(id, &block) ⇒ Object
Registers a callback with ID id to the block block.
107 108 109 110 |
# File 'lib/tinkerforge/bricklet_segment_display_4x7.rb', line 107 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.
59 60 61 |
# File 'lib/tinkerforge/bricklet_segment_display_4x7.rb', line 59 def set_segments(segments, brightness, colon) send_request(FUNCTION_SET_SEGMENTS, [segments, brightness, colon], 'C4 C ?', 0, '') 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. The length of the increment is given in ms.
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.
The maximum values for from, to and increment is 9999, the minimum value is -999.
Using a negative increment allows to count backwards.
You can stop the counter at every time by calling BrickletSegmentDisplay4x7#set_segments.
83 84 85 |
# File 'lib/tinkerforge/bricklet_segment_display_4x7.rb', line 83 def start_counter(value_from, value_to, increment, length) send_request(FUNCTION_START_COUNTER, [value_from, value_to, increment, length], 's s s L', 0, '') end |