Library for drawing on the Hexiwear's OLED - more features being actively worked on

Dependents:   Hexidraw_Demo Hexiwear-FinalProject_v2

Discussion: https://developer.mbed.org/forum/team-4615-Hexiwear-community/topic/26595/

Hexidraw is a library for drawing on the Hexiwear's OLED. Be aware that it is not very optimized, so drawing may be slow, especially when drawing on large areas of the screen.

Please see the wiki for API documentation.

Features:

  • Screen fill with a color
  • Drawing filled rectangles
  • Drawing circles with a set radius and line width
  • Setting individual pixels
  • Turning on and off the OLED's sleep mode
  • Drawing images

Example project: https://developer.mbed.org/users/keithm01/code/Hexidraw_Demo/

Revision:
1:82ccc138bbe6
Parent:
0:2d3fcb6dabd4
Child:
2:ef14c6dd6b93
--- a/hexidraw.cpp	Fri Aug 19 01:17:28 2016 +0000
+++ b/hexidraw.cpp	Fri Aug 19 16:28:09 2016 +0000
@@ -169,7 +169,7 @@
 void OLED::cursor(int x, int y)   //goTo
 {
     if ((x >= OLED_WIDTH) || (y >= OLED_HEIGHT)) return;
-
+    x+=OLED_COL_OFFSET;
     // set x and y coordinate
     writeCommand(OLED_CMD_SET_COLUMN);
     writeData(x);
@@ -182,6 +182,9 @@
     writeCommand(OLED_CMD_WRITERAM);
 }
 
+void OLED::clear (uint16_t color){
+    rect(0, 0, OLED_WIDTH, OLED_HEIGHT, color);
+}
 void OLED::rect(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t fillcolor)
 {
     // Bounds check
@@ -197,6 +200,8 @@
     if (x+w > OLED_WIDTH) {
         w = OLED_WIDTH - x - 1;
     }
+    
+    x+= OLED_COL_OFFSET;
 
     // set location
     writeCommand(OLED_CMD_SET_COLUMN);
@@ -217,6 +222,16 @@
     }
 }
 
+void OLED::dim()
+{
+    for ( int i = 0; i < 16; i++ )
+    {
+        writeCommand( OLED_CMD_CONTRASTMASTER);
+        writeData( 0xC0 | (0xF-i));
+        wait( 20 );
+    }
+}
+
 uint16_t Color565(uint8_t r, uint8_t g, uint8_t b)
 {
     uint16_t c;