![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Finished V1
Dependencies: mbed wave_player 4DGL-uLCD-SE MMA8452
speech.cpp@5:2fb023cdc666, 2019-11-24 (annotated)
- Committer:
- trich9
- Date:
- Sun Nov 24 03:22:35 2019 +0000
- Revision:
- 5:2fb023cdc666
- Parent:
- 4:2297a714936f
finished V1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rconnorlawson | 0:35660d7952f7 | 1 | #include "speech.h" |
rconnorlawson | 0:35660d7952f7 | 2 | |
rconnorlawson | 0:35660d7952f7 | 3 | #include "globals.h" |
rconnorlawson | 0:35660d7952f7 | 4 | #include "hardware.h" |
rconnorlawson | 0:35660d7952f7 | 5 | |
rconnorlawson | 0:35660d7952f7 | 6 | /** |
rconnorlawson | 0:35660d7952f7 | 7 | * Draw the speech bubble background. |
rconnorlawson | 0:35660d7952f7 | 8 | */ |
rconnorlawson | 0:35660d7952f7 | 9 | static void draw_speech_bubble(); |
rconnorlawson | 0:35660d7952f7 | 10 | |
rconnorlawson | 0:35660d7952f7 | 11 | /** |
rconnorlawson | 0:35660d7952f7 | 12 | * Erase the speech bubble. |
rconnorlawson | 0:35660d7952f7 | 13 | */ |
rconnorlawson | 0:35660d7952f7 | 14 | static void erase_speech_bubble(); |
rconnorlawson | 0:35660d7952f7 | 15 | |
rconnorlawson | 0:35660d7952f7 | 16 | /** |
rconnorlawson | 0:35660d7952f7 | 17 | * Draw a single line of the speech bubble. |
rconnorlawson | 0:35660d7952f7 | 18 | * @param line The text to display |
rconnorlawson | 0:35660d7952f7 | 19 | * @param which If TOP, the first line; if BOTTOM, the second line. |
rconnorlawson | 0:35660d7952f7 | 20 | */ |
rconnorlawson | 0:35660d7952f7 | 21 | #define TOP 0 |
rconnorlawson | 0:35660d7952f7 | 22 | #define BOTTOM 1 |
rconnorlawson | 0:35660d7952f7 | 23 | static void draw_speech_line(const char* line, int which); |
rconnorlawson | 0:35660d7952f7 | 24 | |
rconnorlawson | 0:35660d7952f7 | 25 | /** |
rconnorlawson | 0:35660d7952f7 | 26 | * Delay until it is time to scroll. |
rconnorlawson | 0:35660d7952f7 | 27 | */ |
rconnorlawson | 0:35660d7952f7 | 28 | static void speech_bubble_wait(); |
rconnorlawson | 0:35660d7952f7 | 29 | |
rconnorlawson | 0:35660d7952f7 | 30 | void draw_speech_bubble() |
trich9 | 4:2297a714936f | 31 | { |
trich9 | 4:2297a714936f | 32 | //MYCODE |
trich9 | 4:2297a714936f | 33 | uLCD.filled_rectangle(0, 75, 128, 128, BLACK); |
trich9 | 4:2297a714936f | 34 | |
trich9 | 4:2297a714936f | 35 | uLCD.filled_rectangle(0, 74, 128, 75, BLUE);//top |
trich9 | 4:2297a714936f | 36 | uLCD.filled_rectangle(0, 127, 128, 128, BLUE);//bottom |
trich9 | 4:2297a714936f | 37 | |
trich9 | 4:2297a714936f | 38 | uLCD.filled_rectangle(0, 75, 1, 128, BLUE); |
trich9 | 4:2297a714936f | 39 | uLCD.filled_rectangle(127, 75, 128, 128, BLUE); |
rconnorlawson | 0:35660d7952f7 | 40 | } |
rconnorlawson | 0:35660d7952f7 | 41 | |
rconnorlawson | 0:35660d7952f7 | 42 | void erase_speech_bubble() |
rconnorlawson | 0:35660d7952f7 | 43 | { |
trich9 | 4:2297a714936f | 44 | uLCD.filled_rectangle(0, 117, 128, 128, BLACK); |
rconnorlawson | 0:35660d7952f7 | 45 | } |
rconnorlawson | 0:35660d7952f7 | 46 | |
rconnorlawson | 0:35660d7952f7 | 47 | void draw_speech_line(const char* line, int which) |
rconnorlawson | 0:35660d7952f7 | 48 | { |
trich9 | 4:2297a714936f | 49 | //MYCODE |
trich9 | 4:2297a714936f | 50 | int locateY = 10; |
trich9 | 4:2297a714936f | 51 | uLCD.locate(1, locateY); |
trich9 | 4:2297a714936f | 52 | uLCD.color(WHITE); |
trich9 | 4:2297a714936f | 53 | uLCD.text_width(1); |
trich9 | 4:2297a714936f | 54 | uLCD.text_height(1); |
trich9 | 4:2297a714936f | 55 | //every 17 characters go down a line |
trich9 | 4:2297a714936f | 56 | for(int i = 0; i < strlen(line); i++){//each char in line |
trich9 | 4:2297a714936f | 57 | if(i%17 == 0 && i != 0){//hit 17th character |
trich9 | 4:2297a714936f | 58 | locateY++; |
trich9 | 4:2297a714936f | 59 | uLCD.locate(1, locateY); |
trich9 | 4:2297a714936f | 60 | } |
trich9 | 4:2297a714936f | 61 | uLCD.printf("%c", line[i]); |
trich9 | 5:2fb023cdc666 | 62 | |
trich9 | 5:2fb023cdc666 | 63 | //SANS TEST |
trich9 | 5:2fb023cdc666 | 64 | speaker = 0.001; |
trich9 | 5:2fb023cdc666 | 65 | speaker.period(1.0/160); |
trich9 | 5:2fb023cdc666 | 66 | wait_ms(15); |
trich9 | 5:2fb023cdc666 | 67 | speaker = 0; |
trich9 | 5:2fb023cdc666 | 68 | wait_ms(10); |
trich9 | 5:2fb023cdc666 | 69 | //ENDSANS TEST |
trich9 | 5:2fb023cdc666 | 70 | |
trich9 | 5:2fb023cdc666 | 71 | //wait_ms(25); |
trich9 | 4:2297a714936f | 72 | } |
trich9 | 4:2297a714936f | 73 | |
trich9 | 4:2297a714936f | 74 | |
trich9 | 4:2297a714936f | 75 | //prints on top line |
trich9 | 4:2297a714936f | 76 | //17 chars per line |
trich9 | 4:2297a714936f | 77 | /*KINDA WORKS |
trich9 | 4:2297a714936f | 78 | uLCD.locate(1, 10); |
trich9 | 4:2297a714936f | 79 | uLCD.color(WHITE); |
trich9 | 4:2297a714936f | 80 | uLCD.text_width(1); |
trich9 | 4:2297a714936f | 81 | uLCD.text_height(1); |
trich9 | 4:2297a714936f | 82 | uLCD.printf("123456789qwertyui"); |
trich9 | 4:2297a714936f | 83 | |
trich9 | 4:2297a714936f | 84 | //prints on next line down |
trich9 | 4:2297a714936f | 85 | uLCD.locate(1, 11); |
trich9 | 4:2297a714936f | 86 | uLCD.color(WHITE); |
trich9 | 4:2297a714936f | 87 | uLCD.text_width(1); |
trich9 | 4:2297a714936f | 88 | uLCD.text_height(1); |
trich9 | 4:2297a714936f | 89 | uLCD.printf("opasdfas");*/ |
trich9 | 4:2297a714936f | 90 | |
rconnorlawson | 0:35660d7952f7 | 91 | } |
rconnorlawson | 0:35660d7952f7 | 92 | |
rconnorlawson | 0:35660d7952f7 | 93 | void speech_bubble_wait() |
rconnorlawson | 0:35660d7952f7 | 94 | { |
trich9 | 5:2fb023cdc666 | 95 | wait_ms(1500); |
rconnorlawson | 0:35660d7952f7 | 96 | } |
rconnorlawson | 0:35660d7952f7 | 97 | |
rconnorlawson | 0:35660d7952f7 | 98 | void speech(const char* line1, const char* line2) |
rconnorlawson | 0:35660d7952f7 | 99 | { |
rconnorlawson | 0:35660d7952f7 | 100 | draw_speech_bubble(); |
rconnorlawson | 0:35660d7952f7 | 101 | draw_speech_line(line1, TOP); |
rconnorlawson | 0:35660d7952f7 | 102 | draw_speech_line(line2, BOTTOM); |
rconnorlawson | 0:35660d7952f7 | 103 | speech_bubble_wait(); |
rconnorlawson | 0:35660d7952f7 | 104 | erase_speech_bubble(); |
rconnorlawson | 0:35660d7952f7 | 105 | } |
rconnorlawson | 0:35660d7952f7 | 106 | |
rconnorlawson | 0:35660d7952f7 | 107 | void long_speech(const char* lines[], int n) |
rconnorlawson | 0:35660d7952f7 | 108 | { |
rconnorlawson | 0:35660d7952f7 | 109 | } |