Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: Hexi_OLED_SSD1351
Fork of Hexi_OLED_Text_Example by
Revision 1:42e8e50ae4ac, committed 2016-08-26
- Comitter:
- khuang
- Date:
- Fri Aug 26 23:07:25 2016 +0000
- Parent:
- 0:a1af4ae04b06
- Child:
- 2:47c3dad2c8ef
- Commit message:
- OLED Text Example
Changed in this revision
| Hexi_OLED_SSD1351.lib | 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 |
--- a/Hexi_OLED_SSD1351.lib Fri Aug 19 00:37:13 2016 +0000 +++ b/Hexi_OLED_SSD1351.lib Fri Aug 26 23:07:25 2016 +0000 @@ -1,1 +1,1 @@ -https://developer.mbed.org/teams/Hexiwear/code/Hexi_OLED_SSD1351/#3b5be0ee5f0c +https://developer.mbed.org/teams/Hexiwear/code/Hexi_OLED_SSD1351/#9961c525e249
--- a/main.cpp Fri Aug 19 00:37:13 2016 +0000
+++ b/main.cpp Fri Aug 26 23:07:25 2016 +0000
@@ -1,64 +1,54 @@
#include "mbed.h"
#include "Hexi_OLED_SSD1351.h"
#include "OLED_types.h"
-#include "OLED_fonts.h"
+#include "OpenSans_Font.h"
#include "string.h"
int main() {
-
- //Instantiate Time
- Timer time;
+ char text[20]; /* Text Buffer */
+ Timer time; /* Instantiate Time */
- //Instantiate the SSD1351 OLED Driver
- SSD1351 oled(PTB22,PTB21,PTC13,PTB20,PTE6, PTD15); // (MOSI,SCLK,POWER,CS,RST,DC)
- //Turn on the backlight of the OLED Display
- oled.DimScreenON();
- //Fills the screen with solid black
- oled.FillScreen(COLOR_BLACK);
+ /* Instantiate the SSD1351 OLED Driver */
+ SSD1351 oled(PTB22,PTB21,PTC13,PTB20,PTE6, PTD15); /* (MOSI,SCLK,POWER,CS,RST,DC) */
- //Set the parameters for desired text properties
- oled_text_properties_t
- textProperties =
- {
- .font = oledFont_Tahoma_8_Regular,
- .fontColor = COLOR_WHITE,
- .alignParam = OLED_TEXT_ALIGN_LEFT, //currently does nothing in this example
- .background = NULL
- };
+ /* Get OLED Class Default Text Properties */
+ oled_text_properties_t textProperties = {0};
+ oled.GetTextProperties(&textProperties);
+ /* Turn on the backlight of the OLED Display */
+ oled.DimScreenON();
+
+ /* Fills the screen with solid black */
+ oled.FillScreen(COLOR_BLACK);
+
+ /* Display Text at (x=7,y=0) */
+ strcpy((char *) text,"TEXT EXAMPLE");
+ oled.Label((uint8_t *)text,7,0);
+
+ /* Change font color to blue */
+ textProperties.fontColor = COLOR_BLUE;
oled.SetTextProperties(&textProperties);
- //Approximately 15 characters can fit on one line for this font size.
- //Extra element for null terminator of string.
- char text[15+1];
-
- //Display Text at (x=13,y=0). Need to manually center.
- strcpy((char *) text,"TEXT EXAMPLE");
- oled.DrawText((uint8_t *)text,13,0);
-
- //Change Font to Blue
- textProperties.fontColor = COLOR_BLUE;
- oled.SetTextProperties(&textProperties);
-
- //Display text at (x=5,y=24)
+ /* Display text at (x=5,y=40) */
strcpy(text,"Timer(s):");
- oled.DrawText((uint8_t *)text,5,24);
+ oled.Label((uint8_t *)text,5,40);
- //Set text color to white
+ /* Set text properties to white and right aligned for the dynamic text */
textProperties.fontColor = COLOR_WHITE;
+ textProperties.alignParam = OLED_TEXT_ALIGN_RIGHT;
oled.SetTextProperties(&textProperties);
- //start timer
- time.start();
+
+ time.start(); /* start timer */
while (true) {
-
- //Dynamic Text
+
+ /* Format the time reading */
+ sprintf(text,"%.2f",time.read());
- //Display Time Reading at (x=50, y=24)
- sprintf(text,"%.2f",time.read());
- oled.DrawText((uint8_t *)text,50,24);
-
+ /* Display time reading in 35px by 15px textbox at(x=55, y=40) */
+ oled.TextBox((uint8_t *)text,55,40,35,15);
+
Thread::wait(1000);
}
}
