class Tinkerforge::BrickletOLED64x48

1.68cm (0.66“) OLED display with 64x48 pixels

Public Class Methods

new(uid, ipcon) click to toggle source

Creates an object with the unique device ID uid and adds it to the IP Connection ipcon.

Calls superclass method
# File lib/tinkerforge/bricklet_oled_64x48.rb, line 30
def initialize(uid, ipcon)
  super uid, ipcon, DEVICE_IDENTIFIER, DEVICE_DISPLAY_NAME

  @api_version = [2, 0, 0]

  @response_expected[FUNCTION_WRITE] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_NEW_WINDOW] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_CLEAR_DISPLAY] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_SET_DISPLAY_CONFIGURATION] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_GET_DISPLAY_CONFIGURATION] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_WRITE_LINE] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE


  @ipcon.add_device self
end

Public Instance Methods

clear_display() click to toggle source

Clears the current content of the window as set by BrickletOLED64x48#new_window.

# File lib/tinkerforge/bricklet_oled_64x48.rb, line 81
def clear_display
  check_validity

  send_request FUNCTION_CLEAR_DISPLAY, [], '', 8, ''
end
get_display_configuration() click to toggle source

Returns the configuration as set by BrickletOLED64x48#set_display_configuration.

# File lib/tinkerforge/bricklet_oled_64x48.rb, line 98
def get_display_configuration
  check_validity

  send_request FUNCTION_GET_DISPLAY_CONFIGURATION, [], '', 10, 'C ?'
end
get_identity() click to toggle source

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_oled_64x48.rb, line 131
def get_identity
  send_request FUNCTION_GET_IDENTITY, [], '', 33, 'Z8 Z8 k C3 C3 S'
end
new_window(column_from, column_to, row_from, row_to) click to toggle source

Sets the window in which you can write with BrickletOLED64x48#write. One row has a height of 8 pixels.

# File lib/tinkerforge/bricklet_oled_64x48.rb, line 74
def new_window(column_from, column_to, row_from, row_to)
  check_validity

  send_request FUNCTION_NEW_WINDOW, [column_from, column_to, row_from, row_to], 'C C C C', 8, ''
end
set_display_configuration(contrast, invert) click to toggle source

Sets the configuration of the display.

You can set a contrast value from 0 to 255 and you can invert the color (black/white) of the display.

# File lib/tinkerforge/bricklet_oled_64x48.rb, line 91
def set_display_configuration(contrast, invert)
  check_validity

  send_request FUNCTION_SET_DISPLAY_CONFIGURATION, [contrast, invert], 'C ?', 8, ''
end
write(data) click to toggle source

Appends 64 byte of data to the window as set by BrickletOLED64x48#new_window.

Each row has a height of 8 pixels which corresponds to one byte of data.

Example: if you call BrickletOLED64x48#new_window with column from 0 to 63 and row from 0 to 5 (the whole display) each call of BrickletOLED64x48#write (red arrow) will write one row.

.. image

/Images/Bricklets/bricklet_oled_64x48_display.png

:scale: 100 %
:alt: Display pixel order
:align: center
:target: ../../_images/Bricklets/bricklet_oled_64x48_display.png

The LSB (D0) of each data byte is at the top and the MSB (D7) is at the bottom of the row.

The next call of BrickletOLED64x48#write will write the second row and so on. To fill the whole display you need to call BrickletOLED64x48#write 6 times.

# File lib/tinkerforge/bricklet_oled_64x48.rb, line 66
def write(data)
  check_validity

  send_request FUNCTION_WRITE, [data], 'C64', 8, ''
end
write_line(line, position, text) click to toggle source

Writes text to a specific line with a specific position. The text can have a maximum of 13 characters.

For example: (1, 4, “Hello”) will write Hello in the middle of the second line of the display.

You can draw to the display with BrickletOLED64x48#write and then add text to it afterwards.

The display uses a special 5x7 pixel charset. You can view the characters of the charset in Brick Viewer.

# File lib/tinkerforge/bricklet_oled_64x48.rb, line 115
def write_line(line, position, text)
  check_validity

  send_request FUNCTION_WRITE_LINE, [line, position, text], 'C C Z13', 8, ''
end