class Tinkerforge::BrickletLCD16x2
16x2 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.
- CALLBACK_BUTTON_RELEASED
This callback is triggered when a button is released. The parameter is the number of the button.
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_16x2.rb, line 42 def initialize(uid, ipcon) super uid, ipcon, DEVICE_IDENTIFIER, DEVICE_DISPLAY_NAME @api_version = [2, 0, 1] @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_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_16x2.rb, line 97 def backlight_off check_validity send_request FUNCTION_BACKLIGHT_OFF, [], '', 8, '' end
Turns the backlight on.
# File lib/tinkerforge/bricklet_lcd_16x2.rb, line 90 def backlight_on check_validity send_request FUNCTION_BACKLIGHT_ON, [], '', 8, '' end
Deletes all characters from the display.
# File lib/tinkerforge/bricklet_lcd_16x2.rb, line 83 def clear_display check_validity send_request FUNCTION_CLEAR_DISPLAY, [], '', 8, '' end
Returns the configuration as set by BrickletLCD16x2#set_config
.
# File lib/tinkerforge/bricklet_lcd_16x2.rb, line 121 def get_config check_validity send_request FUNCTION_GET_CONFIG, [], '', 10, '? ?' end
Returns the custom character for a given index, as set with BrickletLCD16x2#set_custom_character
.
- .. versionadded
-
2.0.1$nbsp;(Plugin)
# File lib/tinkerforge/bricklet_lcd_16x2.rb, line 172 def get_custom_character(index) check_validity send_request FUNCTION_GET_CUSTOM_CHARACTER, [index], 'C', 16, 'C8' 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_16x2.rb, line 188 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_16x2.rb, line 104 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_16x2.rb, line 193 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 BrickletLCD16x2#write_line
.
# File lib/tinkerforge/bricklet_lcd_16x2.rb, line 114 def set_config(cursor, blinking) check_validity send_request FUNCTION_SET_CONFIG, [cursor, blinking], '? ?', 8, '' end
The LCD 16x2 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 BrickletLCD16x2#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 since version 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_16x2.rb, line 162 def set_custom_character(index, character) check_validity send_request FUNCTION_SET_CUSTOM_CHARACTER, [index, character], 'C C8', 8, '' end
Writes text to a specific line with a specific position. The text can have a maximum of 16 characters.
For example: (0, 5, “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_16x2.rb, line 76
def write_line(line, position, text)
check_validity
send_request FUNCTION_WRITE_LINE, [line, position, text], 'C C Z16', 8, ''
end