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: N5110 SRF02-JEB mbed
introScreen/intro.h@3:ab75e6a12701, 2016-05-05 (annotated)
- Committer:
- ll13j7b
- Date:
- Thu May 05 14:22:27 2016 +0000
- Revision:
- 3:ab75e6a12701
- Parent:
- 2:01f697b856de
Final Code Submission
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| ll13j7b | 2:01f697b856de | 1 | /** |
| ll13j7b | 2:01f697b856de | 2 | @file intro.h |
| ll13j7b | 2:01f697b856de | 3 | @brief Introduction |
| ll13j7b | 2:01f697b856de | 4 | @author James Bruce |
| ll13j7b | 2:01f697b856de | 5 | */ |
| ll13j7b | 1:f82359c58eda | 6 | |
| ll13j7b | 1:f82359c58eda | 7 | #ifndef INTRO_H |
| ll13j7b | 1:f82359c58eda | 8 | #define INTRO_H |
| ll13j7b | 1:f82359c58eda | 9 | #include "mbed.h" |
| ll13j7b | 1:f82359c58eda | 10 | #include "N5110.h" |
| ll13j7b | 1:f82359c58eda | 11 | #include <bitset> |
| ll13j7b | 1:f82359c58eda | 12 | |
| ll13j7b | 2:01f697b856de | 13 | /** |
| ll13j7b | 2:01f697b856de | 14 | @namespace update_screen |
| ll13j7b | 2:01f697b856de | 15 | @brief defining the tickers used that update the screen |
| ll13j7b | 2:01f697b856de | 16 | */ |
| ll13j7b | 1:f82359c58eda | 17 | Ticker update_screen, update_screen2; |
| ll13j7b | 2:01f697b856de | 18 | /** |
| ll13j7b | 2:01f697b856de | 19 | defining the flag for updating screen1 |
| ll13j7b | 2:01f697b856de | 20 | */ |
| ll13j7b | 2:01f697b856de | 21 | volatile bool g_update_screen = 0; |
| ll13j7b | 2:01f697b856de | 22 | /** |
| ll13j7b | 2:01f697b856de | 23 | defining the flag for updating screen2 |
| ll13j7b | 2:01f697b856de | 24 | */ |
| ll13j7b | 1:f82359c58eda | 25 | volatile bool g_update_screen_2 = 0; |
| ll13j7b | 2:01f697b856de | 26 | /** |
| ll13j7b | 2:01f697b856de | 27 | defining a new, bigger buffer for the movable text |
| ll13j7b | 2:01f697b856de | 28 | */ |
| ll13j7b | 1:f82359c58eda | 29 | int introBuffer[168][96]; |
| ll13j7b | 1:f82359c58eda | 30 | |
| ll13j7b | 2:01f697b856de | 31 | /** |
| ll13j7b | 2:01f697b856de | 32 | function to initialise the mbed, on board switches and LEDs |
| ll13j7b | 2:01f697b856de | 33 | */ |
| ll13j7b | 1:f82359c58eda | 34 | void init_K64F(); |
| ll13j7b | 2:01f697b856de | 35 | |
| ll13j7b | 2:01f697b856de | 36 | /** |
| ll13j7b | 2:01f697b856de | 37 | function that prints strings to buffer in bit form; |
| ll13j7b | 2:01f697b856de | 38 | this avoids banks so that it can be moved easily pixel by pixel |
| ll13j7b | 2:01f697b856de | 39 | */ |
| ll13j7b | 1:f82359c58eda | 40 | void PrintStringToBuffer(const char * str, int x, int y); |
| ll13j7b | 2:01f697b856de | 41 | |
| ll13j7b | 2:01f697b856de | 42 | /** |
| ll13j7b | 2:01f697b856de | 43 | function to send the new buffer to the lcd |
| ll13j7b | 2:01f697b856de | 44 | */ |
| ll13j7b | 1:f82359c58eda | 45 | void SendBufferToLCD(); |
| ll13j7b | 2:01f697b856de | 46 | |
| ll13j7b | 2:01f697b856de | 47 | /** |
| ll13j7b | 2:01f697b856de | 48 | function to initialise the serial connections from mbed to PC |
| ll13j7b | 2:01f697b856de | 49 | */ |
| ll13j7b | 1:f82359c58eda | 50 | void init_serial(); |
| ll13j7b | 2:01f697b856de | 51 | |
| ll13j7b | 2:01f697b856de | 52 | /** |
| ll13j7b | 2:01f697b856de | 53 | function to flip the flag for updating the screen |
| ll13j7b | 2:01f697b856de | 54 | */ |
| ll13j7b | 1:f82359c58eda | 55 | void update_screen_isr(); |
| ll13j7b | 2:01f697b856de | 56 | |
| ll13j7b | 2:01f697b856de | 57 | /** |
| ll13j7b | 2:01f697b856de | 58 | function to print the first section of the text |
| ll13j7b | 2:01f697b856de | 59 | */ |
| ll13j7b | 1:f82359c58eda | 60 | void printFirstText(); |
| ll13j7b | 2:01f697b856de | 61 | |
| ll13j7b | 2:01f697b856de | 62 | /** |
| ll13j7b | 2:01f697b856de | 63 | function to animate the menu sliding on to the screen |
| ll13j7b | 2:01f697b856de | 64 | */ |
| ll13j7b | 1:f82359c58eda | 65 | void animateToMenu(); |
| ll13j7b | 2:01f697b856de | 66 | |
| ll13j7b | 2:01f697b856de | 67 | /** |
| ll13j7b | 2:01f697b856de | 68 | function to flip the falg for updating the new screen |
| ll13j7b | 2:01f697b856de | 69 | uses a different rate than the other |
| ll13j7b | 2:01f697b856de | 70 | */ |
| ll13j7b | 1:f82359c58eda | 71 | void update_screen2_isr(); |
| ll13j7b | 2:01f697b856de | 72 | |
| ll13j7b | 2:01f697b856de | 73 | /** |
| ll13j7b | 2:01f697b856de | 74 | function that runs the correct sequence for the animated intro |
| ll13j7b | 2:01f697b856de | 75 | */ |
| ll13j7b | 1:f82359c58eda | 76 | void performAnimatedIntro(); |
| ll13j7b | 1:f82359c58eda | 77 | |
| ll13j7b | 1:f82359c58eda | 78 | |
| ll13j7b | 2:01f697b856de | 79 | //*****************************************************************************************************// |
| ll13j7b | 2:01f697b856de | 80 | |
| ll13j7b | 2:01f697b856de | 81 | // END OF GLOBAL VARIABLES & FUNCTIONS // |
| ll13j7b | 2:01f697b856de | 82 | |
| ll13j7b | 2:01f697b856de | 83 | //*****************************************************************************************************// |
| ll13j7b | 2:01f697b856de | 84 | |
| ll13j7b | 2:01f697b856de | 85 | |
| ll13j7b | 2:01f697b856de | 86 | |
| ll13j7b | 2:01f697b856de | 87 | // FUNCTION TO PERFORM THE ORDER OF ANIMATION |
| ll13j7b | 1:f82359c58eda | 88 | void performAnimatedIntro() |
| ll13j7b | 1:f82359c58eda | 89 | { |
| ll13j7b | 1:f82359c58eda | 90 | update_screen.attach(&update_screen_isr, 0.05); |
| ll13j7b | 1:f82359c58eda | 91 | update_screen2.attach(&update_screen2_isr, 0.05); |
| ll13j7b | 1:f82359c58eda | 92 | |
| ll13j7b | 1:f82359c58eda | 93 | printFirstText(); |
| ll13j7b | 1:f82359c58eda | 94 | animateToMenu(); |
| ll13j7b | 1:f82359c58eda | 95 | } |
| ll13j7b | 1:f82359c58eda | 96 | |
| ll13j7b | 2:01f697b856de | 97 | // FUNCTION TO FLIP FLAG OF THE TICKER |
| ll13j7b | 1:f82359c58eda | 98 | void update_screen_isr() |
| ll13j7b | 1:f82359c58eda | 99 | { |
| ll13j7b | 1:f82359c58eda | 100 | g_update_screen = 1; |
| ll13j7b | 1:f82359c58eda | 101 | } |
| ll13j7b | 1:f82359c58eda | 102 | |
| ll13j7b | 2:01f697b856de | 103 | // FUNCTION TO FLIP FLAG OF THE TICKER |
| ll13j7b | 1:f82359c58eda | 104 | void update_screen2_isr() |
| ll13j7b | 1:f82359c58eda | 105 | { |
| ll13j7b | 1:f82359c58eda | 106 | g_update_screen_2 = 1; |
| ll13j7b | 1:f82359c58eda | 107 | } |
| ll13j7b | 1:f82359c58eda | 108 | |
| ll13j7b | 2:01f697b856de | 109 | // FUNCTION TO SET SERIAL BAUD RATE FOR DEBUGGING |
| ll13j7b | 1:f82359c58eda | 110 | void init_serial() |
| ll13j7b | 1:f82359c58eda | 111 | { |
| ll13j7b | 1:f82359c58eda | 112 | // set to highest baud - ensure terminal software matches |
| ll13j7b | 1:f82359c58eda | 113 | pc.baud(115200); |
| ll13j7b | 1:f82359c58eda | 114 | } |
| ll13j7b | 1:f82359c58eda | 115 | |
| ll13j7b | 2:01f697b856de | 116 | // FUNCTION THAT PRINTS STRING TO BUFFER |
| ll13j7b | 1:f82359c58eda | 117 | void PrintStringToBuffer(const char * str, int x, int y) |
| ll13j7b | 1:f82359c58eda | 118 | { |
| ll13j7b | 2:01f697b856de | 119 | // initialise the number of chars inside a string |
| ll13j7b | 1:f82359c58eda | 120 | int char_no = 0; |
| ll13j7b | 1:f82359c58eda | 121 | |
| ll13j7b | 2:01f697b856de | 122 | /// while the string is incrementing to the end char |
| ll13j7b | 1:f82359c58eda | 123 | while (*str) { |
| ll13j7b | 2:01f697b856de | 124 | // sets the font position relative to the ASCII table |
| ll13j7b | 1:f82359c58eda | 125 | int font_pos = (*str - 32)*5; |
| ll13j7b | 2:01f697b856de | 126 | /// loops through the number of columns in a char |
| ll13j7b | 2:01f697b856de | 127 | for (int i = 0; i < 5; i++) { |
| ll13j7b | 2:01f697b856de | 128 | int x_pixel = x + i + (char_no*6); // set to correct value for char length of 6 pixels |
| ll13j7b | 1:f82359c58eda | 129 | |
| ll13j7b | 2:01f697b856de | 130 | /// converts to the string to bitset form (8 bits per char) |
| ll13j7b | 1:f82359c58eda | 131 | std::bitset<8> bit_representation (font5x7[font_pos + i]); |
| ll13j7b | 2:01f697b856de | 132 | /// loops through the bits and sets them for each char passed in the string |
| ll13j7b | 2:01f697b856de | 133 | for (int bit = 0; bit < 8; bit++) { |
| ll13j7b | 2:01f697b856de | 134 | if (bit_representation.test(bit)) { |
| ll13j7b | 1:f82359c58eda | 135 | introBuffer[x_pixel][y + bit] = 1; |
| ll13j7b | 1:f82359c58eda | 136 | } |
| ll13j7b | 1:f82359c58eda | 137 | } |
| ll13j7b | 1:f82359c58eda | 138 | } |
| ll13j7b | 1:f82359c58eda | 139 | |
| ll13j7b | 2:01f697b856de | 140 | // increase char no. & increase str pointer |
| ll13j7b | 1:f82359c58eda | 141 | char_no++; |
| ll13j7b | 1:f82359c58eda | 142 | str++; |
| ll13j7b | 1:f82359c58eda | 143 | } |
| ll13j7b | 1:f82359c58eda | 144 | } |
| ll13j7b | 1:f82359c58eda | 145 | |
| ll13j7b | 2:01f697b856de | 146 | // FUNTION THAT SENDS BUFFER TO THE LCD SCREEN |
| ll13j7b | 1:f82359c58eda | 147 | void SendBufferToLCD() |
| ll13j7b | 1:f82359c58eda | 148 | { |
| ll13j7b | 2:01f697b856de | 149 | /// loop through the bounds of the screen and set the relative pixels to the buffer |
| ll13j7b | 2:01f697b856de | 150 | for (int col = 0; col < 84; col++) { |
| ll13j7b | 2:01f697b856de | 151 | for (int row = 0; row < 48; row++) { |
| ll13j7b | 1:f82359c58eda | 152 | if (introBuffer[col][row]) { |
| ll13j7b | 2:01f697b856de | 153 | lcd.setPixel(col, row); // set pixel to buffer |
| ll13j7b | 1:f82359c58eda | 154 | } |
| ll13j7b | 1:f82359c58eda | 155 | } |
| ll13j7b | 1:f82359c58eda | 156 | } |
| ll13j7b | 1:f82359c58eda | 157 | } |
| ll13j7b | 1:f82359c58eda | 158 | |
| ll13j7b | 2:01f697b856de | 159 | // FUNCTION THAT PRINTS THE FIRST ANIMATED TEXT |
| ll13j7b | 1:f82359c58eda | 160 | void printFirstText() |
| ll13j7b | 1:f82359c58eda | 161 | { |
| ll13j7b | 2:01f697b856de | 162 | /// preset the text to animate upwards |
| ll13j7b | 1:f82359c58eda | 163 | char text[] = "Sensor"; |
| ll13j7b | 1:f82359c58eda | 164 | char text1[] = "Project By"; |
| ll13j7b | 1:f82359c58eda | 165 | char text2[] = "James Bruce"; |
| ll13j7b | 2:01f697b856de | 166 | /// define their starting Y position |
| ll13j7b | 1:f82359c58eda | 167 | int y_pos = 50; //Starting y position |
| ll13j7b | 1:f82359c58eda | 168 | int y_pos1 = 58; //Starting y position |
| ll13j7b | 1:f82359c58eda | 169 | int y_pos2 = 66; //Starting y position |
| ll13j7b | 1:f82359c58eda | 170 | |
| ll13j7b | 2:01f697b856de | 171 | /// decrease the Y bit of the text until it reaches 5 |
| ll13j7b | 2:01f697b856de | 172 | while (y_pos > 5) { // while loop |
| ll13j7b | 1:f82359c58eda | 173 | if (g_update_screen) { |
| ll13j7b | 1:f82359c58eda | 174 | g_update_screen = 0; |
| ll13j7b | 1:f82359c58eda | 175 | |
| ll13j7b | 2:01f697b856de | 176 | // forces clear of the screen and buffer |
| ll13j7b | 2:01f697b856de | 177 | for (int col = 0; col < 168; col++) { |
| ll13j7b | 2:01f697b856de | 178 | for (int row = 0; row < 96; row++) { |
| ll13j7b | 2:01f697b856de | 179 | introBuffer[col][row] = 0; |
| ll13j7b | 2:01f697b856de | 180 | } |
| ll13j7b | 2:01f697b856de | 181 | } |
| ll13j7b | 2:01f697b856de | 182 | |
| ll13j7b | 1:f82359c58eda | 183 | lcd.clear(); |
| ll13j7b | 2:01f697b856de | 184 | // print the string at the new Y position |
| ll13j7b | 1:f82359c58eda | 185 | PrintStringToBuffer(text, 3, y_pos); |
| ll13j7b | 1:f82359c58eda | 186 | PrintStringToBuffer(text1, 3, y_pos1); |
| ll13j7b | 1:f82359c58eda | 187 | PrintStringToBuffer(text2, 3, y_pos2); |
| ll13j7b | 2:01f697b856de | 188 | SendBufferToLCD(); // send to the LCD |
| ll13j7b | 1:f82359c58eda | 189 | |
| ll13j7b | 1:f82359c58eda | 190 | lcd.refresh(); |
| ll13j7b | 1:f82359c58eda | 191 | |
| ll13j7b | 2:01f697b856de | 192 | /// decrease the positions of Y by 1 bit each time |
| ll13j7b | 2:01f697b856de | 193 | y_pos--; |
| ll13j7b | 1:f82359c58eda | 194 | y_pos1--; |
| ll13j7b | 1:f82359c58eda | 195 | y_pos2--; |
| ll13j7b | 1:f82359c58eda | 196 | } |
| ll13j7b | 1:f82359c58eda | 197 | } |
| ll13j7b | 2:01f697b856de | 198 | wait(1); // short delay so the user can read the text before next animation |
| ll13j7b | 1:f82359c58eda | 199 | } |
| ll13j7b | 1:f82359c58eda | 200 | |
| ll13j7b | 2:01f697b856de | 201 | // FUNCTION THAT PRINTS THE ANIMATED INTRO OF THE MENU |
| ll13j7b | 1:f82359c58eda | 202 | void animateToMenu() |
| ll13j7b | 1:f82359c58eda | 203 | { |
| ll13j7b | 2:01f697b856de | 204 | /// preset the menu text |
| ll13j7b | 1:f82359c58eda | 205 | char text[] = "MENU"; |
| ll13j7b | 1:f82359c58eda | 206 | char text1[] = "SETTINGS"; |
| ll13j7b | 1:f82359c58eda | 207 | char text2[] = "GRAPH PLOT"; |
| ll13j7b | 1:f82359c58eda | 208 | char text3[] = "NUMERICAL"; |
| ll13j7b | 1:f82359c58eda | 209 | char text4[] = "RADAR MODE"; |
| ll13j7b | 2:01f697b856de | 210 | /// re-define the previous text |
| ll13j7b | 1:f82359c58eda | 211 | char oldText[] = "Sensor"; |
| ll13j7b | 1:f82359c58eda | 212 | char oldText1[] = "Project By"; |
| ll13j7b | 1:f82359c58eda | 213 | char oldText2[] = "James Bruce"; |
| ll13j7b | 2:01f697b856de | 214 | /// define the X positions for the menu text |
| ll13j7b | 1:f82359c58eda | 215 | int x_pos = 83+30; //Starting x position |
| ll13j7b | 1:f82359c58eda | 216 | int x_pos1 = 83+17; //Starting x position |
| ll13j7b | 1:f82359c58eda | 217 | int x_pos2 = 83+12; //Starting x position |
| ll13j7b | 1:f82359c58eda | 218 | int x_pos3 = 83+16; //Starting x position |
| ll13j7b | 1:f82359c58eda | 219 | int x_pos4 = 83+12; //Starting x position |
| ll13j7b | 2:01f697b856de | 220 | int x = 3; // old x position |
| ll13j7b | 1:f82359c58eda | 221 | |
| ll13j7b | 2:01f697b856de | 222 | /// decreases the X position of the menu and the Y position of the previous text |
| ll13j7b | 1:f82359c58eda | 223 | while (x_pos1 > 17) { //Stops when x = 0 |
| ll13j7b | 1:f82359c58eda | 224 | if (g_update_screen_2) { |
| ll13j7b | 1:f82359c58eda | 225 | g_update_screen_2 = 0; |
| ll13j7b | 1:f82359c58eda | 226 | |
| ll13j7b | 2:01f697b856de | 227 | // forces clear of the screen and buffer |
| ll13j7b | 2:01f697b856de | 228 | for (int col = 0; col < 168; col++) { |
| ll13j7b | 2:01f697b856de | 229 | for (int row = 0; row < 96; row++) { |
| ll13j7b | 2:01f697b856de | 230 | introBuffer[col][row] = 0; |
| ll13j7b | 2:01f697b856de | 231 | } |
| ll13j7b | 2:01f697b856de | 232 | } |
| ll13j7b | 2:01f697b856de | 233 | |
| ll13j7b | 1:f82359c58eda | 234 | lcd.clear(); |
| ll13j7b | 2:01f697b856de | 235 | // prints the previous text back to its position |
| ll13j7b | 1:f82359c58eda | 236 | PrintStringToBuffer(oldText, 3, x+2); |
| ll13j7b | 1:f82359c58eda | 237 | PrintStringToBuffer(oldText1, 3, x+10); |
| ll13j7b | 1:f82359c58eda | 238 | PrintStringToBuffer(oldText2, 3, x+18); |
| ll13j7b | 2:01f697b856de | 239 | // prints the new text to the buffer |
| ll13j7b | 1:f82359c58eda | 240 | PrintStringToBuffer(text, x_pos, 0); |
| ll13j7b | 1:f82359c58eda | 241 | PrintStringToBuffer(text1, x_pos1, 16); |
| ll13j7b | 1:f82359c58eda | 242 | PrintStringToBuffer(text2, x_pos2, 24); |
| ll13j7b | 1:f82359c58eda | 243 | PrintStringToBuffer(text3, x_pos3, 32); |
| ll13j7b | 1:f82359c58eda | 244 | PrintStringToBuffer(text4, x_pos4, 40); |
| ll13j7b | 1:f82359c58eda | 245 | SendBufferToLCD(); |
| ll13j7b | 1:f82359c58eda | 246 | |
| ll13j7b | 1:f82359c58eda | 247 | lcd.refresh(); |
| ll13j7b | 2:01f697b856de | 248 | /// decreases all the X positions of the menu and increases the X of the old texts |
| ll13j7b | 1:f82359c58eda | 249 | x_pos--; //Decrements the y coordinate |
| ll13j7b | 1:f82359c58eda | 250 | x_pos1--; |
| ll13j7b | 1:f82359c58eda | 251 | x_pos2--; |
| ll13j7b | 1:f82359c58eda | 252 | x_pos3--; |
| ll13j7b | 1:f82359c58eda | 253 | x_pos4--; |
| ll13j7b | 1:f82359c58eda | 254 | x++; |
| ll13j7b | 2:01f697b856de | 255 | // dont allow the old text to wrap round the top and distorting the screen |
| ll13j7b | 1:f82359c58eda | 256 | if (x > 60) { |
| ll13j7b | 1:f82359c58eda | 257 | x = 60; |
| ll13j7b | 1:f82359c58eda | 258 | } |
| ll13j7b | 1:f82359c58eda | 259 | } |
| ll13j7b | 1:f82359c58eda | 260 | } |
| ll13j7b | 1:f82359c58eda | 261 | } |
| ll13j7b | 1:f82359c58eda | 262 | |
| ll13j7b | 2:01f697b856de | 263 | //*****************************************************************************************************// |
| ll13j7b | 2:01f697b856de | 264 | |
| ll13j7b | 2:01f697b856de | 265 | // END OF FUNCTION IMPLEMENTATIONS // |
| ll13j7b | 2:01f697b856de | 266 | |
| ll13j7b | 2:01f697b856de | 267 | //*****************************************************************************************************// |
| ll13j7b | 2:01f697b856de | 268 | |
| ll13j7b | 2:01f697b856de | 269 | |
| ll13j7b | 2:01f697b856de | 270 | #endif |
| ll13j7b | 2:01f697b856de | 271 | |
| ll13j7b | 2:01f697b856de | 272 | |
| ll13j7b | 2:01f697b856de | 273 | |
| ll13j7b | 2:01f697b856de | 274 | |
| ll13j7b | 2:01f697b856de | 275 |