PololuOLED library
Public Member Functions | Public Attributes | List of all members
PololuSH1106 Class Reference

Generic SH1106 class implemented using Arduino I/O functions. More...

#include <PololuSH1106.h>

Inheritance diagram for PololuSH1106:
PololuSH1106Main< PololuSH1106Core >

Public Member Functions

 PololuSH1106 (uint8_t clk, uint8_t mos, uint8_t res=255, uint8_t dc=255, uint8_t cs=255)
 Creates a new instance of PololuSH1106. More...
 
void init ()
 Initializes the OLED if it has not already been initialized. More...
 
void reinitialize ()
 Reinitializes the OLED and its settings. More...
 
void invert ()
 Configures the OLED to invert all the pixels, resulting in black-on-white text. More...
 
void noInvert ()
 Configures the OLED to not invert its pixels (the default). More...
 
void rotate180 ()
 Configures the OLED to rotate its display 180 degrees from normal. More...
 
void noRotate ()
 Configures the OLED to use the default orientation. More...
 
void setContrast (uint8_t contrast)
 Sets the contrast (i.e. brightness) of the OLED. More...
 
void setLayout8x2 ()
 Configures this library to use its default layout, which allows for 8 columns and 2 rows of text. More...
 
void setLayout8x2WithGraphics (const uint8_t *graphics)
 Configures this library to use a layout with 8 columns and 2 rows of text, XORed with a graphics buffer. More...
 
void setLayout11x4 ()
 Configures this library to use a layout with 11 columns and 4 rows of text. More...
 
void setLayout11x4WithGraphics (const uint8_t *graphics)
 Configures this library to use a layout with 11 columns and 4 rows of text, XORed with a graphics buffer. More...
 
void setLayout21x8 ()
 Configures this library to use a layout with 21 columns and 8 rows of text. More...
 
void setLayout21x8WithGraphics (const uint8_t *graphics)
 Configures this library to use a layout with 21 columns and 8 rows of text, XORed with a graphics buffer. More...
 
void display ()
 Writes all of the text/graphics to the OLED. More...
 
void displayPartial (uint8_t x, uint8_t y, uint8_t width)
 Writes a certain region of text/graphics to the OLED. More...
 
void noAutoDisplay ()
 Turns off auto display mode. More...
 
uint8_t * getLinePointer (uint8_t line)
 Gets a pointer to a line of text in this library's text buffer. More...
 
void gotoXY (uint8_t x, uint8_t y)
 Changes the location of the text cursor. More...
 
uint8_t getX ()
 Gets the X coordinate of the text cursor. More...
 
uint8_t getY ()
 Gets the Y coordinate of the text cursor. More...
 
void scrollDisplayUp ()
 Moves all the text up one row. (Does not change the cursor position.) More...
 
void clear ()
 Clears the text and resets the text cursor to the upper left. More...
 
size_t write (const uint8_t *buffer, size_t size) override
 Writes a string of text. More...
 
size_t write (uint8_t d) override
 Writes a single character of text. More...
 
void loadCustomCharacterFromRam (const uint8_t *picture, uint8_t number)
 Defines a custom character from RAM. More...
 
void loadCustomCharacter (const uint8_t *picture, uint8_t number)
 Defines a custom character. More...
 
void loadCustomCharacter (const char *picture, uint8_t number)
 Defines a custom character. More...
 

Public Attributes

PololuSH1106Core core
 This object handles all low-level communication with the SH1106. More...
 

Detailed Description

Generic SH1106 class implemented using Arduino I/O functions.

Definition at line 149 of file PololuSH1106.h.

Constructor & Destructor Documentation

◆ PololuSH1106()

PololuSH1106::PololuSH1106 ( uint8_t  clk,
uint8_t  mos,
uint8_t  res = 255,
uint8_t  dc = 255,
uint8_t  cs = 255 
)
inline

Creates a new instance of PololuSH1106.

Parameters
clkThe pin to use to control the SH1106 CLK/SCL/D0 (clock input) pin.
mosThe pin to use to control the SH1106 MOS/MOSI/SI/D1 (data input) pin.
resThe pin to use to control the SH1106 RES (reset) pin. If you are not using the RES pin, you can pass 255.
dcThe pin to use to control the SH1106 DC/A0 (data mode / not command mode) pin. If your display module uses 3-wire SPI mode so there is no DC pin to control, you should pass 255.
csSets the pin to use to control the SH1106 CS (chip select) pin. If you are not using the CS pin, you can pass 255. In that case, you should ensure the SH1106's CS pin is driven low when you are communicating with it.

Definition at line 170 of file PololuSH1106.h.

Member Function Documentation

◆ clear()

void PololuSH1106Main< PololuSH1106Core >::clear ( )
inlineinherited

Clears the text and resets the text cursor to the upper left.

After calling this function, the text buffer will consist entirely of space characters.

By default, this function also calls display() to write these changes to the OLED, but noAutoDisplay() disables that behavior.

Definition at line 901 of file PololuSH1106Main.h.

◆ display()

void PololuSH1106Main< PololuSH1106Core >::display ( )
inlineinherited

Writes all of the text/graphics to the OLED.

This also turns on auto display mode, undoing the effect of noAutoDisplay().

Note that this function does not always write to the entire display: for text-only modes, it will normally only write to the portion of the screen containing text.

Definition at line 794 of file PololuSH1106Main.h.

◆ displayPartial()

void PololuSH1106Main< PololuSH1106Core >::displayPartial ( uint8_t  x,
uint8_t  y,
uint8_t  width 
)
inlineinherited

Writes a certain region of text/graphics to the OLED.

This function is like display(), but it only writes text/graphics to the OLED which are in a region corresponding to one or more consecutive characters in a line of text. This function cannot write arbitrary regions.

Most users will not need to call this because the clear(), write(), and print() functions automatically write to the display as needed. You can also use the display() function to write all of the text/graphics.

However, this function is useful to users who have disabled auto display mode, or are directly writing to the text buffer, and want an efficient way to update part of the screen.

Parameters
xThe row number of the text to update (0 means top row).
yThe column number of the first character to update (0 means left-most column).
widthThe number of characters to update.

Definition at line 822 of file PololuSH1106Main.h.

◆ getLinePointer()

uint8_t* PololuSH1106Main< PololuSH1106Core >::getLinePointer ( uint8_t  line)
inlineinherited

Gets a pointer to a line of text in this library's text buffer.

This is for advanced users who want to use their own code to directly manipulate the text buffer.

The returned pointer will point to a region of memory at least 21 bytes long that holds the specified line of text. You can perform arbitrary operations on these bytes.

Note that you should not assume anything about where the lines are in relation to each other, and you should not assume it is safe to write beyond the 21st byte of a line.

Note that functions like snprintf will add a null (0) character at the end of their output. This is probably undesirable if you have configured character 0 to be a custom character using loadCustomCharacter(). Also, it means that the maximum content they can safely write to the text buffer is limited to 19 characters.

Definition at line 862 of file PololuSH1106Main.h.

◆ getX()

uint8_t PololuSH1106Main< PololuSH1106Core >::getX ( )
inlineinherited

Gets the X coordinate of the text cursor.

Definition at line 881 of file PololuSH1106Main.h.

◆ getY()

uint8_t PololuSH1106Main< PololuSH1106Core >::getY ( )
inlineinherited

Gets the Y coordinate of the text cursor.

Definition at line 884 of file PololuSH1106Main.h.

◆ gotoXY()

void PololuSH1106Main< PololuSH1106Core >::gotoXY ( uint8_t  x,
uint8_t  y 
)
inlineinherited

Changes the location of the text cursor.

This function changes the text cursor, which is the location of the text that will be overwritten by the next call to write() or print().

Parameters
xThe column number (0 means left-most column).
yThe row number (0 means top row).

Definition at line 874 of file PololuSH1106Main.h.

◆ init()

void PololuSH1106Main< PololuSH1106Core >::init ( )
inlineinherited

Initializes the OLED if it has not already been initialized.

This resets the OLED, clears the contents of the OLED RAM, sets some default settings, and turns on the display.

Most users do not have to call this, because it is automatically called by any public function in this class that writes to the OLED.

Definition at line 176 of file PololuSH1106Main.h.

◆ invert()

void PololuSH1106Main< PololuSH1106Core >::invert ( )
inlineinherited

Configures the OLED to invert all the pixels, resulting in black-on-white text.

Definition at line 195 of file PololuSH1106Main.h.

◆ loadCustomCharacter() [1/2]

void PololuSH1106Main< PololuSH1106Core >::loadCustomCharacter ( const char *  picture,
uint8_t  number 
)
inlineinherited

Defines a custom character.

This overload is only provided for compatibility existing code that defines char arrays instead of uint8_t arrays.

Definition at line 1005 of file PololuSH1106Main.h.

◆ loadCustomCharacter() [2/2]

void PololuSH1106Main< PololuSH1106Core >::loadCustomCharacter ( const uint8_t *  picture,
uint8_t  number 
)
inlineinherited

Defines a custom character.

Parameters
pictureA pointer to the character dot pattern, in program space.
numberA character code between 0 and 7.

Definition at line 991 of file PololuSH1106Main.h.

◆ loadCustomCharacterFromRam()

void PololuSH1106Main< PololuSH1106Core >::loadCustomCharacterFromRam ( const uint8_t *  picture,
uint8_t  number 
)
inlineinherited

Defines a custom character from RAM.

Parameters
pictureA pointer to the character dot pattern, in RAM.
numberA character code between 0 and 7.

Definition at line 969 of file PololuSH1106Main.h.

◆ noAutoDisplay()

void PololuSH1106Main< PololuSH1106Core >::noAutoDisplay ( )
inlineinherited

Turns off auto display mode.

This causes the clear(), write(), and print() functions to not perform any I/O or write any data to the OLED.

Calling display() will write to the display and turn auto display mode on again.

Definition at line 839 of file PololuSH1106Main.h.

◆ noInvert()

void PololuSH1106Main< PololuSH1106Core >::noInvert ( )
inlineinherited

Configures the OLED to not invert its pixels (the default).

Definition at line 205 of file PololuSH1106Main.h.

◆ noRotate()

void PololuSH1106Main< PololuSH1106Core >::noRotate ( )
inlineinherited

Configures the OLED to use the default orientation.

This is the orientation that results in the text shown on the Graphical OLED Display: 128x64, 1.3", White, SPI from Pololu being the same orientation as the pin labels.

Definition at line 232 of file PololuSH1106Main.h.

◆ reinitialize()

void PololuSH1106Main< PololuSH1106Core >::reinitialize ( )
inlineinherited

Reinitializes the OLED and its settings.

This redoes the initialization that is automatically done by init() the first time any function is called that writes to the OLED.

This can be useful if you want to plug the OLED into the robot after the library has already been initialized.

The screen will be blank after calling this, so you might want to call display() to show the graphics/text that you were shown before.

Definition at line 188 of file PololuSH1106Main.h.

◆ rotate180()

void PololuSH1106Main< PololuSH1106Core >::rotate180 ( )
inlineinherited

Configures the OLED to rotate its display 180 degrees from normal.

Definition at line 215 of file PololuSH1106Main.h.

◆ scrollDisplayUp()

void PololuSH1106Main< PololuSH1106Core >::scrollDisplayUp ( )
inlineinherited

Moves all the text up one row. (Does not change the cursor position.)

Definition at line 887 of file PololuSH1106Main.h.

◆ setContrast()

void PololuSH1106Main< PololuSH1106Core >::setContrast ( uint8_t  contrast)
inlineinherited

Sets the contrast (i.e. brightness) of the OLED.

Parameters
contrastA number between 0 (darkest, but still visible) and 255 (brightest, default).

Definition at line 246 of file PololuSH1106Main.h.

◆ setLayout11x4()

void PololuSH1106Main< PololuSH1106Core >::setLayout11x4 ( )
inlineinherited

Configures this library to use a layout with 11 columns and 4 rows of text.

Note that the last column of text will have one column of pixels cut off. You can choose not to use this column or only use it for narrow characters such as punctuation.

Definition at line 284 of file PololuSH1106Main.h.

◆ setLayout11x4WithGraphics()

void PololuSH1106Main< PololuSH1106Core >::setLayout11x4WithGraphics ( const uint8_t *  graphics)
inlineinherited

Configures this library to use a layout with 11 columns and 4 rows of text, XORed with a graphics buffer.

Parameters
graphicsA pointer to a 1024-byte graphics buffer.

Note that the last column of text will have one column of pixels cut off. You can choose not to use this column or only use it for narrow characters such as punctuation.

Definition at line 300 of file PololuSH1106Main.h.

◆ setLayout21x8()

void PololuSH1106Main< PololuSH1106Core >::setLayout21x8 ( )
inlineinherited

Configures this library to use a layout with 21 columns and 8 rows of text.

Definition at line 310 of file PololuSH1106Main.h.

◆ setLayout21x8WithGraphics()

void PololuSH1106Main< PololuSH1106Core >::setLayout21x8WithGraphics ( const uint8_t *  graphics)
inlineinherited

Configures this library to use a layout with 21 columns and 8 rows of text, XORed with a graphics buffer.

Parameters
graphicsA pointer to a 1024-byte graphics buffer.

Definition at line 322 of file PololuSH1106Main.h.

◆ setLayout8x2()

void PololuSH1106Main< PololuSH1106Core >::setLayout8x2 ( )
inlineinherited

Configures this library to use its default layout, which allows for 8 columns and 2 rows of text.

Definition at line 258 of file PololuSH1106Main.h.

◆ setLayout8x2WithGraphics()

void PololuSH1106Main< PololuSH1106Core >::setLayout8x2WithGraphics ( const uint8_t *  graphics)
inlineinherited

Configures this library to use a layout with 8 columns and 2 rows of text, XORed with a graphics buffer.

Parameters
graphicsA pointer to a 1024-byte graphics buffer.

Definition at line 270 of file PololuSH1106Main.h.

◆ write() [1/2]

size_t PololuSH1106Main< PololuSH1106Core >::write ( const uint8_t *  buffer,
size_t  size 
)
inlineoverrideinherited

Writes a string of text.

This function writes the specified string of text to the text buffer at the location specified by the text cursor (see gotoXY()), and moves the text cursor to the position immediately to the right of the string.

By default, this function also calls displayPartial() to write these changes to the OLED, but noAutoDisplay() disables that behavior.

There is no limit to how much text you can pass to this function, but the text will be discarded when you reach the end of the current line.

To advance to the next line, use gotoXY(). The newline and carriage return characters do not have any special effect on the text cursor position like they might have in a terminal emulator.

This function is called by (certain overloads of) the print() function provided by the Arduino print class.

Definition at line 926 of file PololuSH1106Main.h.

◆ write() [2/2]

size_t PololuSH1106Main< PololuSH1106Core >::write ( uint8_t  d)
inlineoverrideinherited

Writes a single character of text.

This is equivalent to writing a single character using write(const uint8_t *, size_t).

Definition at line 950 of file PololuSH1106Main.h.

Member Data Documentation

◆ core

This object handles all low-level communication with the SH1106.

Definition at line 1012 of file PololuSH1106Main.h.


The documentation for this class was generated from the following file: