iBreathe Breathalyzer can now talk thanks to the Text to Speech Click Board

Dependencies:   Hexi_KW40Z Hexi_OLED_SSD1351 text_to_speak_mbed

Fork of iBreathe_Breathalyzer by Dave Clarke

Committer:
khuang
Date:
Fri Aug 19 00:37:13 2016 +0000
Revision:
0:a1af4ae04b06
Child:
1:42e8e50ae4ac
OLED Text Example;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
khuang 0:a1af4ae04b06 1 #include "mbed.h"
khuang 0:a1af4ae04b06 2 #include "Hexi_OLED_SSD1351.h"
khuang 0:a1af4ae04b06 3 #include "OLED_types.h"
khuang 0:a1af4ae04b06 4 #include "OLED_fonts.h"
khuang 0:a1af4ae04b06 5 #include "string.h"
khuang 0:a1af4ae04b06 6
khuang 0:a1af4ae04b06 7 int main() {
khuang 0:a1af4ae04b06 8
khuang 0:a1af4ae04b06 9 //Instantiate Time
khuang 0:a1af4ae04b06 10 Timer time;
khuang 0:a1af4ae04b06 11
khuang 0:a1af4ae04b06 12 //Instantiate the SSD1351 OLED Driver
khuang 0:a1af4ae04b06 13 SSD1351 oled(PTB22,PTB21,PTC13,PTB20,PTE6, PTD15); // (MOSI,SCLK,POWER,CS,RST,DC)
khuang 0:a1af4ae04b06 14 //Turn on the backlight of the OLED Display
khuang 0:a1af4ae04b06 15 oled.DimScreenON();
khuang 0:a1af4ae04b06 16 //Fills the screen with solid black
khuang 0:a1af4ae04b06 17 oled.FillScreen(COLOR_BLACK);
khuang 0:a1af4ae04b06 18
khuang 0:a1af4ae04b06 19 //Set the parameters for desired text properties
khuang 0:a1af4ae04b06 20 oled_text_properties_t
khuang 0:a1af4ae04b06 21 textProperties =
khuang 0:a1af4ae04b06 22 {
khuang 0:a1af4ae04b06 23 .font = oledFont_Tahoma_8_Regular,
khuang 0:a1af4ae04b06 24 .fontColor = COLOR_WHITE,
khuang 0:a1af4ae04b06 25 .alignParam = OLED_TEXT_ALIGN_LEFT, //currently does nothing in this example
khuang 0:a1af4ae04b06 26 .background = NULL
khuang 0:a1af4ae04b06 27 };
khuang 0:a1af4ae04b06 28
khuang 0:a1af4ae04b06 29 oled.SetTextProperties(&textProperties);
khuang 0:a1af4ae04b06 30
khuang 0:a1af4ae04b06 31 //Approximately 15 characters can fit on one line for this font size.
khuang 0:a1af4ae04b06 32 //Extra element for null terminator of string.
khuang 0:a1af4ae04b06 33 char text[15+1];
khuang 0:a1af4ae04b06 34
khuang 0:a1af4ae04b06 35 //Display Text at (x=13,y=0). Need to manually center.
khuang 0:a1af4ae04b06 36 strcpy((char *) text,"TEXT EXAMPLE");
khuang 0:a1af4ae04b06 37 oled.DrawText((uint8_t *)text,13,0);
khuang 0:a1af4ae04b06 38
khuang 0:a1af4ae04b06 39 //Change Font to Blue
khuang 0:a1af4ae04b06 40 textProperties.fontColor = COLOR_BLUE;
khuang 0:a1af4ae04b06 41 oled.SetTextProperties(&textProperties);
khuang 0:a1af4ae04b06 42
khuang 0:a1af4ae04b06 43 //Display text at (x=5,y=24)
khuang 0:a1af4ae04b06 44 strcpy(text,"Timer(s):");
khuang 0:a1af4ae04b06 45 oled.DrawText((uint8_t *)text,5,24);
khuang 0:a1af4ae04b06 46
khuang 0:a1af4ae04b06 47 //Set text color to white
khuang 0:a1af4ae04b06 48 textProperties.fontColor = COLOR_WHITE;
khuang 0:a1af4ae04b06 49 oled.SetTextProperties(&textProperties);
khuang 0:a1af4ae04b06 50
khuang 0:a1af4ae04b06 51 //start timer
khuang 0:a1af4ae04b06 52 time.start();
khuang 0:a1af4ae04b06 53
khuang 0:a1af4ae04b06 54 while (true) {
khuang 0:a1af4ae04b06 55
khuang 0:a1af4ae04b06 56 //Dynamic Text
khuang 0:a1af4ae04b06 57
khuang 0:a1af4ae04b06 58 //Display Time Reading at (x=50, y=24)
khuang 0:a1af4ae04b06 59 sprintf(text,"%.2f",time.read());
khuang 0:a1af4ae04b06 60 oled.DrawText((uint8_t *)text,50,24);
khuang 0:a1af4ae04b06 61
khuang 0:a1af4ae04b06 62 Thread::wait(1000);
khuang 0:a1af4ae04b06 63 }
khuang 0:a1af4ae04b06 64 }
khuang 0:a1af4ae04b06 65
khuang 0:a1af4ae04b06 66
khuang 0:a1af4ae04b06 67
khuang 0:a1af4ae04b06 68