Demonstration of SSD1308 OLED driver library

Dependencies:   mbed SSD1308_128x64_I2C

Files at this revision

API Documentation at this revision

Comitter:
wim
Date:
Sat Jun 30 14:44:39 2012 +0000
Parent:
0:2ded56b8407d
Child:
2:d86478c0f5da
Commit message:
First tested version

Changed in this revision

SSD1308.cpp Show annotated file Show diff for this revision Revisions of this file
SSD1308.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed_logo.h Show annotated file Show diff for this revision Revisions of this file
--- a/SSD1308.cpp	Tue Jun 19 20:00:10 2012 +0000
+++ b/SSD1308.cpp	Sat Jun 30 14:44:39 2012 +0000
@@ -1,16 +1,15 @@
-// I2Cdev library collection - SSD1308 I2C device class header file
-// Based on Solomon Systech SSD1308 datasheet, rev. 1, 10/2008
-//  8/25/2011 by Andrew Schamp <schamp@gmail.com>
-// 19/06/2012 Ported to mbed (WH)
+// SSD1308 I2C device class file
+//   Based on Solomon Systech SSD1308 datasheet, rev. 1, 10/2008
+//   The SSD1308 is used for example in the Seeed 128x64 OLED Display
+//   http://www.seeedstudio.com/depot/grove-oled-display-12864-p-781.html?cPath=163_167
 //
-// This I2C device library is using (and submitted as a part of) Jeff Rowberg's I2Cdevlib library,
+// The original code is using (and submitted as a part of) Jeff Rowberg's I2Cdevlib library,
 // which should (hopefully) always be available at https://github.com/jrowberg/i2cdevlib
-// Note WH: I2Cdevlib not used for mbed port
 //
 // Changelog:
-//     2011-08-25 - initial release
-//     2012-06-19 - Ported to mbed (WH)
-        
+//   2011-08-25 - initial release by Andrew Schamp <schamp@gmail.com>
+//   2012-06-19 - Ported to mbed and optimised (WH)
+//       
 /* ============================================
 I2Cdev device library code is placed under the MIT license
 Copyright (c) 2011 Andrew Schamp
@@ -38,59 +37,138 @@
 #include "mbed.h"
 #include "SSD1308.h"
 
-#define SSD1308_USE_FONT
+//#define SSD1308_USE_FONT
 //#ifdef SSD1308_USE_FONT
 #include "FixedWidthFont.h"
 //#endif
 
+//Constructor
+//
 SSD1308::SSD1308(I2C &i2c, uint8_t deviceAddress) : _i2c(i2c) {
 //  m_devAddr = deviceAddress; 
   
   _writeOpcode = deviceAddress & 0xFE; // low order bit = 0 for write
   _readOpcode  = deviceAddress | 0x01; // low order bit = 1 for read  
+  
+  initialize(); 
 }
 
+// High level Init, most settings remain at Power-On reset value
+//
 void SSD1308::initialize() {
   setHorizontalAddressingMode();
   clearDisplay();
 }
 
+
+#if(0)
+// Standard version
 void SSD1308::clearDisplay() {
-  setDisplayOff();
+  //setDisplayOff();
   setPageAddress(0, MAX_PAGE);  // all pages
   setColumnAddress(0, MAX_COL); // all columns
-  for (uint8_t page = 0; page < PAGES; page++)
-  {
-    for (uint8_t col = 0; col < COLUMNS; col++)
-    {
-      sendData(0x0);
+
+  for (uint8_t page = 0; page < PAGES; page++) {
+    for (uint8_t col = 0; col < COLUMNS; col++) {
+      sendData(0x00);
     }
   }
-  setDisplayOn();
+
+//  setDisplayOn();
 }
+#else
+//Optimised version
+// Save lots of I2C S,P, address and datacommands:
+// Send S, address, DATA_MODE, data, data, data,...., P
+//
+void SSD1308::clearDisplay() {
 
-void SSD1308::fillDisplay() {
+  //setDisplayOff();
+  
   setPageAddress(0, MAX_PAGE);  // all pages
   setColumnAddress(0, MAX_COL); // all columns
 
-  uint8_t b = 0;
-  for (uint8_t page = 0; page < PAGES; page++)
-  {
-    for (uint8_t col = 0; col < COLUMNS; col++)
-    {
-      sendData(b++);
+  _i2c.start();
+  _i2c.write(_writeOpcode);
+  _i2c.write(DATA_MODE);  
+  for (int i=0; i<(PAGES * COLUMNS); i++) {
+    _i2c.write(0x00);  // Write Data   
+  }
+  _i2c.stop();
+
+//  setDisplayOn();
+}
+#endif
+
+
+#if(0)
+//Standard version
+void SSD1308::fillDisplay(uint8_t pattern) {
+  
+  //setDisplayOff();  
+  
+  setPageAddress(0, MAX_PAGE);  // all pages
+  setColumnAddress(0, MAX_COL); // all columns
+
+  for (uint8_t page = 0; page < PAGES; page++) {
+    for (uint8_t col = 0; col < COLUMNS; col++) {
+      sendData(pattern); 
     }
   }
+ 
+  //  setDisplayOn();  
+}
+#else
+//Optimised version
+// Save lots of I2C S,P, address and datacommands:
+// Send S, address, DATA_MODE, data, data, data,...., P
+//
+void SSD1308::fillDisplay(uint8_t pattern) {
+
+  //setDisplayOff();
+  setPageAddress(0, MAX_PAGE);  // all pages
+  setColumnAddress(0, MAX_COL); // all columns
+
+  _i2c.start();
+  _i2c.write(_writeOpcode);
+  _i2c.write(DATA_MODE);  
+  for (int i=0; i<(PAGES * COLUMNS); i++) {
+    _i2c.write(pattern);  // Write Data   
+  }
+  _i2c.stop();
+
+//  setDisplayOn();
+}
+#endif
+
+
+void SSD1308::writeBitmap(int len, uint8_t* data) {
+  //setDisplayOff();
+  setPageAddress(0, MAX_PAGE);  // all pages
+  setColumnAddress(0, MAX_COL); // all columns
+
+  _i2c.start();
+  _i2c.write(_writeOpcode);
+  _i2c.write(DATA_MODE);  
+  for (int i=0; i<len; i++) {
+    _i2c.write(data[i]);  // Write Data   
+  }
+  _i2c.stop();
+
+//  setDisplayOn();
 }
 
 void SSD1308::writeChar(char chr) {
 //#ifdef SSD1308_USE_FONT
+
   const uint8_t char_index = chr - 0x20;
   for (uint8_t i = 0; i < 8; i++) {
 //     const uint8_t b = pgm_read_byte( &fontData[char_index][i] );
-     const uint8_t b = fontData[char_index][i];     
-     sendData( b ); 
+//     const uint8_t b = fontData[char_index][i];     
+//     sendData( b ); 
+     sendData( fontData[char_index][i] );      
   }
+
 //#endif
 }
 
@@ -137,14 +215,15 @@
 }
 
 void SSD1308::sendCommands(uint8_t len, uint8_t* commands) {
-//  I2Cdev::writeBytes(m_devAddr, COMMAND_MODE, len, commands);
 
-  int i;
- 
+//  I2Cdev::writeBytes(m_devAddr, COMMAND_MODE, len, commands);
+//  Note this original code is not correct, continuationbit is set!
+
   _i2c.start();
   _i2c.write(_writeOpcode);
-  _i2c.write(COMMAND_MODE);  
-  for (i=0; i<len ; i++) {
+  
+  for (int i=0; i<len ; i++) {
+    _i2c.write(COMMAND_MODE);      
     _i2c.write(commands[i]);  // Write Commands   
   }
   _i2c.stop();
@@ -165,18 +244,18 @@
 void SSD1308::sendData(uint8_t len, uint8_t* data) {
 //  I2Cdev::writeBytes(m_devAddr, DATA_MODE, len, data);
   
-  int i;
- 
   _i2c.start();
   _i2c.write(_writeOpcode);
   _i2c.write(DATA_MODE);  
-  for (i=0; i<len ; i++) {
+  for (int i=0; i<len ; i++) {
     _i2c.write(data[i]);  // Write Data   
   }
   _i2c.stop();
     
 }
 
+
+
 void SSD1308::setHorizontalAddressingMode(){
   setMemoryAddressingMode(HORIZONTAL_ADDRESSING_MODE); 
 }
@@ -194,6 +273,17 @@
   sendCommands(2, cmds); 
 }
 
+void SSD1308::setPageAddress(uint8_t start, uint8_t end) {
+  uint8_t data[3] = { SET_PAGE_ADDRESS, start, end };
+  sendCommands(3, data);  
+}
+
+void SSD1308::setColumnAddress(uint8_t start, uint8_t end) {
+  uint8_t data[3] = { SET_COLUMN_ADDRESS, start, end };
+  sendCommands(3, data);  
+}
+
+
 void SSD1308::setDisplayOn() {
   sendCommand(SET_DISPLAY_POWER_ON);
 }
@@ -210,12 +300,27 @@
   }
 }
 
-void SSD1308::setPageAddress(uint8_t start, uint8_t end) {
-  uint8_t data[3] = { SET_PAGE_ADDRESS, start, end };
-  sendCommands(3, data);  
+void SSD1308::setDisplayNormal() {
+  sendCommand(SET_NORMAL_DISPLAY);
+}
+
+
+void SSD1308::setDisplayInverse() {
+  sendCommand(SET_INVERSE_DISPLAY);
 }
 
-void SSD1308::setColumnAddress(uint8_t start, uint8_t end) {
-  uint8_t data[3] = { SET_COLUMN_ADDRESS, start, end };
-  sendCommands(3, data);  
+
+// Low level Init
+// Init the configuration registers in accordance with the datasheet
+//
+void SSD1308::_init() {
+  setHorizontalAddressingMode();
+  clearDisplay();
+  
+  sendCommand(SET_DISPLAY_POWER_OFF);
+    
+  sendCommand(SET_NORMAL_DISPLAY);  
+  
+  sendCommand(SET_DISPLAY_POWER_ON);  
 }
+
--- a/SSD1308.h	Tue Jun 19 20:00:10 2012 +0000
+++ b/SSD1308.h	Sat Jun 30 14:44:39 2012 +0000
@@ -1,16 +1,15 @@
-// I2Cdev library collection - SSD1308 I2C device class header file
-// Based on Solomon Systech SSD1308 datasheet, rev. 1, 10/2008
-//  8/25/2011 by Andrew Schamp <schamp@gmail.com>
-// 19/06/2012 Ported to mbed (WH)
+// SSD1308 I2C device class header file
+//   Based on Solomon Systech SSD1308 datasheet, rev. 1, 10/2008
+//   The SSD1308 is used for example in the Seeed 128x64 OLED Display
+//   http://www.seeedstudio.com/depot/grove-oled-display-12864-p-781.html?cPath=163_167
 //
-// This I2C device library is using (and submitted as a part of) Jeff Rowberg's I2Cdevlib library,
+// The original code is using (and submitted as a part of) Jeff Rowberg's I2Cdevlib library,
 // which should (hopefully) always be available at https://github.com/jrowberg/i2cdevlib
-// Note WH: I2Cdevlib not used for mbed port
 //
 // Changelog:
-//     2011-08-25 - initial release
-//     2012-06-19 - Ported to mbed (WH)
-        
+//   2011-08-25 - initial release by Andrew Schamp <schamp@gmail.com>
+//   2012-06-19 - Ported to mbed and optimised (WH)
+//             
 /* ============================================
 I2Cdev device library code is placed under the MIT license
 Copyright (c) 2011 Andrew Schamp
@@ -40,22 +39,20 @@
 #define SSD1308_H
 
 // This is the I2C address (8 bit)
-//  which one is used is determined by the D/C# pin.
-//  with D/C# (pin 13) grounded, address is 0x78
-//  with D/C# tied high it is 0x7A
-//  assume grounded by default.
-#define SSD1308_SA0 0x78
-#define SSD1308_SA1 0x7A
-#define SSD1308_DEF_SA SSD1308_SA0
+//  There are two possible addresses: with D/C# (pin 13) grounded, the address is 0x78,
+//  with D/C# tied high it is 0x7A. Assume grounded by default.
+#define SSD1308_SA0                0x78
+#define SSD1308_SA1                0x7A
+#define SSD1308_DEF_SA             SSD1308_SA0
 
-#define ROWS        64
-#define COLUMNS     128
-#define PAGES       8
-#define PAGE_WIDTH  (ROWS / 8)
-#define FONT_WIDTH  8
-#define CHARS       (COLUMNS / FONT_WIDTH)
-#define MAX_PAGE    (PAGES - 1)
-#define MAX_COL     (COLUMNS - 1)
+#define ROWS                       64
+#define COLUMNS                    128
+#define PAGES                      (ROWS / 8)
+#define MAX_PAGE                   (PAGES - 1)
+#define MAX_COL                    (COLUMNS - 1)
+
+#define FONT_WIDTH                 8
+#define CHARS                      (COLUMNS / FONT_WIDTH)
 
 #define HORIZONTAL_ADDRESSING_MODE 0x00
 #define VERTICAL_ADDRESSING_MODE   0x01
@@ -86,7 +83,7 @@
 #define SET_DISPLAY_POWER_OFF      0xAE
 #define SET_DISPLAY_POWER_ON       0xAF
 
-#define COMMAND_MODE               0x80
+#define COMMAND_MODE               0x80 // continuation bit is set!
 #define DATA_MODE                  0x40
 
 #define PAGE0                      0x00
@@ -129,7 +126,9 @@
 
     void initialize();
     void clearDisplay();
-    void fillDisplay(); // crosshatches    
+    void fillDisplay(uint8_t pattern); // pattern     
+    
+    void writeBitmap(int len, uint8_t* data);
     
     // x, y is position (x is row (i.e., page), y is character (0-15), starting at top-left)
     // text will wrap around until it is done.
@@ -167,8 +166,6 @@
     void setEntireDisplayOn();
     void setEntireDisplayRAM();
     void setEntireDisplay(bool on);
-    void setNormalDisplay();
-    void setInverseDisplay();
     
     // setMultiplexRatio
     
@@ -178,6 +175,9 @@
     void setDisplayOn();
     void setDisplayOff();
     void setDisplayPower(bool on);
+
+    void setDisplayNormal();
+    void setDisplayInverse();
     
     // Set vertical shift by COM from 0 - 63 (0x00 - 0x3F)
     // set to 0x00 after RESET
@@ -221,16 +221,16 @@
 
     void sendData(uint8_t data);
     void sendData(uint8_t len, uint8_t* data);
-    // write the configuration registers in accordance with the datasheet and app note 3944
-//    void initialize();
+    
   
-
   private:
     // sends a single-byte command (given) to device
     void sendCommand(uint8_t command);
     void sendCommands(uint8_t len, uint8_t* buf);
+    void writeChar(char chr);
 
-    void writeChar(char chr);
+    // Init the configuration registers in accordance with the datasheet
+    void _init();
     
     I2C _i2c;          // I2C bus
 //    uint8_t m_devAddr; // contains the I2C address of the device
--- a/main.cpp	Tue Jun 19 20:00:10 2012 +0000
+++ b/main.cpp	Sat Jun 30 14:44:39 2012 +0000
@@ -1,205 +1,233 @@
-/* mbed Seeed 128x64 OLED Test
- * http://www.seeedstudio.com/depot/grove-oled-display-12864-p-781.html?cPath=163_167
- *
- * Copyright (c) 2012 Wim Huiskamp
- * Released under the MIT License: http://mbed.org/license/mit
- *
- * version 0.2 Initial Release
- */
-#include "mbed.h"
-#include "FixedWidthFont.h"
-#include "SSD1308.h"
-
-//Pin Defines for I2C Bus
-//#define D_SDA                  p9
-//#define D_SCL                  p10
-#define D_SDA                  p28
-#define D_SCL                  p27
-I2C i2c(D_SDA, D_SCL);
-
-//Host PC Baudrate (Virtual Com Port on USB)
-#define D_BAUDRATE            9600
-//#define D_BAUDRATE            57600
-
-// mbed Interface Hardware definitions
-DigitalOut myled1(LED1);
-DigitalOut myled2(LED2);
-DigitalOut myled3(LED3);
-DigitalOut heartbeatLED(LED4);
-
-// Host PC Communication channels
-Serial pc(USBTX, USBRX); // tx, rx
-
-// Instantiate OLED
-SSD1308 oled = SSD1308(i2c, SSD1308_SA0);
-
-void show_menu() {
-    pc.printf("0: Exit\n\r");
-    pc.printf("1: Show Menu\n\r");    
-    pc.printf("2: Send Message\n\r"); 
-    pc.printf("3: \n\r");    
-    pc.printf("4: \n\r");        
-    pc.printf("5: \n\r");            
-    pc.printf("6: \n\r");                
-    pc.printf("7: \n\r");                    
-    pc.printf("A: \n\r");                
-    pc.printf("B: \n\r");                    
-    pc.printf("P: \n\r");                        
-    pc.printf("\n\r");                
-}
-
-
-void oled_Test() {
-  pc.printf("OLED test start\r");  
-  
-  oled.setDisplayOff();
-  pc.printf("display off\r\n");          
-  wait(0.5);
-
-  oled.setDisplayOn();
-  pc.printf("display on\r\n");          
-  wait(0.5);  
-
-  oled.clearDisplay();
-  pc.printf("display cleared\r\n");        
-  wait(0.5);
-
-  oled.fillDisplay();
-  pc.printf("display filled\r\n");      
-  wait(0.5);
-  
-  oled.clearDisplay();
-  pc.printf("display cleared\r\n");    
-  wait(0.5);
-
-  oled.writeString(0, 0, 8, "Foobar!!");
-  pc.printf("printed something\r\n");    
-  wait(3);
-    
-  oled.writeString(1, 8, 8, "baz quux");
-  pc.printf("printed something\r\n");  
-  wait(3);
-    
-  oled.writeString(2, 0, 272, "a long, rather lengthy, extended string passage thing, eh, that just goes on, and on, and on, and on, and on, and on, and on, yes, further, continuing, extending, expanding beyond all reason or sanity!!!!! and yet, there's more!  so much more!  for ever and ever, oh yeah");
-  pc.printf("printed something\r\n");
-  wait(3);
-
-  pc.printf("OLED test done\r\n");  
-}
-
-// Variables for Heartbeat and Status monitoring
-Ticker heartbeat;
-bool heartbeatflag=false;
-
-// Local functions
-void clear_screen() {
-//ANSI Terminal Commands
-    pc.printf("\x1B[2J");
-    pc.printf("\x1B[H");
-}
-
-
-void init_interfaces() {
-    // Init Host PC communication, default is 9600
-    pc.baud(D_BAUDRATE);
-      
-    // Init I/F hardware
-//    i2c.frequency(100000);
-    i2c.frequency(400000); // according to the spec the max bitrate for the SSD1308 is 400 kbit/s
-}
-      
-
-// Heartbeat monitor
-void pulse() {
-  heartbeatLED = !heartbeatLED;
-}
-
-void heartbeat_start() {
-  heartbeat.attach(&pulse, 0.5);
-}
-
-void heartbeat_stop() {
-  heartbeat.detach();
-}
-
-
-int main() {
-    bool running=true;
-    char command;
-
-    init_interfaces();
-    
-    heartbeat_start();
-          
-    clear_screen(); 
-  
-    pc.printf("Hello World!\n\r");
-
-// Quick test
-    oled_Test(); 
-    
-    while(1) {
-        myled1 = 1;
-        wait(0.2);       
-         
-        myled1 = 0;
-        wait(0.2);     
-        pc.printf("*");
-    }
-    
-
-// Interactive Test
-    show_menu();
-      
-    while(running) {
-          
-       if(pc.readable()) {
-         command = pc.getc();       
-         pc.printf("command= %c \n\r", command);         
-
-         switch (command) {
-          case '0' :
-                     pc.printf("Done\n\r");                    
-                     running = false;  
-                     break;
-          
-          case '1' :
-                     show_menu();
-                     break;
-                    
-          case '2' :
-                     pc.printf("Hello World!\n\r");          
-                     break;
-          
-          case '3' :
-                     break;
-
-          case '4' :
-                     break;
-
-          case '5' :
-                     break;
-          case '6' :
-                     break;
-
-          case '7' :
-                     break;
-
-          case 'A' :
-                     break;
-
-          case 'B' :
-                   
-                     break;
-
-          case 'P' :
-          
-                    break;
-                              
-        } //switch
-      }//if
-    }//while
-
-    pc.printf("Bye World!\n\r");                       
-}//main    
-
+/* mbed Seeed 128x64 OLED Test
+ * http://www.seeedstudio.com/depot/grove-oled-display-12864-p-781.html?cPath=163_167
+ *
+ * Copyright (c) 2012 Wim Huiskamp
+ * Released under the MIT License: http://mbed.org/license/mit
+ *
+ * version 0.2 Initial Release
+ */
+#include "mbed.h"
+//#include "FixedWidthFont.h"
+#include "mbed_logo.h"
+#include "SSD1308.h"
+
+
+//Pin Defines for I2C Bus
+//#define D_SDA                  p9
+//#define D_SCL                  p10
+#define D_SDA                  p28
+#define D_SCL                  p27
+I2C i2c(D_SDA, D_SCL);
+
+//Host PC Baudrate (Virtual Com Port on USB)
+#define D_BAUDRATE            9600
+//#define D_BAUDRATE            57600
+
+// mbed Interface Hardware definitions
+DigitalOut myled1(LED1);
+DigitalOut myled2(LED2);
+DigitalOut myled3(LED3);
+DigitalOut heartbeatLED(LED4);
+
+// Host PC Communication channels
+Serial pc(USBTX, USBRX); // tx, rx
+
+// Instantiate OLED
+SSD1308 oled = SSD1308(i2c, SSD1308_SA0);
+
+void show_menu() {
+    pc.printf("0: Exit\n\r");
+    pc.printf("1: Show Menu\n\r");    
+    pc.printf("2: Send Message\n\r"); 
+    pc.printf("3: Fill Display\n\r");
+    pc.printf("4: Display cleared\n\r");        
+    pc.printf("5: Display off\n\r");            
+    pc.printf("6: Display on\n\r");                
+    pc.printf("7: Display Invert\n\r");                    
+    pc.printf("8: Display Normal\n\r");                
+    pc.printf("9: Display Bitmap\n\r");                    
+//    pc.printf("A: \n\r");                    
+//    pc.printf("B: \n\r");                    
+//    pc.printf("C: \n\r");                        
+//    pc.printf("D: \n\r");                            
+//    pc.printf("E: \n\r");                                
+//    pc.printf("F: \n\r");                                    
+//    pc.printf("\n\r");                
+     
+}
+
+
+void oled_Test() {
+  pc.printf("OLED test start\r");  
+  
+  oled.writeString(0, 0, 13, "Hello World !");
+  pc.printf("Printed something\r\n");    
+  wait(3);
+    
+  oled.writeString(1, 0, 8, "baz quux");
+  pc.printf("Printed something\r\n");  
+  wait(3);
+    
+//  oled.writeString(4, 0, 272, "a long, rather lengthy, extended string passage thing, eh, that just goes on, and on, and on, and on, and on, and on, and on, yes, further, continuing, extending, expanding beyond all reason or sanity!!!!! and yet, there's more!  so much more!  for ever and ever, oh yeah");
+//  pc.printf("Printed something\r\n");
+//  wait(3);
+
+  oled.fillDisplay(0xAA);
+  pc.printf("Display filled\r\n");      
+  wait(3);
+
+  oled.setDisplayOff();
+  pc.printf("Display off\r\n");          
+  wait(0.5);
+
+  oled.setDisplayOn();
+  pc.printf("Display on\r\n");          
+  wait(0.5);  
+
+  oled.clearDisplay();
+  pc.printf("Display cleared\r\n");        
+  wait(0.5);
+
+  oled.writeString(0, 0, 11, "Bye World !");
+  pc.printf("Printed something\r\n");    
+  wait(3);
+
+  pc.printf("OLED test done\r\n");  
+}
+
+// Variables for Heartbeat and Status monitoring
+Ticker heartbeat;
+bool heartbeatflag=false;
+
+// Local functions
+void clear_screen() {
+//ANSI Terminal Commands
+    pc.printf("\x1B[2J");
+    pc.printf("\x1B[H");
+}
+
+
+void init_interfaces() {
+    // Init Host PC communication, default is 9600
+    pc.baud(D_BAUDRATE);
+      
+    // Init I/F hardware
+//    i2c.frequency(100000);
+    i2c.frequency(400000); // according to the spec the max bitrate for the SSD1308 is 400 kbit/s
+}
+      
+
+// Heartbeat monitor
+void pulse() {
+  heartbeatLED = !heartbeatLED;
+}
+
+void heartbeat_start() {
+  heartbeat.attach(&pulse, 0.5);
+}
+
+void heartbeat_stop() {
+  heartbeat.detach();
+}
+
+
+int main() {
+    bool running=true;
+    char command;
+
+    init_interfaces();
+    
+    heartbeat_start();
+          
+    clear_screen(); 
+  
+    pc.printf("Hello World!\n\r");
+
+#if(0)
+// Quick test
+    oled_Test(); 
+    
+    while(1) {
+        myled1 = 1;
+        wait(0.2);       
+         
+        myled1 = 0;
+        wait(0.2);     
+        pc.printf("*");
+    }
+#else    
+// Interactive Test
+    show_menu();
+      
+    while(running) {
+          
+       if(pc.readable()) {
+         command = pc.getc();       
+         pc.printf("command= %c \n\r", command);         
+
+         switch (command) {
+          case '0' :
+                     pc.printf("Done\n\r");                    
+                     running = false;  
+                     break;
+          
+          case '1' :
+                     show_menu();
+                     break;
+                    
+          case '2' :
+                     pc.printf("Hello World!\n\r");  
+                     oled.writeString(0, 0, 13, "Hello World !");                            
+                     break;
+          
+          case '3' :
+                     pc.printf("Fill Display 0xA5\n\r");            
+                     oled.fillDisplay(0xA5);
+                     break;
+
+          case '4' :
+                     pc.printf("Display cleared\r\n");                  
+                     oled.clearDisplay();
+                     break;
+
+          case '5' :
+                     pc.printf("Display off\r\n");                
+                     oled.setDisplayOff();                  
+                     break;
+          case '6' :
+                     pc.printf("Display on\r\n");          
+                     oled.setDisplayOn();                     
+                     break;
+
+          case '7' :
+                     pc.printf("Display Invert\r\n");          
+                     oled.setDisplayInverse();
+                     break;
+
+          case '8' :
+                     pc.printf("Display Normal\r\n");
+                     oled.setDisplayNormal();                                         
+                     break;
+
+          case '9' :
+                     pc.printf("Display bitmap\r\n");          
+                     oled.writeBitmap((PAGES*COLUMNS), (uint8_t*) mbed_logo);
+                   
+                     break;
+
+          case 'A' :
+                   
+                     break;
+
+          case 'B' :
+          
+                    break;
+                              
+        } //switch
+      }//if
+    }//while
+#endif
+
+    pc.printf("Bye World!\n\r");                       
+}//main    
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed_logo.h	Sat Jun 30 14:44:39 2012 +0000
@@ -0,0 +1,71 @@
+//------------------------------------------------------------------------------
+// File generated by LCD Assistant
+// http://en.radzio.dxp.pl/bitmap_converter/
+//------------------------------------------------------------------------------
+
+const uint8_t mbed_logo [] = {
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE,
+0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0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0, 0xF0, 0xF0, 0xF0, 0xF0,
+0xF0, 0xF8, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03,
+0x03, 0x03, 0x01, 0x00, 0x00, 0x01, 0x01, 0x03, 0x03, 0x03, 0x03, 0x01, 0x01, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
+0x01, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x03, 0x03, 0x03, 0x03, 0x03, 0x01,
+0x01, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+};