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
main.cpp@3:d633281e5f83, 2016-08-26 (annotated)
- Committer:
- khuang
- Date:
- Fri Aug 26 23:52:37 2016 +0000
- Revision:
- 3:d633281e5f83
- Parent:
- 1:42e8e50ae4ac
- Child:
- 4:4e35f2e4b786
Added Comment;
Who changed what in which revision?
User | Revision | Line number | New 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 | 1:42e8e50ae4ac | 4 | #include "OpenSans_Font.h" |
khuang | 0:a1af4ae04b06 | 5 | #include "string.h" |
khuang | 0:a1af4ae04b06 | 6 | |
khuang | 0:a1af4ae04b06 | 7 | int main() { |
khuang | 1:42e8e50ae4ac | 8 | char text[20]; /* Text Buffer */ |
khuang | 1:42e8e50ae4ac | 9 | Timer time; /* Instantiate Time */ |
khuang | 0:a1af4ae04b06 | 10 | |
khuang | 1:42e8e50ae4ac | 11 | /* Instantiate the SSD1351 OLED Driver */ |
khuang | 1:42e8e50ae4ac | 12 | SSD1351 oled(PTB22,PTB21,PTC13,PTB20,PTE6, PTD15); /* (MOSI,SCLK,POWER,CS,RST,DC) */ |
khuang | 0:a1af4ae04b06 | 13 | |
khuang | 1:42e8e50ae4ac | 14 | /* Get OLED Class Default Text Properties */ |
khuang | 1:42e8e50ae4ac | 15 | oled_text_properties_t textProperties = {0}; |
khuang | 1:42e8e50ae4ac | 16 | oled.GetTextProperties(&textProperties); |
khuang | 0:a1af4ae04b06 | 17 | |
khuang | 1:42e8e50ae4ac | 18 | /* Turn on the backlight of the OLED Display */ |
khuang | 1:42e8e50ae4ac | 19 | oled.DimScreenON(); |
khuang | 1:42e8e50ae4ac | 20 | |
khuang | 1:42e8e50ae4ac | 21 | /* Fills the screen with solid black */ |
khuang | 1:42e8e50ae4ac | 22 | oled.FillScreen(COLOR_BLACK); |
khuang | 1:42e8e50ae4ac | 23 | |
khuang | 1:42e8e50ae4ac | 24 | /* Display Text at (x=7,y=0) */ |
khuang | 1:42e8e50ae4ac | 25 | strcpy((char *) text,"TEXT EXAMPLE"); |
khuang | 1:42e8e50ae4ac | 26 | oled.Label((uint8_t *)text,7,0); |
khuang | 1:42e8e50ae4ac | 27 | |
khuang | 1:42e8e50ae4ac | 28 | /* Change font color to blue */ |
khuang | 1:42e8e50ae4ac | 29 | textProperties.fontColor = COLOR_BLUE; |
khuang | 0:a1af4ae04b06 | 30 | oled.SetTextProperties(&textProperties); |
khuang | 0:a1af4ae04b06 | 31 | |
khuang | 1:42e8e50ae4ac | 32 | /* Display text at (x=5,y=40) */ |
khuang | 0:a1af4ae04b06 | 33 | strcpy(text,"Timer(s):"); |
khuang | 1:42e8e50ae4ac | 34 | oled.Label((uint8_t *)text,5,40); |
khuang | 0:a1af4ae04b06 | 35 | |
khuang | 1:42e8e50ae4ac | 36 | /* Set text properties to white and right aligned for the dynamic text */ |
khuang | 0:a1af4ae04b06 | 37 | textProperties.fontColor = COLOR_WHITE; |
khuang | 1:42e8e50ae4ac | 38 | textProperties.alignParam = OLED_TEXT_ALIGN_RIGHT; |
khuang | 0:a1af4ae04b06 | 39 | oled.SetTextProperties(&textProperties); |
khuang | 0:a1af4ae04b06 | 40 | |
khuang | 1:42e8e50ae4ac | 41 | |
khuang | 1:42e8e50ae4ac | 42 | time.start(); /* start timer */ |
khuang | 0:a1af4ae04b06 | 43 | |
khuang | 0:a1af4ae04b06 | 44 | while (true) { |
khuang | 1:42e8e50ae4ac | 45 | |
khuang | 1:42e8e50ae4ac | 46 | /* Format the time reading */ |
khuang | 1:42e8e50ae4ac | 47 | sprintf(text,"%.2f",time.read()); |
khuang | 0:a1af4ae04b06 | 48 | |
khuang | 1:42e8e50ae4ac | 49 | /* Display time reading in 35px by 15px textbox at(x=55, y=40) */ |
khuang | 3:d633281e5f83 | 50 | oled.TextBox((uint8_t *)text,55,40,35,15); //Increase textbox for more digits |
khuang | 1:42e8e50ae4ac | 51 | |
khuang | 0:a1af4ae04b06 | 52 | Thread::wait(1000); |
khuang | 0:a1af4ae04b06 | 53 | } |
khuang | 0:a1af4ae04b06 | 54 | } |
khuang | 0:a1af4ae04b06 | 55 | |
khuang | 0:a1af4ae04b06 | 56 | |
khuang | 0:a1af4ae04b06 | 57 | |
khuang | 0:a1af4ae04b06 | 58 |