class Tinkerforge::BrickletLCD20x4
20x4 character alphanumeric display with blue backlight
Constants
- CALLBACK_BUTTON_PRESSED
This callback is triggered when a button is pressed. The parameter is the number of the button (0 to 2 or 0 to 3 since hardware version 1.2).
- CALLBACK_BUTTON_RELEASED
This callback is triggered when a button is released. The parameter is the number of the button (0 to 2 or 0 to 3 since hardware version 1.2).
Public Class Methods
Creates an object with the unique device ID uid
and adds it to the IP Connection ipcon
.
# File lib/tinkerforge/bricklet_lcd_20x4.rb, line 46 def initialize(uid, ipcon) super uid, ipcon, DEVICE_IDENTIFIER, DEVICE_DISPLAY_NAME @api_version = [2, 0, 2] @response_expected[FUNCTION_WRITE_LINE] = RESPONSE_EXPECTED_FALSE @response_expected[FUNCTION_CLEAR_DISPLAY] = RESPONSE_EXPECTED_FALSE @response_expected[FUNCTION_BACKLIGHT_ON] = RESPONSE_EXPECTED_FALSE @response_expected[FUNCTION_BACKLIGHT_OFF] = RESPONSE_EXPECTED_FALSE @response_expected[FUNCTION_IS_BACKLIGHT_ON] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_SET_CONFIG] = RESPONSE_EXPECTED_FALSE @response_expected[FUNCTION_GET_CONFIG] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_IS_BUTTON_PRESSED] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_SET_CUSTOM_CHARACTER] = RESPONSE_EXPECTED_FALSE @response_expected[FUNCTION_GET_CUSTOM_CHARACTER] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_SET_DEFAULT_TEXT] = RESPONSE_EXPECTED_FALSE @response_expected[FUNCTION_GET_DEFAULT_TEXT] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_SET_DEFAULT_TEXT_COUNTER] = RESPONSE_EXPECTED_FALSE @response_expected[FUNCTION_GET_DEFAULT_TEXT_COUNTER] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE @callback_formats[CALLBACK_BUTTON_PRESSED] = [9, 'C'] @callback_formats[CALLBACK_BUTTON_RELEASED] = [9, 'C'] @ipcon.add_device self end
Public Instance Methods
Turns the backlight off.
# File lib/tinkerforge/bricklet_lcd_20x4.rb, line 105 def backlight_off check_validity send_request FUNCTION_BACKLIGHT_OFF, [], '', 8, '' end
Turns the backlight on.
# File lib/tinkerforge/bricklet_lcd_20x4.rb, line 98 def backlight_on check_validity send_request FUNCTION_BACKLIGHT_ON, [], '', 8, '' end
Deletes all characters from the display.
# File lib/tinkerforge/bricklet_lcd_20x4.rb, line 91 def clear_display check_validity send_request FUNCTION_CLEAR_DISPLAY, [], '', 8, '' end
Returns the configuration as set by BrickletLCD20x4#set_config
.
# File lib/tinkerforge/bricklet_lcd_20x4.rb, line 129 def get_config check_validity send_request FUNCTION_GET_CONFIG, [], '', 10, '? ?' end
Returns the custom character for a given index, as set with BrickletLCD20x4#set_custom_character
.
- .. versionadded
-
2.0.1$nbsp;(Plugin)
# File lib/tinkerforge/bricklet_lcd_20x4.rb, line 181 def get_custom_character(index) check_validity send_request FUNCTION_GET_CUSTOM_CHARACTER, [index], 'C', 16, 'C8' end
Returns the default text for a given line (0-3) as set by BrickletLCD20x4#set_default_text
.
- .. versionadded
-
2.0.2$nbsp;(Plugin)
# File lib/tinkerforge/bricklet_lcd_20x4.rb, line 204 def get_default_text(line) check_validity send_request FUNCTION_GET_DEFAULT_TEXT, [line], 'C', 28, 'Z20' end
Returns the current value of the default text counter.
- .. versionadded
-
2.0.2$nbsp;(Plugin)
# File lib/tinkerforge/bricklet_lcd_20x4.rb, line 234 def get_default_text_counter check_validity send_request FUNCTION_GET_DEFAULT_TEXT_COUNTER, [], '', 12, 'l' 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_lcd_20x4.rb, line 250 def get_identity send_request FUNCTION_GET_IDENTITY, [], '', 33, 'Z8 Z8 k C3 C3 S' end
Returns true if the backlight is on and false otherwise.
# File lib/tinkerforge/bricklet_lcd_20x4.rb, line 112 def is_backlight_on check_validity send_request FUNCTION_IS_BACKLIGHT_ON, [], '', 9, '?' end
Registers a callback with ID id
to the block block
.
# File lib/tinkerforge/bricklet_lcd_20x4.rb, line 255 def register_callback(id, &block) callback = block @registered_callbacks[id] = callback end
Configures if the cursor (shown as “_”) should be visible and if it should be blinking (shown as a blinking block). The cursor position is one character behind the the last text written with BrickletLCD20x4#write_line
.
# File lib/tinkerforge/bricklet_lcd_20x4.rb, line 122 def set_config(cursor, blinking) check_validity send_request FUNCTION_SET_CONFIG, [cursor, blinking], '? ?', 8, '' end
The LCD 20x4 Bricklet can store up to 8 custom characters. The characters consist of 5x8 pixels and can be addressed with the index 0-7. To describe the pixels, the first 5 bits of 8 bytes are used. For example, to make a custom character “H”, you should transfer the following:
-
“character = 0b00010001“ (decimal value 17)
-
“character = 0b00010001“ (decimal value 17)
-
“character = 0b00010001“ (decimal value 17)
-
“character = 0b00011111“ (decimal value 31)
-
“character = 0b00010001“ (decimal value 17)
-
“character = 0b00010001“ (decimal value 17)
-
“character = 0b00010001“ (decimal value 17)
-
“character = 0b00000000“ (decimal value 0)
The characters can later be written with BrickletLCD20x4#write_line
by using the characters with the byte representation 8 (“\x08” or “\u0008”) to 15 (“\x0F” or “\u000F”).
You can play around with the custom characters in Brick Viewer version since 2.0.1.
Custom characters are stored by the LCD in RAM, so they have to be set after each startup.
- .. versionadded
-
2.0.1$nbsp;(Plugin)
# File lib/tinkerforge/bricklet_lcd_20x4.rb, line 171 def set_custom_character(index, character) check_validity send_request FUNCTION_SET_CUSTOM_CHARACTER, [index, character], 'C C8', 8, '' end
Sets the default text for lines 0-3. The max number of characters per line is 20.
The default text is shown on the LCD, if the default text counter expires, see BrickletLCD20x4#set_default_text_counter
.
- .. versionadded
-
2.0.2$nbsp;(Plugin)
# File lib/tinkerforge/bricklet_lcd_20x4.rb, line 194 def set_default_text(line, text) check_validity send_request FUNCTION_SET_DEFAULT_TEXT, [line, text], 'C Z20', 8, '' end
Sets the default text counter. This counter is decremented each ms by the LCD firmware. If the counter reaches 0, the default text (see BrickletLCD20x4#set_default_text
) is shown on the LCD.
This functionality can be used to show a default text if the controlling program crashes or the connection is interrupted.
A possible approach is to call BrickletLCD20x4#set_default_text_counter
every minute with the parameter 1000*60*2 (2 minutes). In this case the default text will be shown no later than 2 minutes after the controlling program crashes.
A negative counter turns the default text functionality off.
- .. versionadded
-
2.0.2$nbsp;(Plugin)
# File lib/tinkerforge/bricklet_lcd_20x4.rb, line 225 def set_default_text_counter(counter) check_validity send_request FUNCTION_SET_DEFAULT_TEXT_COUNTER, [counter], 'l', 8, '' end
Writes text to a specific line with a specific position. The text can have a maximum of 20 characters.
For example: (0, 7, “Hello”) will write Hello in the middle of the first line of the display.
The display uses a special charset that includes all ASCII characters except backslash and tilde. The LCD charset also includes several other non-ASCII characters, see the `charset specification <
# File lib/tinkerforge/bricklet_lcd_20x4.rb, line 84
def write_line(line, position, text)
check_validity
send_request FUNCTION_WRITE_LINE, [line, position, text], 'C C Z20', 8, ''
end