Example shows how to display static and dynamic text on the Hexiwear OLED Display.

Dependencies:   Hexi_OLED_SSD1351

Fork of Hexi_OLED_Text_Example by Hexiwear

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "Hexi_OLED_SSD1351.h"
00003 #include "string.h"
00004 
00005 int main() {
00006     char text[20];  /* Text Buffer */ 
00007     Timer time;     /* Instantiate Time */
00008 
00009     /* Instantiate the SSD1351 OLED Driver */ 
00010     SSD1351 oled(PTB22,PTB21,PTC13,PTB20,PTE6, PTD15); /* (MOSI,SCLK,POWER,CS,RST,DC) */
00011     
00012     /* Get OLED Class Default Text Properties */
00013     oled_text_properties_t textProperties = {0};
00014     oled.GetTextProperties(&textProperties);    
00015 
00016     /* Turn on the backlight of the OLED Display */
00017     oled.DimScreenON();
00018     
00019     /* Fills the screen with solid black */         
00020     oled.FillScreen(COLOR_BLACK);
00021 
00022     /* Display Text at (x=7,y=0) */
00023     strcpy((char *) text,"TEXT EXAMPLE");
00024     oled.Label((uint8_t *)text,7,0);
00025         
00026     /* Change font color to blue */ 
00027     textProperties.fontColor   = COLOR_BLUE;
00028     oled.SetTextProperties(&textProperties);
00029 
00030     /* Display text at (x=5,y=40) */ 
00031     strcpy(text,"Timer(s):");
00032     oled.Label((uint8_t *)text,5,40);
00033         
00034     /* Set text properties to white and right aligned for the dynamic text */
00035     textProperties.fontColor = COLOR_WHITE;
00036     textProperties.alignParam = OLED_TEXT_ALIGN_RIGHT;
00037     oled.SetTextProperties(&textProperties);    
00038 
00039     
00040     time.start(); /* start timer */
00041 
00042     while (true) {
00043         
00044         /* Format the time reading */
00045         sprintf(text,"%.2f",time.read());
00046         
00047         /* Display time reading in 35px by 15px textbox at(x=55, y=40) */
00048         oled.TextBox((uint8_t *)text,55,40,35,15); //Increase textbox for more digits
00049              
00050         Thread::wait(1000);
00051     }
00052 }
00053 
00054 
00055     
00056