0.95-inch RGB OLED Display library  0.5
Library for the 0.95-inch RGB OLED Display library (Parallax Part #28087)
Macros | Functions
oledc.h File Reference
#include <propeller.h>

Go to the source code of this file.

Macros

Fonts
   One medium and one large font can be included
#define FONT_SANS   0Sans Serif (Console) font    
 
#define FONT_SERIF   1Serif (Typewriter) font    
 
#define FONT_SCRIPT   2Script (Handwriting) font    
 
#define FONT_BUBBLE   3Bubble (Outline) font    
 
Text Sizes
#define FONT_SMALL   1
 
#define FONT_MEDIUM   2
 
#define FONT_LARGE   3
 
Named Colors
#define       WHITE   0xFFFF
 
#define       PINK   0xFD59
 
#define       MAGENTA   0xF319
 
#define       RED   0xC082
 
#define       DARKRED   0xA162
 
#define       REDORANGE   0xD261
 
#define       LIGHTORANGE   0xFEB6
 
#define       ORANGE   0xFC00
 
#define       YELLOWORANGE   0xFCC0
 
#define       GOLD   0xF704
 
#define       YELLOW   0xF744
 
#define       LEMON   0xF7D3
 
#define       YELLOWGREEN   0x5600
 
#define       GREEN   0x1C62
 
#define       DARKGREEN   0x02C0
 
#define       GREENBLUE   0x0C75
 
#define       CYAN   0x5E97
 
#define       LIGHTBLUE   0x857B
 
#define       SKYBLUE   0x0E3E
 
#define       BLUE   0x2B16
 
#define       NAVYBLUE   0x0007
 
#define       VIOLET   0x7A37
 
#define       PURPLE   0x7A37
 
#define       RASPBERRY   0xA82E
 
#define       TAN   0xCC2A
 
#define       LIGHTBROWN   0xBB44
 
#define       BRONZE   0xA440
 
#define       BROWN   0x9201
 
#define       DARKBROWN   0x7269
 
#define       LIGHTGRAY   0xBDD7
 
#define       GRAY   0x8410
 
#define       DARKGRAY   0x3186
 
#define       BLACK   0x0000
 

Functions

void oledc_init (char SID, char SCLK, char CS, char RS, char RST, char screen_rotation)
 Initializes the OLED screen by setting up it's SPI and control pins. More...
 
unsigned int oledc_color565 (char r, char g, char b)
 Generates a 2-byte (16-bit) color code (RRRRRGGGGGGBBBBB format) for use with the OLED screen. More...
 
Drawing Functions
void oledc_drawPixel (int x, int y, unsigned int color)
 Draws a single pixel on the screen in the specified color. More...
 
void oledc_drawLine (int x0, int y0, int x1, int y1, unsigned int color)
 Draws a line on the screen in the specified color. More...
 
void oledc_drawFastVLine (int x, int y, int h, unsigned int color)
 Draws a vertical line on the screen in the specified color. More...
 
void oledc_drawFastHLine (int x, int y, int w, unsigned int color)
 Draws a horizontal line on the screen in the specified color. More...
 
void oledc_drawCircle (int x0, int y0, int r, unsigned int color)
 Draws a circle on the screen in the specified color. More...
 
void oledc_fillCircle (int x0, int y0, int r, unsigned int color)
 Draws a filled circle on the screen in the specified color. More...
 
void oledc_drawRect (int x, int y, int w, int h, unsigned int color)
 Draws a rectangle on the screen in the specified color. More...
 
void oledc_fillRect (int x, int y, int w, int h, unsigned int color)
 Draws a filled rectangle on the screen in the specified color. More...
 
void oledc_drawRoundRect (int x, int y, int w, int h, int r, unsigned int color)
 Draws a rectangle with rounded corners on the screen in the specified color. More...
 
void oledc_fillRoundRect (int x, int y, int w, int h, int r, unsigned int color)
 Draws a filled rectangle with rounded corners on the screen in the specified color. More...
 
void oledc_drawTriangle (int x0, int y0, int x1, int y1, int x2, int y2, unsigned int color)
 Draws a triangle with on the screen in the specified color. More...
 
void oledc_fillTriangle (int x0, int y0, int x1, int y1, int x2, int y2, unsigned int color)
 Draws a filled triangle with on the screen in the specified color. More...
 
void oledc_bitmap (char *imgdir, int x0, int y0)
 Displays a properly formatted bitmap (.BMP) image on the screen. The image must be saved as a Device Independant Bitmap with r5g6b5 (16-bit), normal row-order encoding. More...
 
Text Functions
void oledc_setTextSize (char s)
 Sets the size of the font to be used. Range is from 1 to 3. Size (1) is 5x7 (6x8 spacing) pixels, size (2) is 11x15 (12x16 spacing) pixels and size (3) is 15x23 (16x24 spacing) pixels. More...
 
void oledc_setTextFont (char f)
 Sets the font face to be used. Range is from 0 to 3. Font face (0) is a sans-serif (console) font, face (1) is serif (typewriter) font, face (2) is a script (handwriting) font and face (3) is a bubble (outline/cartoon) font.More...
 
void oledc_setTextColor (unsigned int c, unsigned int b)
 Sets the color of the font and the color of the background (highlighting) to be used. Setting the text color and text background to the same color will make the background color transparent. More...
 
void oledc_setTextWrap (char w)
 Toggles automatic wrapping of text printed to the screen. (0) turns wrapping off, (1) turning wrapping on. More...
 
void oledc_setCursor (int x, int y, char size)
 Sets the cursor position based on the size parameter. More...
 
int oledc_print (const char *fmt,...)
 Print format "..." args to the screen. The output is limited to 128 bytes. More...
 
int oledc_drawNumber (float d, int r)
 Prints a number to the screen starting at the cursor position. Output is limited to 64 bytes. More...
 
int oledc_drawText (char *myString)
 Prints a string of text to the screen starting at the cursor position. Output is limited to 64 bytes. More...
 
int oledc_getCursorX ()
 Returns the current horizontal position of the cursor, measured from the left side of the screen in pixels. More...
 
int oledc_getCursorY ()
 Returns the current vertical position of the cursor, measured from the top of the screen in pixels. More...
 
Screen Manipulation Functions
void oledc_clear (int x0, int y0, int w, int h)
 Clears (sets to black) a rectangular area of the screen. More...
 
void oledc_copy (int x0, int y0, int w, int h, int x2, int y2)
 Creates a copy a rectangular area of the screen at another position on the screen. More...
 
void oledc_sleep ()
 Turn the display off without changing it's contents (make it sleep). More...
 
void oledc_wake ()
 Turn the display back on if it was put to sleep. Whatever the screen was displaying on the screen before it was put to sleep will return. More...
 
char oledc_getRotation ()
 Returns the screen's orientation. (0) means the pins are pointed upwards, (1) means the pins are pointed to the left, (2) means the pins are pointed down and (3) means the pins are pointed to the right. More...
 
void oledc_setRotation (char x)
 Low-level function used by the begin function to set up the screen's orientation. More...
 
int oledc_getWidth ()
 Returns the width of the screen per the screen's current orientation. More...
 
int oledc_getHeight ()
 Returns the height of the screen per the screen's current orientation. More...
 
void oledc_invertDisplay ()
 Inverts the screen. More...
 
void oledc_scrollStart (char h, char v)
 Starts scrolling the entire image on the screen horizontally, vertically, or both. More...
 
void oledc_scrollStop ()
 Stops scrolling the screen. More...
 
int oledc_isScrolling ()
 Returns (1) if the screen is currently scrolling and (0) if it is not. More...
 

Macro Definition Documentation

#define FONT_SMALL   1
#define FONT_MEDIUM   2
#define FONT_LARGE   3


#define BLACK   0x0000
#define BLUE   0x2B16
#define BRONZE   0xA440
#define BROWN   0x9201
#define CYAN   0x5E97
#define DARKBROWN   0x7269
#define DARKGRAY   0x3186
#define DARKGREEN   0x03CE
#define DARKRED   0xA162
#define GOLD   0xF704
#define GRAY   0x8410
#define GREEN   0x1C62
#define GREENBLUE   0x0C75
#define LEMON   0xF7D3
#define LIGHTBLUE   0x857B
#define LIGHTBROWN   0xBB44
#define LIGHTGRAY   0xBDD7
#define LIGHTORANGE   0xFEB6
#define MAGENTA   0xF319
#define NAVYBLUE   0x0007
#define ORANGE   0xFC00
#define PINK   0xFD59
#define PURPLE   0x7A37
#define RASPBERRY   0xA82E
#define RED   0xC082
#define REDORANGE   0xD261
#define SKYBLUE   0x0E3E
#define TAN   0xCC2A
#define TFTHEIGHT   64
#define TFTWIDTH   96
#define VIOLET   0x7A37
#define WHITE   0xFFFF
#define YELLOW   0xF744
#define YELLOWGREEN   0x5600
#define YELLOWORANGE   0xFCC0

Function Documentation

void oledc_bitmap ( char *  imgdir,
int  x0,
int  y0 
)

Displays a properly formatted bitmap (.BMP) image on the screen. The image must be saved as a Device Independant Bitmap with r5g6b5 (16-bit), normal row-order encoding.

Note
The SD card must be properly mounted before using this function.
Parameters
*imgdirFilename of the image saved to the SD card to be displayed.
x0Horizontal position of the top-left corner of the bitmap image to be displayed, counted from the left side of the screen.
y0Vertical position of the top-left corner of the bitmap image to be displayed, counted down from the top of the screen.
void oledc_clear ( int  x0,
int  y0,
int  w,
int  h 
)

Clears (sets to black) a rectangular area of the screen.

Parameters
x0Starting horizontal coordinate of the box to be cleared, counted from the left side of the screen.
y0Starting vertical coordinate of the box to be cleared, counted down from the top of the screen.
wWidth of the box to be cleared.
hheight of the box to be cleared.
unsigned int oledc_color565 ( char  r,
char  g,
char  b 
)

Generates a 2-byte (16-bit) color code (RRRRRGGGGGGBBBBB format) for use with the OLED screen.

Parameters
rAmount of Red in the color, range is from 0-255.
gAmount of Green in the color, range is from 0-255.
bAmount of Blue in the color, range is from 0-255.
void oledc_copy ( int  x0,
int  y0,
int  w,
int  h,
int  x2,
int  y2 
)

Creates a copy a rectangular area of the screen at another position on the screen.

Parameters
x0Starting horizontal coordinate of the box to be copied, counted from the left side of the screen.
y0Starting vertical coordinate of the box to be copied, counted down from the top of the screen.
wWidth of the box to be copied.
hheight of the box to be copied.
x2Horizontal coordinate where the copied box is to be pasted.
y2Vertical coordinate where the copied box is to be pasted.
void oledc_drawCircle ( int  x0,
int  y0,
int  r,
unsigned int  color 
)

Draws a circle on the screen in the specified color.

Parameters
x0Horizontal coordinate of the center of the circle, counted from the left side of the screen.
y0Vertical coordinate of the center of the circle, counted down from the top of the screen.
rRadius of the circle.
colorColor of the pixel, in r5g6b5 format.
void oledc_drawFastHLine ( int  x,
int  y,
int  w,
unsigned int  color 
)

Draws a horizontal line on the screen in the specified color.

Parameters
xStarting horizontal coordinate of the line, counted from the left side of the screen.
yStarting vertical coordinate of the line, counted down from the top of the screen.
wLength of the line.
colorColor of the line, in r5g6b5 format.
void oledc_drawFastVLine ( int  x,
int  y,
int  h,
unsigned int  color 
)

Draws a vertical line on the screen in the specified color.

Parameters
xStarting horizontal coordinate of the line, counted from the left side of the screen.
yStarting vertical coordinate of the line, counted down from the top of the screen.
hLength of the line.
colorColor of the line, in r5g6b5 format.
void oledc_drawLine ( int  x0,
int  y0,
int  x1,
int  y1,
unsigned int  color 
)

Draws a line on the screen in the specified color.

Parameters
x0Starting horizontal coordinate of the line, counted from the left side of the screen.
y0Starting vertical coordinate of the line, counted down from the top of the screen.
x1Ending horizontal coordinate of the line.
y1Ending vertical coordinate of the line.
colorColor of the pixel, in r5g6b5 format.
void oledc_drawPixel ( int  x,
int  y,
unsigned int  color 
)

Draws a single pixel on the screen in the specified color.

Parameters
xHorizontal coordinate of the pixel, counted from the left side of the screen.
yVertical coordinate of the pixel, counted down from the top of the screen.
colorColor of the pixel, in r5g6b5 format.
void oledc_drawRect ( int  x,
int  y,
int  w,
int  h,
unsigned int  color 
)

Draws a rectangle on the screen in the specified color.

Parameters
xStarting horizontal coordinate of the rectangle, counted from the left side of the screen.
yStarting vertical coordinate of the rectangle, counted down from the top of the screen.
wWidth of the rectangle.
hHeight of the rectangle.
colorColor of the rectangle, in r5g6b5 format.
void oledc_drawRoundRect ( int  x,
int  y,
int  w,
int  h,
int  r,
unsigned int  color 
)

Draws a rectangle with rounded corners on the screen in the specified color.

Parameters
xStarting horizontal coordinate of the rectangle, counted from the left side of the screen.
yStarting vertical coordinate of the rectangle, counted down from the top of the screen.
wWidth of the rectangle.
hHeight of the rectangle.
rRadius of the rounded corners.
colorColor of the rectangle, in r5g6b5 format.
void oledc_drawTriangle ( int  x0,
int  y0,
int  x1,
int  y1,
int  x2,
int  y2,
unsigned int  color 
)

Draws a triangle with on the screen in the specified color.

Parameters
x0Horizontal coordinate of the first vertex (corner) of the triangle, counted from the left side of the screen.
y0Vertical coordinate of the first vertex (corner) of the triangle, counted down from the top of the screen.
x1Horizontal coordinate of the second vertex of the triangle.
y1Vertical coordinate of the first vertex of the triangle.
x2Horizontal coordinate of the third vertex of the triangle.
y2Vertical coordinate of the third vertex of the triangle.
colorColor of the triangle, in r5g6b5 format.
void oledc_fillCircle ( int  x0,
int  y0,
int  r,
unsigned int  color 
)

Draws a filled circle on the screen in the specified color.

Parameters
x0Horizontal coordinate of the center of the circle, counted from the left side of the screen.
y0Vertical coordinate of the center of the circle, counted down from the top of the screen.
rRadius of the circle.
colorColor of the pixel, in r5g6b5 format.
void oledc_fillRect ( int  x,
int  y,
int  w,
int  h,
unsigned int  color 
)

Draws a filled rectangle on the screen in the specified color.

Parameters
xStarting horizontal coordinate of the rectangle, counted from the left side of the screen.
yStarting vertical coordinate of the rectangle, counted down from the top of the screen.
wWidth of the rectangle.
hHeight of the rectangle.
colorColor of the rectangle, in r5g6b5 format.
void oledc_fillRoundRect ( int  x,
int  y,
int  w,
int  h,
int  r,
unsigned int  color 
)

Draws a filled rectangle with rounded corners on the screen in the specified color.

Parameters
xStarting horizontal coordinate of the rectangle, counted from the left side of the screen.
yStarting vertical coordinate of the rectangle, counted down from the top of the screen.
wWidth of the rectangle.
hHeight of the rectangle.
rRadius of the rounded corners.
colorColor of the rectangle, in r5g6b5 format.
void oledc_fillTriangle ( int  x0,
int  y0,
int  x1,
int  y1,
int  x2,
int  y2,
unsigned int  color 
)

Draws a filled triangle with on the screen in the specified color.

Parameters
x0Horizontal coordinate of the first vertex (corner) of the triangle, counted from the left side of the screen.
y0Vertical coordinate of the first vertex (corner) of the triangle, counted down from the top of the screen.
x1Horizontal coordinate of the second vertex of the triangle.
y1Vertical coordinate of the first vertex of the triangle.
x2Horizontal coordinate of the third vertex of the triangle.
y2Vertical coordinate of the third vertex of the triangle.
colorColor of the triangle, in r5g6b5 format.
int oledc_getCursorX ( )

Returns the current horizontal position of the cursor, measured from the left side of the screen in pixels.

int oledc_getCursorY ( )

Returns the current vertical position of the cursor, measured from the top of the screen in pixels.

int oledc_getHeight ( )

Returns the height of the screen per the screen's current orientation.

char oledc_getRotation ( )

Returns the screen's orientation. (0) means the pins are pointed upwards, (1) means the pins are pointed to the left, (2) means the pins are pointed down and (3) means the pins are pointed to the right.

int oledc_getWidth ( )

Returns the width of the screen per the screen's current orientation.

void oledc_init ( char  CS,
char  SID,
char  SCLK,
char  RS,
char  RST,
char  screen_rotation 
)

Initializes the OLED screen by setting up it's SPI and control pins.

Parameters
SIDwhich pin is connected to the Serial Data In pin, marked "DIN".
SCLKwhich pin is connected to the Serial Clock pin, marked "CLK".
CSwhich pin is connected to the Chip Select pin, marked "CS".
RSwhich pin is connected to the Read Status pin, marked "D/C".
RSTwhich pin is connected to the Reset pin, marked "RST".
screen_rotationSets up the OLED screen and establishes its orientation. (0) means the pins are pointed upwards, (1) means the pins are pointed to the left, (2) means the pins are pointed down and (3) means the pins are pointed to the right.
void oledc_invertDisplay ( )

Inverts the screen.

int oledc_isScrolling ( )

Returns (1) if the screen is currently scrolling and (0) if it is not.

int oledc_print ( const char *  fmt,
  ... 
)

Print format "..." args to the screen. The output is limited to 128 bytes.

int oledc_drawNumber ( float  d,
int  r 
)

Prints a number to the screen starting at the cursor position. Output is limited to 64 bytes.

Parameters
dNumber to be printed to the screen. The number can be either a floating point decimal or an integer.
rThe number of decimals to display following the decimal point (for floating point numbers) or the number base to display the number in (for integers); HEX, BIN, OCT, and DEC are acceptable values. Negative numbers in bases other than DEC (10) will display "Err".
int oledc_drawText ( char *  myString,
)

Prints a number to the screen starting at the cursor position. Output is limited to 64 bytes.

void oledc_scrollStart ( char  h,
char  v 
)

Starts scrolling the entire image on the screen horizontally, vertically, or both.

Note
the screen's horizontal displacement will persist after scrolling has stopped, but its vertical displacement will not.
Parameters
hHorizontal scrolling in rows per interval. (0) turns off horizontal scrolling, negative integers scroll to the left and positive integers scroll to the right.
vVertical scrolling columns per interval. (0) turns off vertical scrolling, negative integers scroll down and positive integers scroll up.
void oledc_scrollStop ( )

Stops scrolling the screen.

void oledc_setCursor ( int  x,
int  y,
char  size 
)

Sets the cursor position based on the size parameter.

Parameters
xHorizontal position of the cursor, counted from the left side of the screen.
yVertical position of the cursor, counted down from the top of the screen.
sizeThe size of the cursor. Correlated to font size: (0) moves the cursor in 1 pixel increments, (1) moves the cursor in font size 1 character increments, (2) moves the cursor in font size 2 increments and (3) moves the cursor in font size 3 increments
void oledc_setTextColor ( unsigned int  c,
unsigned int  b 
)

Sets the color of the font and the color of the background (highlighting) to be used. Setting the text color and text background to the same color will make the background color transparent.

Parameters
cColor of the font, in r5g6b5 format.
bColor of the font's background, in r5g6b5 format. To make the background transparent, set to the same color as the font itself.
void oledc_setTextFont ( char  f)

Sets the font face to be used. Range is from 0 to 3. Font face (0) is a sans-serif (console) font, face (1) is serif (typewriter) font, face (2) is a script (handwriting) font and face (3) is a bubble (outline/cartoon) font.

void oledc_setTextSize ( char  s)

Sets the size of the font to be used. Range is from 1 to 3. Size (1) is 5x7 (6x8 spacing) pixels, size (2) is 11x15 (12x16 spacing) pixels and size (3) is 15x23 (16x24 spacing) pixels.

void oledc_setTextWrap ( char  w)

Toggles automatic wrapping of text printed to the screen. (0) turns wrapping off, (1) turning wrapping on.

void oledc_sleep ( char  w)

Turn the display off without changing it's contents (make it sleep).

void oledc_wake ( char  w)

Turn the display back on if it was put to sleep. Whatever the screen was displaying on the screen before it was put to sleep will return.