Simon: A Memory Game
Dependencies: 4DGL-uLCD-SE PinDetect mbed
main.cpp@1:cd222334a4fe, 2014-10-21 (annotated)
- Committer:
- cmathis
- Date:
- Tue Oct 21 14:01:21 2014 +0000
- Revision:
- 1:cd222334a4fe
- Parent:
- 0:64ea583d77e2
- Child:
- 2:c92f0e749b94
revision2
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
cmathis | 0:64ea583d77e2 | 1 | /*********************************/ |
cmathis | 0:64ea583d77e2 | 2 | // ECE 4180 Lab 4 |
cmathis | 0:64ea583d77e2 | 3 | // Colton Mathis, Taylor Hawley |
cmathis | 0:64ea583d77e2 | 4 | /*********************************/ |
cmathis | 0:64ea583d77e2 | 5 | |
cmathis | 0:64ea583d77e2 | 6 | #include "mbed.h" |
cmathis | 0:64ea583d77e2 | 7 | #include "uLCD_4DGL.h" |
cmathis | 0:64ea583d77e2 | 8 | #include "PinDetect.h" |
cmathis | 0:64ea583d77e2 | 9 | #include "Speaker.h" |
cmathis | 0:64ea583d77e2 | 10 | |
cmathis | 0:64ea583d77e2 | 11 | // pushbutton interrupts with debounce |
cmathis | 0:64ea583d77e2 | 12 | PinDetect pb1(p25, PullUp); |
cmathis | 0:64ea583d77e2 | 13 | PinDetect pb2(p26, PullUp); |
cmathis | 0:64ea583d77e2 | 14 | PinDetect pb3(p23, PullUp); |
cmathis | 0:64ea583d77e2 | 15 | PinDetect pb4(p24, PullUp); |
cmathis | 0:64ea583d77e2 | 16 | |
cmathis | 0:64ea583d77e2 | 17 | // four LED outputs |
cmathis | 0:64ea583d77e2 | 18 | DigitalOut led1(p7); |
cmathis | 0:64ea583d77e2 | 19 | DigitalOut led2(p9); |
cmathis | 0:64ea583d77e2 | 20 | DigitalOut led3(p8); |
cmathis | 0:64ea583d77e2 | 21 | DigitalOut led4(p6); |
cmathis | 0:64ea583d77e2 | 22 | |
cmathis | 0:64ea583d77e2 | 23 | // speaker object |
cmathis | 0:64ea583d77e2 | 24 | Speaker mySpeaker(p21); |
cmathis | 0:64ea583d77e2 | 25 | |
cmathis | 0:64ea583d77e2 | 26 | // LCD object |
cmathis | 0:64ea583d77e2 | 27 | uLCD_4DGL uLCD(p28, p27, p29); |
cmathis | 0:64ea583d77e2 | 28 | |
cmathis | 0:64ea583d77e2 | 29 | // analog input for seeding rand() function |
cmathis | 0:64ea583d77e2 | 30 | AnalogIn adcReading(p18); |
cmathis | 0:64ea583d77e2 | 31 | |
cmathis | 0:64ea583d77e2 | 32 | // variable declarations |
cmathis | 0:64ea583d77e2 | 33 | int levels[16]; |
cmathis | 0:64ea583d77e2 | 34 | int levelsIndex; |
cmathis | 0:64ea583d77e2 | 35 | int level; |
cmathis | 0:64ea583d77e2 | 36 | int buttonPressed; |
cmathis | 0:64ea583d77e2 | 37 | int buttonPushes; |
cmathis | 0:64ea583d77e2 | 38 | int failed; |
cmathis | 0:64ea583d77e2 | 39 | int start = 1; |
cmathis | 0:64ea583d77e2 | 40 | int randomSeed; |
cmathis | 0:64ea583d77e2 | 41 | |
cmathis | 0:64ea583d77e2 | 42 | // function prototypes |
cmathis | 0:64ea583d77e2 | 43 | void enableInterrupts(); |
cmathis | 0:64ea583d77e2 | 44 | void disableInterrupts(); |
cmathis | 0:64ea583d77e2 | 45 | void startGame(); |
cmathis | 0:64ea583d77e2 | 46 | void setLevels(); |
cmathis | 0:64ea583d77e2 | 47 | void playSequence(); |
cmathis | 0:64ea583d77e2 | 48 | void pushOne(); |
cmathis | 0:64ea583d77e2 | 49 | void pushTwo(); |
cmathis | 0:64ea583d77e2 | 50 | void pushThree(); |
cmathis | 0:64ea583d77e2 | 51 | void pushFour(); |
cmathis | 0:64ea583d77e2 | 52 | void failedGame(); |
cmathis | 0:64ea583d77e2 | 53 | void endGame(); |
cmathis | 0:64ea583d77e2 | 54 | |
cmathis | 0:64ea583d77e2 | 55 | int main() { |
cmathis | 0:64ea583d77e2 | 56 | |
cmathis | 0:64ea583d77e2 | 57 | // read in value from analog input as unsigned short instead of float |
cmathis | 0:64ea583d77e2 | 58 | // and seed the rand() function with the value |
cmathis | 0:64ea583d77e2 | 59 | randomSeed = adcReading.read_u16(); |
cmathis | 0:64ea583d77e2 | 60 | srand(randomSeed); |
cmathis | 0:64ea583d77e2 | 61 | uLCD.baudrate(3000000); |
cmathis | 0:64ea583d77e2 | 62 | |
cmathis | 0:64ea583d77e2 | 63 | while(1) { |
cmathis | 0:64ea583d77e2 | 64 | |
cmathis | 0:64ea583d77e2 | 65 | // only initialize these variables at the start of each game |
cmathis | 0:64ea583d77e2 | 66 | if(start == 1){ |
cmathis | 0:64ea583d77e2 | 67 | failed = 0; |
cmathis | 0:64ea583d77e2 | 68 | level = 0; |
cmathis | 0:64ea583d77e2 | 69 | buttonPressed = 0; |
cmathis | 0:64ea583d77e2 | 70 | buttonPushes = 0; |
cmathis | 0:64ea583d77e2 | 71 | levelsIndex = 0; |
cmathis | 0:64ea583d77e2 | 72 | startGame(); |
cmathis | 0:64ea583d77e2 | 73 | } |
cmathis | 0:64ea583d77e2 | 74 | start = 0; |
cmathis | 0:64ea583d77e2 | 75 | |
cmathis | 0:64ea583d77e2 | 76 | // generate and play the sequence of LEDs (and sounds) that the player copies |
cmathis | 0:64ea583d77e2 | 77 | setLevels(); |
cmathis | 0:64ea583d77e2 | 78 | playSequence(); |
cmathis | 0:64ea583d77e2 | 79 | |
cmathis | 0:64ea583d77e2 | 80 | // enable the four pushbutton interrupts |
cmathis | 0:64ea583d77e2 | 81 | enableInterrupts(); |
cmathis | 0:64ea583d77e2 | 82 | |
cmathis | 0:64ea583d77e2 | 83 | // wait in this loop until the user pushes buttons the same number of times as the current level |
cmathis | 0:64ea583d77e2 | 84 | // or until the user has pushed an incorrect button |
cmathis | 0:64ea583d77e2 | 85 | while(buttonPushes != level && failed == 0){ |
cmathis | 0:64ea583d77e2 | 86 | wait(0.5); |
cmathis | 0:64ea583d77e2 | 87 | } |
cmathis | 0:64ea583d77e2 | 88 | |
cmathis | 0:64ea583d77e2 | 89 | // if the user has failed, disable the pushbutton interrupts, notify the user that they failed, |
cmathis | 0:64ea583d77e2 | 90 | // and then set start=1 so that the game restarts from level 1 |
cmathis | 0:64ea583d77e2 | 91 | if(failed == 1){ |
cmathis | 0:64ea583d77e2 | 92 | disableInterrupts(); |
cmathis | 0:64ea583d77e2 | 93 | failedGame(); |
cmathis | 0:64ea583d77e2 | 94 | start = 1; |
cmathis | 0:64ea583d77e2 | 95 | } |
cmathis | 0:64ea583d77e2 | 96 | |
cmathis | 0:64ea583d77e2 | 97 | // if the user has completed all of the levels without failing, disable the pushbutton interrupts, |
cmathis | 0:64ea583d77e2 | 98 | // notify the user that they won, and set start=1 so that the game restarts from level 1 |
cmathis | 0:64ea583d77e2 | 99 | if(level == 5 && failed == 0){ |
cmathis | 0:64ea583d77e2 | 100 | disableInterrupts(); |
cmathis | 0:64ea583d77e2 | 101 | endGame(); |
cmathis | 0:64ea583d77e2 | 102 | start = 1; |
cmathis | 0:64ea583d77e2 | 103 | } |
cmathis | 0:64ea583d77e2 | 104 | |
cmathis | 0:64ea583d77e2 | 105 | // if the user has not failed or completed all of the levels, disable the interrupts and continue |
cmathis | 0:64ea583d77e2 | 106 | disableInterrupts(); |
cmathis | 0:64ea583d77e2 | 107 | |
cmathis | 0:64ea583d77e2 | 108 | // set buttonpushes=0 to record the button presses for the next level |
cmathis | 0:64ea583d77e2 | 109 | buttonPushes = 0; |
cmathis | 0:64ea583d77e2 | 110 | |
cmathis | 0:64ea583d77e2 | 111 | // wait a short amount of time before starting the next game |
cmathis | 0:64ea583d77e2 | 112 | if(start==1){ |
cmathis | 0:64ea583d77e2 | 113 | wait(2); |
cmathis | 0:64ea583d77e2 | 114 | } |
cmathis | 0:64ea583d77e2 | 115 | |
cmathis | 0:64ea583d77e2 | 116 | } |
cmathis | 0:64ea583d77e2 | 117 | |
cmathis | 0:64ea583d77e2 | 118 | } |
cmathis | 0:64ea583d77e2 | 119 | |
cmathis | 0:64ea583d77e2 | 120 | |
cmathis | 0:64ea583d77e2 | 121 | void enableInterrupts(){ |
cmathis | 0:64ea583d77e2 | 122 | |
cmathis | 0:64ea583d77e2 | 123 | // set the four pushbutton interrupts to trigger on a falling edge |
cmathis | 0:64ea583d77e2 | 124 | pb1.attach_deasserted(&pushOne); |
cmathis | 0:64ea583d77e2 | 125 | pb2.attach_deasserted(&pushTwo); |
cmathis | 0:64ea583d77e2 | 126 | pb3.attach_deasserted(&pushThree); |
cmathis | 0:64ea583d77e2 | 127 | pb4.attach_deasserted(&pushFour); |
cmathis | 0:64ea583d77e2 | 128 | |
cmathis | 0:64ea583d77e2 | 129 | // start the four interrupts (default sample frequency is 20ms) |
cmathis | 0:64ea583d77e2 | 130 | pb1.setSampleFrequency(); |
cmathis | 0:64ea583d77e2 | 131 | pb2.setSampleFrequency(); |
cmathis | 0:64ea583d77e2 | 132 | pb3.setSampleFrequency(); |
cmathis | 0:64ea583d77e2 | 133 | pb4.setSampleFrequency(); |
cmathis | 0:64ea583d77e2 | 134 | |
cmathis | 0:64ea583d77e2 | 135 | } |
cmathis | 0:64ea583d77e2 | 136 | |
cmathis | 0:64ea583d77e2 | 137 | |
cmathis | 0:64ea583d77e2 | 138 | void disableInterrupts(){ |
cmathis | 0:64ea583d77e2 | 139 | |
cmathis | 0:64ea583d77e2 | 140 | // disable four interrupts by setting their service routine to NULL pointer |
cmathis | 0:64ea583d77e2 | 141 | pb1.attach_deasserted(NULL); |
cmathis | 0:64ea583d77e2 | 142 | pb2.attach_deasserted(NULL); |
cmathis | 0:64ea583d77e2 | 143 | pb3.attach_deasserted(NULL); |
cmathis | 0:64ea583d77e2 | 144 | pb4.attach_deasserted(NULL); |
cmathis | 0:64ea583d77e2 | 145 | |
cmathis | 0:64ea583d77e2 | 146 | } |
cmathis | 0:64ea583d77e2 | 147 | |
cmathis | 0:64ea583d77e2 | 148 | // this function is called at the beginning of the game |
cmathis | 0:64ea583d77e2 | 149 | void startGame(){ |
cmathis | 0:64ea583d77e2 | 150 | |
cmathis | 0:64ea583d77e2 | 151 | uLCD.cls(); |
cmathis | 0:64ea583d77e2 | 152 | uLCD.display_control(PORTRAIT); |
cmathis | 0:64ea583d77e2 | 153 | uLCD.color(BLUE); |
cmathis | 0:64ea583d77e2 | 154 | uLCD.text_width(2); |
cmathis | 0:64ea583d77e2 | 155 | uLCD.text_height(2); |
cmathis | 0:64ea583d77e2 | 156 | uLCD.locate(2, 3); |
cmathis | 0:64ea583d77e2 | 157 | uLCD.printf("SIMON"); |
cmathis | 0:64ea583d77e2 | 158 | |
cmathis | 1:cd222334a4fe | 159 | // start up LED/uLCD sequence |
cmathis | 0:64ea583d77e2 | 160 | led1 = 1; |
cmathis | 0:64ea583d77e2 | 161 | uLCD.filled_rectangle(0, 0, 63, 40, 0x00CC00); |
cmathis | 0:64ea583d77e2 | 162 | wait(0.5); |
cmathis | 0:64ea583d77e2 | 163 | led1 = 0; |
cmathis | 0:64ea583d77e2 | 164 | uLCD.filled_rectangle(0, 0, 63, 40, 0x000000); |
cmathis | 0:64ea583d77e2 | 165 | |
cmathis | 0:64ea583d77e2 | 166 | led2 = 1; |
cmathis | 0:64ea583d77e2 | 167 | uLCD.filled_rectangle(64, 0, 127, 40, 0xFF0000); |
cmathis | 0:64ea583d77e2 | 168 | wait(0.5); |
cmathis | 0:64ea583d77e2 | 169 | led2 = 0; |
cmathis | 0:64ea583d77e2 | 170 | uLCD.filled_rectangle(64, 0, 127, 40, 0x000000); |
cmathis | 0:64ea583d77e2 | 171 | |
cmathis | 0:64ea583d77e2 | 172 | led3 = 1; |
cmathis | 0:64ea583d77e2 | 173 | uLCD.filled_rectangle(64, 87, 127, 127, 0x0000FF); |
cmathis | 0:64ea583d77e2 | 174 | wait(0.5); |
cmathis | 0:64ea583d77e2 | 175 | led3 = 0; |
cmathis | 0:64ea583d77e2 | 176 | uLCD.filled_rectangle(64, 87, 127, 127, 0x000000); |
cmathis | 0:64ea583d77e2 | 177 | |
cmathis | 0:64ea583d77e2 | 178 | led4 = 1; |
cmathis | 0:64ea583d77e2 | 179 | uLCD.filled_rectangle(0, 87, 63, 127, 0xCCCC00); |
cmathis | 0:64ea583d77e2 | 180 | wait(0.5); |
cmathis | 0:64ea583d77e2 | 181 | led4 = 0; |
cmathis | 0:64ea583d77e2 | 182 | uLCD.filled_rectangle(0, 87, 63, 127, 0x000000); |
cmathis | 0:64ea583d77e2 | 183 | |
cmathis | 0:64ea583d77e2 | 184 | wait(2); |
cmathis | 0:64ea583d77e2 | 185 | |
cmathis | 0:64ea583d77e2 | 186 | uLCD.cls(); |
cmathis | 0:64ea583d77e2 | 187 | |
cmathis | 0:64ea583d77e2 | 188 | } |
cmathis | 0:64ea583d77e2 | 189 | |
cmathis | 0:64ea583d77e2 | 190 | |
cmathis | 0:64ea583d77e2 | 191 | void setLevels(){ |
cmathis | 0:64ea583d77e2 | 192 | |
cmathis | 0:64ea583d77e2 | 193 | // "levels" array is a sequence of numbers 1-4 that determines which LEDs will light up |
cmathis | 0:64ea583d77e2 | 194 | // during a given level --- grows by 1 value each level |
cmathis | 0:64ea583d77e2 | 195 | level++; |
cmathis | 0:64ea583d77e2 | 196 | levels[level-1] = rand()%4 + 1; |
cmathis | 0:64ea583d77e2 | 197 | |
cmathis | 1:cd222334a4fe | 198 | // display the current level on the uLCD |
cmathis | 0:64ea583d77e2 | 199 | uLCD.color(BLUE); |
cmathis | 0:64ea583d77e2 | 200 | uLCD.text_width(2); |
cmathis | 0:64ea583d77e2 | 201 | uLCD.text_height(2); |
cmathis | 0:64ea583d77e2 | 202 | uLCD.locate(2, 2); |
cmathis | 0:64ea583d77e2 | 203 | uLCD.printf("Level"); |
cmathis | 0:64ea583d77e2 | 204 | uLCD.locate(4, 4); |
cmathis | 0:64ea583d77e2 | 205 | uLCD.printf("%d", level); |
cmathis | 0:64ea583d77e2 | 206 | wait(1); |
cmathis | 0:64ea583d77e2 | 207 | |
cmathis | 0:64ea583d77e2 | 208 | } |
cmathis | 0:64ea583d77e2 | 209 | |
cmathis | 0:64ea583d77e2 | 210 | |
cmathis | 0:64ea583d77e2 | 211 | void playSequence(){ |
cmathis | 0:64ea583d77e2 | 212 | |
cmathis | 0:64ea583d77e2 | 213 | // play the sequence of LEDs defined in the "levels" array along with the corresponding notes |
cmathis | 0:64ea583d77e2 | 214 | for(int i = 0; i < level; i++){ |
cmathis | 0:64ea583d77e2 | 215 | switch(levels[i]){ |
cmathis | 0:64ea583d77e2 | 216 | case 1: |
cmathis | 0:64ea583d77e2 | 217 | led1 = 1; |
cmathis | 0:64ea583d77e2 | 218 | mySpeaker.PlayNote(659.26, 0.50, 0.2); |
cmathis | 0:64ea583d77e2 | 219 | led1 = 0; |
cmathis | 0:64ea583d77e2 | 220 | wait(0.025); |
cmathis | 0:64ea583d77e2 | 221 | break; |
cmathis | 0:64ea583d77e2 | 222 | case 2: |
cmathis | 0:64ea583d77e2 | 223 | led2 = 1; |
cmathis | 0:64ea583d77e2 | 224 | mySpeaker.PlayNote(554.00, 0.50, 0.2); |
cmathis | 0:64ea583d77e2 | 225 | led2 = 0; |
cmathis | 0:64ea583d77e2 | 226 | wait(0.025); |
cmathis | 0:64ea583d77e2 | 227 | break; |
cmathis | 0:64ea583d77e2 | 228 | case 3: |
cmathis | 0:64ea583d77e2 | 229 | led3 = 1; |
cmathis | 0:64ea583d77e2 | 230 | mySpeaker.PlayNote(440.00, 0.50, 0.2); |
cmathis | 0:64ea583d77e2 | 231 | led3 = 0; |
cmathis | 0:64ea583d77e2 | 232 | wait(0.025); |
cmathis | 0:64ea583d77e2 | 233 | break; |
cmathis | 0:64ea583d77e2 | 234 | case 4: |
cmathis | 0:64ea583d77e2 | 235 | led4 = 1; |
cmathis | 0:64ea583d77e2 | 236 | mySpeaker.PlayNote(329.63, 0.50, 0.2); |
cmathis | 0:64ea583d77e2 | 237 | led4 = 0; |
cmathis | 0:64ea583d77e2 | 238 | wait(0.025); |
cmathis | 0:64ea583d77e2 | 239 | break; |
cmathis | 0:64ea583d77e2 | 240 | default: |
cmathis | 0:64ea583d77e2 | 241 | while(1){ |
cmathis | 0:64ea583d77e2 | 242 | led1 = !led1; |
cmathis | 0:64ea583d77e2 | 243 | wait(0.5); |
cmathis | 0:64ea583d77e2 | 244 | } |
cmathis | 0:64ea583d77e2 | 245 | } |
cmathis | 0:64ea583d77e2 | 246 | } |
cmathis | 0:64ea583d77e2 | 247 | |
cmathis | 0:64ea583d77e2 | 248 | } |
cmathis | 0:64ea583d77e2 | 249 | |
cmathis | 0:64ea583d77e2 | 250 | // ISR for pushbutton 1 interrupt |
cmathis | 0:64ea583d77e2 | 251 | void pushOne(){ |
cmathis | 0:64ea583d77e2 | 252 | |
cmathis | 0:64ea583d77e2 | 253 | buttonPushes++; |
cmathis | 0:64ea583d77e2 | 254 | |
cmathis | 0:64ea583d77e2 | 255 | led1 = 1; |
cmathis | 0:64ea583d77e2 | 256 | mySpeaker.PlayNote(659.26, 0.25, 0.2); |
cmathis | 0:64ea583d77e2 | 257 | led1 = 0; |
cmathis | 0:64ea583d77e2 | 258 | |
cmathis | 0:64ea583d77e2 | 259 | if(levels[buttonPushes-1] != 1){ |
cmathis | 0:64ea583d77e2 | 260 | failed = 1; |
cmathis | 0:64ea583d77e2 | 261 | } |
cmathis | 0:64ea583d77e2 | 262 | |
cmathis | 0:64ea583d77e2 | 263 | } |
cmathis | 0:64ea583d77e2 | 264 | |
cmathis | 0:64ea583d77e2 | 265 | // ISR for pushbutton 2 interrupt |
cmathis | 0:64ea583d77e2 | 266 | void pushTwo(){ |
cmathis | 0:64ea583d77e2 | 267 | |
cmathis | 0:64ea583d77e2 | 268 | buttonPushes++; |
cmathis | 0:64ea583d77e2 | 269 | |
cmathis | 0:64ea583d77e2 | 270 | led2 = 1; |
cmathis | 0:64ea583d77e2 | 271 | mySpeaker.PlayNote(554.00, 0.25, 0.2); |
cmathis | 0:64ea583d77e2 | 272 | led2 = 0; |
cmathis | 0:64ea583d77e2 | 273 | |
cmathis | 0:64ea583d77e2 | 274 | if(levels[buttonPushes-1] != 2){ |
cmathis | 0:64ea583d77e2 | 275 | failed = 1; |
cmathis | 0:64ea583d77e2 | 276 | } |
cmathis | 0:64ea583d77e2 | 277 | |
cmathis | 0:64ea583d77e2 | 278 | } |
cmathis | 0:64ea583d77e2 | 279 | |
cmathis | 0:64ea583d77e2 | 280 | // ISR for pushbutton 3 interrupt |
cmathis | 0:64ea583d77e2 | 281 | void pushThree(){ |
cmathis | 0:64ea583d77e2 | 282 | |
cmathis | 0:64ea583d77e2 | 283 | buttonPushes++; |
cmathis | 0:64ea583d77e2 | 284 | |
cmathis | 0:64ea583d77e2 | 285 | led3 = 1; |
cmathis | 0:64ea583d77e2 | 286 | mySpeaker.PlayNote(440.00, 0.25, 0.2); |
cmathis | 0:64ea583d77e2 | 287 | led3 = 0; |
cmathis | 0:64ea583d77e2 | 288 | |
cmathis | 0:64ea583d77e2 | 289 | if(levels[buttonPushes-1] != 3){ |
cmathis | 0:64ea583d77e2 | 290 | failed = 1; |
cmathis | 0:64ea583d77e2 | 291 | } |
cmathis | 0:64ea583d77e2 | 292 | |
cmathis | 0:64ea583d77e2 | 293 | } |
cmathis | 0:64ea583d77e2 | 294 | |
cmathis | 0:64ea583d77e2 | 295 | // ISR for pushbutton 4 interrupt |
cmathis | 0:64ea583d77e2 | 296 | void pushFour(){ |
cmathis | 0:64ea583d77e2 | 297 | |
cmathis | 0:64ea583d77e2 | 298 | buttonPushes++; |
cmathis | 0:64ea583d77e2 | 299 | |
cmathis | 0:64ea583d77e2 | 300 | led4 = 1; |
cmathis | 0:64ea583d77e2 | 301 | mySpeaker.PlayNote(329.63, 0.25, 0.2); |
cmathis | 0:64ea583d77e2 | 302 | led4 = 0; |
cmathis | 0:64ea583d77e2 | 303 | |
cmathis | 0:64ea583d77e2 | 304 | if(levels[buttonPushes-1] != 4){ |
cmathis | 0:64ea583d77e2 | 305 | failed = 1; |
cmathis | 0:64ea583d77e2 | 306 | } |
cmathis | 0:64ea583d77e2 | 307 | |
cmathis | 0:64ea583d77e2 | 308 | } |
cmathis | 0:64ea583d77e2 | 309 | |
cmathis | 0:64ea583d77e2 | 310 | // this function is called when the user fails the game |
cmathis | 0:64ea583d77e2 | 311 | void failedGame(){ |
cmathis | 0:64ea583d77e2 | 312 | |
cmathis | 0:64ea583d77e2 | 313 | uLCD.cls(); |
cmathis | 0:64ea583d77e2 | 314 | uLCD.color(RED); |
cmathis | 0:64ea583d77e2 | 315 | uLCD.text_width(2); |
cmathis | 0:64ea583d77e2 | 316 | uLCD.text_height(2); |
cmathis | 0:64ea583d77e2 | 317 | uLCD.locate(2, 2); |
cmathis | 0:64ea583d77e2 | 318 | uLCD.printf("Game"); |
cmathis | 0:64ea583d77e2 | 319 | uLCD.locate(2, 4); |
cmathis | 0:64ea583d77e2 | 320 | uLCD.printf("Over"); |
cmathis | 0:64ea583d77e2 | 321 | |
cmathis | 0:64ea583d77e2 | 322 | |
cmathis | 0:64ea583d77e2 | 323 | mySpeaker.PlayNote(147.00, 0.60, 1); |
cmathis | 0:64ea583d77e2 | 324 | mySpeaker.PlayNote(139.00, 0.60, 1); |
cmathis | 0:64ea583d77e2 | 325 | mySpeaker.PlayNote(131.00, 0.60, 1); |
cmathis | 0:64ea583d77e2 | 326 | mySpeaker.PlayNote(123.00, 1.60, 1); |
cmathis | 0:64ea583d77e2 | 327 | |
cmathis | 0:64ea583d77e2 | 328 | } |
cmathis | 0:64ea583d77e2 | 329 | |
cmathis | 0:64ea583d77e2 | 330 | // this function is called if the user completes all levels |
cmathis | 0:64ea583d77e2 | 331 | void endGame(){ |
cmathis | 0:64ea583d77e2 | 332 | |
cmathis | 0:64ea583d77e2 | 333 | uLCD.cls(); |
cmathis | 0:64ea583d77e2 | 334 | uLCD.color(GREEN); |
cmathis | 0:64ea583d77e2 | 335 | uLCD.text_width(2); |
cmathis | 0:64ea583d77e2 | 336 | uLCD.text_height(2); |
cmathis | 0:64ea583d77e2 | 337 | uLCD.locate(2, 2); |
cmathis | 0:64ea583d77e2 | 338 | uLCD.printf("YOU"); |
cmathis | 0:64ea583d77e2 | 339 | uLCD.locate(2, 4); |
cmathis | 0:64ea583d77e2 | 340 | uLCD.printf("WIN!"); |
cmathis | 0:64ea583d77e2 | 341 | |
cmathis | 0:64ea583d77e2 | 342 | int time = 0.01; |
cmathis | 0:64ea583d77e2 | 343 | |
cmathis | 0:64ea583d77e2 | 344 | mySpeaker.PlayNote(392.00, 0.33, 0.2); |
cmathis | 0:64ea583d77e2 | 345 | wait(time); |
cmathis | 0:64ea583d77e2 | 346 | mySpeaker.PlayNote(349.23, 0.17, 0.2); |
cmathis | 0:64ea583d77e2 | 347 | wait(time); |
cmathis | 0:64ea583d77e2 | 348 | |
cmathis | 0:64ea583d77e2 | 349 | mySpeaker.PlayNote(311.13, 0.33, 0.2); |
cmathis | 0:64ea583d77e2 | 350 | wait(time); |
cmathis | 0:64ea583d77e2 | 351 | mySpeaker.PlayNote(311.13, 0.17, 0.2); |
cmathis | 0:64ea583d77e2 | 352 | wait(time); |
cmathis | 0:64ea583d77e2 | 353 | mySpeaker.PlayNote(311.13, 0.33, 0.2); |
cmathis | 0:64ea583d77e2 | 354 | wait(time); |
cmathis | 0:64ea583d77e2 | 355 | mySpeaker.PlayNote(349.23, 0.17, 0.2); |
cmathis | 0:64ea583d77e2 | 356 | wait(time); |
cmathis | 0:64ea583d77e2 | 357 | |
cmathis | 0:64ea583d77e2 | 358 | mySpeaker.PlayNote(392.00, 0.33, 0.2); |
cmathis | 0:64ea583d77e2 | 359 | wait(time); |
cmathis | 0:64ea583d77e2 | 360 | mySpeaker.PlayNote(392.00, 0.17, 0.2); |
cmathis | 0:64ea583d77e2 | 361 | wait(time); |
cmathis | 0:64ea583d77e2 | 362 | mySpeaker.PlayNote(392.00, 0.165, 0.2); |
cmathis | 0:64ea583d77e2 | 363 | wait(time); |
cmathis | 0:64ea583d77e2 | 364 | mySpeaker.PlayNote(349.23, 0.165, 0.2); |
cmathis | 0:64ea583d77e2 | 365 | wait(time); |
cmathis | 0:64ea583d77e2 | 366 | mySpeaker.PlayNote(311.13, 0.17, 0.2); |
cmathis | 0:64ea583d77e2 | 367 | wait(time); |
cmathis | 0:64ea583d77e2 | 368 | |
cmathis | 0:64ea583d77e2 | 369 | mySpeaker.PlayNote(349.23, 0.165, 0.2); |
cmathis | 0:64ea583d77e2 | 370 | wait(time); |
cmathis | 0:64ea583d77e2 | 371 | mySpeaker.PlayNote(392.00, 0.165, 0.2); |
cmathis | 0:64ea583d77e2 | 372 | wait(time); |
cmathis | 0:64ea583d77e2 | 373 | mySpeaker.PlayNote(349.23, 0.17, 0.2); |
cmathis | 0:64ea583d77e2 | 374 | wait(time); |
cmathis | 0:64ea583d77e2 | 375 | mySpeaker.PlayNote(311.13, 0.33, 0.2); |
cmathis | 0:64ea583d77e2 | 376 | wait(time); |
cmathis | 0:64ea583d77e2 | 377 | mySpeaker.PlayNote(293.66, 0.17, 0.2); |
cmathis | 0:64ea583d77e2 | 378 | wait(time); |
cmathis | 0:64ea583d77e2 | 379 | |
cmathis | 0:64ea583d77e2 | 380 | mySpeaker.PlayNote(311.13, 0.5, 0.2); |
cmathis | 0:64ea583d77e2 | 381 | |
cmathis | 0:64ea583d77e2 | 382 | } |