Dependents:   DS18B20 DS18B20GSM Astromed Astromed_build20121123

Embed: (wiki syntax)

« Back to documentation index

uOLED Class Reference

uOLED Class Reference

uOLED control class using Serial More...

#include <uOLED.h>

Public Member Functions

 uOLED (PinName serialTX, PinName serialRX, PinName reset)
 Create an instance of the uOLED class.
short getRGB (char red, char green, char blue)
 Convert RGB value into the type of value that the uOLED wants.
bool addBitmappedCharacter (char character, char data[8])
 Add user defined bitmap character into internal memory.
bool blockCopyPaste (char sourceX, char sourceY, char destinationX, char destinationY, char width, char height)
 Copy and paste a specified block of the screen.
bool screenCopy (char x, char y, char width, char height, char sectorHi, char sectorMid, char sectorLow)
 Save a specified block of the screen to the uSD.
bool displayControl (char mode, char value)
 Display control.
bool displayUserBitmappedCharacter (char character, char x, char y, short red, short green, short blue)
 Draw previously defined user bitmap character at specified location (and colour).
bool drawCircle (char x, char y, char radius, short red, short green, short blue)
 Draw a circle.
bool drawCharacter (char character, char column, char row, short red, short green, short blue)
 Draw ASCII character (text format)
bool drawImage (char x, char y, char width, char height, char colorMode, char *pixels)
 Display a bitmap image on the screen at specified location and size.
bool drawImageSD_16bit (char x, char y, char width, char height, char colourMode, char sectorHi, char sectorMid, char sectorLow)
 Load an image from the uSD and display on the screen at specified location and size.
bool drawLine (char x1, char y1, char x2, char y2, short red, short green, short blue)
 Draw a line.
bool drawPolygon (char vertices, char *x, char *y, short red, short green, short blue)
 Draw a polygon (user defined shape) to the screen.
bool drawRectangle (char x, char y, char width, char height, short red, short green, short blue)
 Draw a rectangle.
bool drawText (char column, char row, char font, short red, short green, short blue, char *text)
 Draw text to the screen.
bool drawTextUF (char x, char y, char font, short red, short green, short blue, char width, char height, char *text)
 Draw unformated text to the screen.
bool drawTriangle (char x1, char y1, char x2, char y2, char x3, char y3, short red, short green, short blue)
 Draw a triangle.
bool eraseScreen ()
 Clear the screen.
bool init ()
 Initialize the screen.
bool penSize (char size)
 Set pen size.
bool putPixel (char x, char y, short red, short green, short blue)
 Draw a coloured pixel at designated position.
short readPixel (char x, char y)
 Read the colour of a specified pixel.
bool setBackgroundColour (char red, char green, char blue)
 Replaces the background colour with a new colour.
bool setFont (char font)
 Set font (for future text).
bool textButton (char state, char x, char y, short red, short green, short blue, char font, short textRed, short textGreen, short textBlue, char textWidth, char textHeight, char *text)
 Draw a text button to the screen.
bool textMode (char mode)
 Set text mode (transparent or opaque).
bool versionInfo (bool onScreen, char info[5])
 Retrieve current version info of the device.

Detailed Description

uOLED control class using Serial

The serially controlled uOLEDs by 4D Systems are controlled with only 3 pins:

  • serialTX
  • serialRX
  • reset

While the device includes many serial functions, it is faster to do things from a uSD card. Consider learning the 4DSL scripting language. You can then write your functions in 4DSL storing them on the uSD to later be triggered serially.

Examples use SGC as the uOLED instance name. SGC just happens to be the type of device that I have. Of course, it doesn't matter what you call your instance(s).

Examples use both decimal and hexadecimal numbers. It does not matter which you use for most functions.

Please post a comment on the library page if you spot an error. I will try to fix it quickly.

Example:

 // Draw text on the screen.
 #include "mbed.h"
 #include "uOLED.h"
 
 uOLED SGC(p9, p10, p11);

 int main()
 {    
     SGC.drawText(0, 0, 0, FF, FF, FF, "This is text");
 }

Definition at line 62 of file uOLED.h.


Constructor & Destructor Documentation

uOLED ( PinName  serialTX,
PinName  serialRX,
PinName  reset 
)

Create an instance of the uOLED class.

Parameters:
serialTX- mbed TX pin to be used
serialRX- mbed RX pin to be used
reset- mbed pin to control reset of the uOLED

Example:

 // (serialTX, serialRX, reset)
 uOLED SGC(p9, p10, p11);

Definition at line 13 of file uOLED.cpp.


Member Function Documentation

bool addBitmappedCharacter ( char  character,
char  data[8] 
)

Add user defined bitmap character into internal memory.

Parameters:
characterCharacter index to add to memory. Range is 0-31 (0x00 to 0x1F). 32 8x8 characters.
data[8]8 data bytes that make up the composition of the bitmap character. 8x8 composition is 1 byte wide (8 bits) by 8 bytes deep.

Example:

 // Array containing data for 8x8 "O" character.
 char data[8] = {0x18, 0x24, 0x42, 0x81, 0x81, 0x42, 0x24, 0x18};
 // (characterIndex, characterData)
 SGC.addBitmappedCharacter(0x01, data);

Definition at line 46 of file uOLED.cpp.

bool blockCopyPaste ( char  sourceX,
char  sourceY,
char  destinationX,
char  destinationY,
char  width,
char  height 
)

Copy and paste a specified block of the screen.

Parameters:
sourceXTop left horizontal start position of screen area to be copied.
sourceYTop left vertical start position of screen area to be copied.
destinationXTop left horizontal start position of where copied area is to be pasted.
destinationYTop left vertical start position of where copied area is to be pasted.
widthWidth of screen area to be copied.
heightHeight of screen area to be copied.

Example:

 // (sourceX, sourceY, destinationX, destinationY, width, height)
 SGC.blockCopyPaste(0, 0, 25, 5, 10, 10);

Definition at line 53 of file uOLED.cpp.

bool displayControl ( char  mode,
char  value 
)

Display control.

Display ON/OFF, set contrast, and PowerUp/Shutdown.

Parameters:
modeSets specified mode.
valueValue option for mode.
  • Mode: 01 Display ON/OFF
    • Value: 00 OFF
    • Value: 01 ON
  • Mode: 02 Contrast Adjust
    • Value range: 0x00 to 0x0F
  • Mode: 03 Display PowerUp/Shutdown (low power mode)
    • Value 00 Shutdown
    • Value 01 Powerup

Example:

 // Turn display ON.
 SGC.displayControl(0x01, 0x01)
 // Set contrast to medium.
 SGC.displayControl(0x02, 0x08);
 // Shutdown display.
 SGC.displayControl(0x03, 0x00);

Definition at line 80 of file uOLED.cpp.

bool displayUserBitmappedCharacter ( char  character,
char  x,
char  y,
short  red,
short  green,
short  blue 
)

Draw previously defined user bitmap character at specified location (and colour).

Parameters:
characterCharacter index of previously defined bitmap character. Range is 0 to 31 (0x00 to 0x1F). 32 8x8 characters.
xHorizontal display position of character.
yVertical display position of character.
redAmount of red.
greenAmount of green.
blueAmount of blue.

Example:

 // Display bitmapped character stored in index 01, at location (0x,0y), and colour it red.
 // (characterIndex, x, y, red, green, blue)
 SGC.displayUserBitmappedCharacter(0x01, 0x00, 0x00, 0xFF, 0x00, 0x00);

Definition at line 88 of file uOLED.cpp.

bool drawCharacter ( char  character,
char  column,
char  row,
short  red,
short  green,
short  blue 
)

Draw ASCII character (text format)

Parameters:
characterInbuilt standard ASCII character. Range 32 to 127 (0x20 to 0x7F).
columnHorizontal position of character.

  • range: 0-20 for 5x7 font.
  • range: 0-15 for 8x8 and 8x12 fonts.
rowVertical position of character.
redAmount of red.
greenAmount of green.
blueAmount of blue.

Example:

 // Draw character 'A' at column 0, row 0.  Colour it white.
 // (character, column, row, red, green, blue)
 SGC.drawCharacter(0x41, 0x00, 0x00, 0xFF, 0xFF, 0xFF);

Definition at line 102 of file uOLED.cpp.

bool drawCircle ( char  x,
char  y,
char  radius,
short  red,
short  green,
short  blue 
)

Draw a circle.

Parameters:
xX position of circle center.
yY position of circle center.
radiusRadius of the circle.
redAmount of red.
greenAmount of green.
blueAmount of blue.

Example:

 // Draw a circle centered at (63x, 63y) with a radius of 34 and colour it green.
 // (x, y, radius, red, green, blue)
 SGC.drawCircle(0x3F, 0x3F, 0x22, 0x00, 0xFF, 0x00);

Definition at line 116 of file uOLED.cpp.

bool drawImage ( char  x,
char  y,
char  width,
char  height,
char  colorMode,
char *  pixels 
)

Display a bitmap image on the screen at specified location and size.

Parameters:
xImage horizontal start position (top left).
yImage vertical start position (top left).
widthHorizontal size of the image.
heightVertical size of the image.
colorModeColour mode to use for the image.

  • 0x08 = 256 colour mode (8bits/1byte per pixel)
  • 0x10 = 65K colour mode (16bits/2bytes per pixel)
*pixelsImage pixel data.

  • Colour Mode 0x08 (256 colour mode): Number of pixels = width x height
  • Colour Mode 0x10 (65K colour mode): Number of pixels = 2 x width x height

Definition at line 130 of file uOLED.cpp.

bool drawImageSD_16bit ( char  x,
char  y,
char  width,
char  height,
char  colourMode,
char  sectorHi,
char  sectorMid,
char  sectorLow 
)

Load an image from the uSD and display on the screen at specified location and size.

Parameters:
xImage horizontal start position (top left).
yImage vertical start position (top left).
widthHorizontal size of the image.
heightVertical size of the image.
colorModeColour mode to use for the image.

  • 0x08 = 256 colour mode (8bits/1byte per pixel)
  • 0x10 = 65K colour mode (16bits/2bytes per pixel)
sectorHiHigh sector address.
sectorMidMid sector address.
sectorLowLow sector address.

Definition at line 149 of file uOLED.cpp.

bool drawLine ( char  x1,
char  y1,
char  x2,
char  y2,
short  red,
short  green,
short  blue 
)

Draw a line.

Parameters:
x1Top left horizontal start position.
y1Top left vertical start position.
x2Bottom right horizontal start position.
y2Bottom right vertical end position.
redAmount of red.
greenAmount of green.
blueAmount of blue.

Example:

 // Draw a line starting at (0x, 0y) and ending at (43x, 43y).  Colour it blue.
 // (x1, y1, x2, y2, red, green, blue)
 SGC.drawLine(0x00, 0x00, 0x2B, 0x2B, 0x00, 0x00, 0xFF);

Definition at line 166 of file uOLED.cpp.

bool drawPolygon ( char  vertices,
char *  x,
char *  y,
short  red,
short  green,
short  blue 
)

Draw a polygon (user defined shape) to the screen.

Parameters:
verticesNumber of vertices from 3 to 7.
*xArray of vertices' X coordinates.
*yArray of vertices' Y coordinates.
redAmount of red.
greenAmount of green.
blueAmount of blue.

Example:

 char x[5] = {0, 18, 26, 44, 54};
 char y[5] = {10, 25, 33, 22, 36};
 // Draw a white polygon with 5 vertices located at:
 // (0x, 10y), (18x, 25y), (26x, 33y), (44x, 22y), (54x, 36y)
 // (vertices, *x, *y, red, green, blue)
 SGC.drawPolygon(5, x, y, 255, 255, 255);

Definition at line 181 of file uOLED.cpp.

bool drawRectangle ( char  x,
char  y,
char  width,
char  height,
short  red,
short  green,
short  blue 
)

Draw a rectangle.

Parameters:
xTop left horizontal start position.
yTop left vertical start position.
widthBottom right horizontal end position.
heightBottom right vertical end position.
redAmount of red.
greenAmount of green.
blueAmount of blue.

Example:

 // Draw rectangle starting at (0x, 0y) and ending at (40x, 40y).  Colour red.
 // (x, y, width, height, red, green, blue)
 SGC.drawRectangle(0, 0, 40, 40, 255, 0, 0);

Definition at line 196 of file uOLED.cpp.

bool drawText ( char  column,
char  row,
char  font,
short  red,
short  green,
short  blue,
char *  text 
)

Draw text to the screen.

Parameters:
columnX coordinate for text placement.
rowY coordinate for text placement.
fontWhich font to use (Uses 0, 1, or 2). More fonts can be added.
colorFont colour to use.
*textCharacter array (string) to be displayed.

Example:

 // Draw string "This is text" at (0, 0) with font set 0, coloured white.
 // (column, row, font, red, green, blue, "text")
 SGC.drawText(0, 0, 0, 0xFF, 0xFF, 0xFF, "This is text");

Definition at line 211 of file uOLED.cpp.

bool drawTextUF ( char  x,
char  y,
char  font,
short  red,
short  green,
short  blue,
char  width,
char  height,
char *  text 
)

Draw unformated text to the screen.

The manual describes this as "graphics format".

Parameters:
xX coordinate for text placement.
yY coordinate for text placement.
fontWhich font to use (Uses 0, 1, or 2). More fonts can be added.
redAmount of red in text colour RGB value.
greenAmount of green in text colour RGB value.
blueAmount of blue in text colour RGB value.
widthText width.
heightText height.
*textCharacter array (string) to be displayed.

Example:

 // Draw unformatted text string "This is text" at (0, 0) with font set 0, coloured white with zero (1x) magnification.
 SGC.drawTextUF(0, 0, 0, 255, 255, 255, 1, 1, "This is text");

Definition at line 228 of file uOLED.cpp.

bool drawTriangle ( char  x1,
char  y1,
char  x2,
char  y2,
char  x3,
char  y3,
short  red,
short  green,
short  blue 
)

Draw a triangle.

Vertices must be defined counter clockwise.

Parameters:
x1Vertice 1 X coordinate.
y1Vertice 1 Y coordinate.
x2Vertice 2 X coordinate.
y2Vertice 2 Y coordinate.
x3Vertice 3 X coordinate.
y3Vertice 3 Y coordinate.
redAmount of red.
blueAmount of blue.
greenAmount of green.

Example:

 // Draw a red triangle with vertices:
 // (0x, 0y), (0x, 40y), (40x, 0y)
 // (x1, y1, x2, y2, x3, y3, red, green, blue)
 SGC.drawTriangle(0, 0, 0, 40, 40, 0, 255, 0, 0);

Definition at line 246 of file uOLED.cpp.

bool eraseScreen (  )

Clear the screen.

Remove everything except the background colour.

Parameters:
returnssuccess or failure.

Example:

 // Do you really need an example? :)
 SGC.eraseScreen();

Definition at line 264 of file uOLED.cpp.

short getRGB ( char  red,
char  green,
char  blue 
)

Convert RGB value into the type of value that the uOLED wants.

Parameters:
redRed value.
greenGreen value.
blueBlue value.

Example:

 // (red, green, blue)
 SGC.getRGB(120, 255, 50);

Definition at line 38 of file uOLED.cpp.

bool init (  )

Initialize the screen.

This must be completed before any other communication with the device.

Timing allows for at least 500ms delay for initialization.

Parameters:
returnsbool indicating success or failure of initialization.

Example:

 // Must be done before anything else
 SGC.init();

Definition at line 270 of file uOLED.cpp.

bool penSize ( char  size )

Set pen size.

Sets if objects should be drawn solid or wire frame. Does not apply to polygon function.

Parameters:
sizeSets solid or wire frame.

  • 0x00 = Solid
  • 0x01 = Wire frame.

Example:

 // Draw objects solid
 SGC.penSize(0);
 // Draw objects wire frame
 SGC.penSize(1);

Definition at line 284 of file uOLED.cpp.

bool putPixel ( char  x,
char  y,
short  red,
short  green,
short  blue 
)

Draw a coloured pixel at designated position.

Parameters:
xHorizontal position of pixel.
yVertical position of pixel.
redAmount of red.
greenAmount of green.
blueAmount of blue.

Example:

 // Draw a blue pixel at (10x, 10y).
 // (x, y, red, green, blue)
 SGC.putPixel(10, 10, 0, 0, 255);

Definition at line 291 of file uOLED.cpp.

short readPixel ( char  x,
char  y 
)

Read the colour of a specified pixel.

Parameters:
xX coordinate.
yY coordinate.
returns2 byte pixel colour in RGB format.

  • MSB: R4R3R2R1R0G5G4G3
  • LSB: G2G1G0B4B3B2B1B0

Example:

 // Read pixel colour at location (20x, 20y).
 short pixelColour = SGC.readPixel(20, 20);

Definition at line 305 of file uOLED.cpp.

bool screenCopy ( char  x,
char  y,
char  width,
char  height,
char  sectorHi,
char  sectorMid,
char  sectorLow 
)

Save a specified block of the screen to the uSD.

Parameters:
xTop left horizontal start position of screen area to be copied.
yTop left vertical start position of screen area to be copied.
widthWidth of screen area to be copied.
heightHeight of screen area to be copied.
sectorHiHigh sector address.
sectorMidMid sector address.
sectorLowLow sector address.

Example:

 // Save a block of the screen from (0x, 0y) to (20x, 20y) and save it on the uSD
 // at (0x00, 0x10, 0x66)
 // (x, y, width, height, sectorHi, sectorMid, sectorLow)
 SGC.screenCopy(0, 0, 20, 20, 0x00, 0x10, 0x66);

Definition at line 65 of file uOLED.cpp.

bool setBackgroundColour ( char  red,
char  green,
char  blue 
)

Replaces the background colour with a new colour.

Most functions call this internally.

Parameters:
redRed value (0 to 255).
greenGreen value (0 to 255).
blueBlue value (0 to 255).

Example:

 // Set background colour to red.
 // (red, green, blue)
 SGC.setBackgroundColour(255, 0, 0);

Definition at line 317 of file uOLED.cpp.

bool setFont ( char  font )

Set font (for future text).

3 default fonts are supplied. Further font sets can be added.

Parameters:
fontFont selection. Either a default or otherwise.

  • DEFAULT: 0x00 = 5x7 small size font set
  • DEFAULT: 0x01 = 8x8 medium size font set
  • DEFAULT: 0x02 = 8x12 large size font set

Example:

 // Use default 5x7 font set
 SGC.setFont(0);
 // Use default 8x12 font set
 SGC.setFont(2);

Definition at line 329 of file uOLED.cpp.

bool textButton ( char  state,
char  x,
char  y,
short  red,
short  green,
short  blue,
char  font,
short  textRed,
short  textGreen,
short  textBlue,
char  textWidth,
char  textHeight,
char *  text 
)

Draw a text button to the screen.

Parameters:
stateButton down (0x00) or button up (0x01).
xTop left horizontal start position.
yTop left vertical start position.
redAmount of red (for button not text).
greenAmount of green (for button not text).
blueAmount of blue (for button not text).
fontSet which font set to use for the button. 3 default font sets are supplied and more can be added.

  • DEFAULT: 0x00 = 5x7 small size font set
  • DEFAULT: 0x01 = 8x8 medium size font set
  • DEFAULT: 0x02 = 8x12 large size font set
textRedAmount of red for text.
textGreenAmount of green for text.
textBlueAmount of blue for text.
textWidthWidth of characters (text). Affect total width of string and button.
textHeightHeight of characters (text). Affects total height of string and button.
*textCharacter array (string) to display in the button.

Example:

 // Draw a text button in the unpressed state starting at (0x, 0y).
 // Button colour is red, text colour is white.  Text magnification is zero (1x).
 // (state, x, y, red, green, blue, font, textRed, textGreen, textBlue, textWidth, textHeight, "Text");
 SGC.textButton(1, 0, 0, 255, 0, 0, 0, 255, 255, 255, 1, 1, "Button text");

Definition at line 336 of file uOLED.cpp.

bool textMode ( char  mode )

Set text mode (transparent or opaque).

Opaque text has a rectangle drawn behind it (blocking out what is under it) and transparent text does not.

Parameters:
modeSet text to transparent (0x00) or opaque (0x01).

Example:

 // Set text mode to transparent.
 SGC.textMode(0);

Definition at line 358 of file uOLED.cpp.

bool versionInfo ( bool  onScreen,
char  info[5] 
)

Retrieve current version info of the device.

Response:

device_type Indicates device type.

  • 0x00 = micro-OLED
  • 0x01 = micro-LCD
  • 0x02 = micro-VGA

hardware_rev Indicates device hardware version.

firmware_rev Indicates device firmware version.

horizontal_res Indicates the horizontal resolution of the display.

  • 0x22 = 220 pixels
  • 0x28 = 128 pixels
  • 0x32 = 320 pixels
  • 0x60 = 160 pixels
  • 0x64 = 64 pixels
  • 0x76 = 176 pixels
  • 0x96 = 96 pixels

vertical_res Indicates the vertical resolution of the display.

  • See horizontal_res (identical).
Parameters:
onScreenSet output option.

  • 0x00 = Output to serial port only.
  • 0x01 = Output to serial port and screen.
*infoCharacter array to store results.

Example:

 // Request version info, pass in character array to store results.
 char info[5];
 SGC.versionInfo(1, info);
 printf("\n\nVersion info:\n\n");
 for(int i = 0; i < 5; i++)
 {
    printf("0x%X\n", info[i]);
 }

Definition at line 365 of file uOLED.cpp.