Final Trivia Game Code
Dependencies: 4DGL-uLCD-SE SDFileSystem mbed wave_player
Fork of TriviaGame by
main.cpp@3:9842b3f1d809, 2016-12-11 (annotated)
- Committer:
- mbalourdas9
- Date:
- Sun Dec 11 03:09:22 2016 +0000
- Revision:
- 3:9842b3f1d809
- Parent:
- 1:1d5055ca2793
- Child:
- 4:55bb76d28153
New
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbalourdas9 | 1:1d5055ca2793 | 1 | #include "mbed.h" |
mbalourdas9 | 1:1d5055ca2793 | 2 | #include "SDFileSystem.h" |
mbalourdas9 | 1:1d5055ca2793 | 3 | #include "uLCD_4DGL.h" |
mbalourdas9 | 1:1d5055ca2793 | 4 | #include "wave_player.h" |
mbalourdas9 | 1:1d5055ca2793 | 5 | #include "mpr121.h" |
mbalourdas9 | 1:1d5055ca2793 | 6 | #include <vector> |
mbalourdas9 | 3:9842b3f1d809 | 7 | #include <string> |
mbalourdas9 | 3:9842b3f1d809 | 8 | #include "stdlib.h" |
mbalourdas9 | 3:9842b3f1d809 | 9 | #include "stdio.h" |
mbalourdas9 | 3:9842b3f1d809 | 10 | |
mbalourdas9 | 3:9842b3f1d809 | 11 | |
4180_1 | 0:e09703934ff4 | 12 | |
mbalourdas9 | 1:1d5055ca2793 | 13 | AnalogOut DACout(p18); // used to play sound on speaker |
mbalourdas9 | 1:1d5055ca2793 | 14 | //wave player plays a *.wav file to D/A and a PWM |
mbalourdas9 | 1:1d5055ca2793 | 15 | wave_player waver(&DACout); |
4180_1 | 0:e09703934ff4 | 16 | InterruptIn interrupt(p26); |
4180_1 | 0:e09703934ff4 | 17 | I2C i2c(p9, p10); |
4180_1 | 0:e09703934ff4 | 18 | Mpr121 mpr121(&i2c, Mpr121::ADD_VSS); |
mbalourdas9 | 3:9842b3f1d809 | 19 | Serial pc(USBTX, USBRX); |
4180_1 | 0:e09703934ff4 | 20 | |
mbalourdas9 | 1:1d5055ca2793 | 21 | uLCD_4DGL uLCD(p28,p27,p29); // serial tx, serial rx, reset pin; |
mbalourdas9 | 1:1d5055ca2793 | 22 | SDFileSystem sd(p5, p6, p7, p8, "sd"); //SD card setup |
mbalourdas9 | 1:1d5055ca2793 | 23 | int Score; |
mbalourdas9 | 1:1d5055ca2793 | 24 | int HighScore = 0; |
mbalourdas9 | 1:1d5055ca2793 | 25 | int question = 0; |
mbalourdas9 | 1:1d5055ca2793 | 26 | bool answer = 1; |
mbalourdas9 | 1:1d5055ca2793 | 27 | int index = 0; |
mbalourdas9 | 1:1d5055ca2793 | 28 | bool check = 0; |
mbalourdas9 | 1:1d5055ca2793 | 29 | int value = 0; |
mbalourdas9 | 1:1d5055ca2793 | 30 | std::vector<int> v; |
mbalourdas9 | 3:9842b3f1d809 | 31 | Timer t; |
mbalourdas9 | 3:9842b3f1d809 | 32 | float tr = 0; |
mbalourdas9 | 3:9842b3f1d809 | 33 | int mode = 0; |
mbalourdas9 | 3:9842b3f1d809 | 34 | int counter = 0; |
mbalourdas9 | 3:9842b3f1d809 | 35 | int cScore = 0; |
mbalourdas9 | 3:9842b3f1d809 | 36 | int tScore = 0; |
mbalourdas9 | 3:9842b3f1d809 | 37 | int nScore = 0; |
mbalourdas9 | 3:9842b3f1d809 | 38 | int tHighScore = 0; |
mbalourdas9 | 3:9842b3f1d809 | 39 | int nHighScore = 0; |
mbalourdas9 | 3:9842b3f1d809 | 40 | int cHighScore = 0; |
mbalourdas9 | 3:9842b3f1d809 | 41 | string game; |
mbalourdas9 | 3:9842b3f1d809 | 42 | char nHigh[2]; |
mbalourdas9 | 3:9842b3f1d809 | 43 | char tHigh[2]; |
mbalourdas9 | 3:9842b3f1d809 | 44 | char cHigh[2]; |
4180_1 | 0:e09703934ff4 | 45 | |
mbalourdas9 | 3:9842b3f1d809 | 46 | void itoa(int n, char s[]) |
mbalourdas9 | 3:9842b3f1d809 | 47 | { |
mbalourdas9 | 3:9842b3f1d809 | 48 | int i, sign; |
mbalourdas9 | 3:9842b3f1d809 | 49 | |
mbalourdas9 | 3:9842b3f1d809 | 50 | if ((sign = n) < 0) /* record sign */ |
mbalourdas9 | 3:9842b3f1d809 | 51 | n = -n; /* make n positive */ |
mbalourdas9 | 3:9842b3f1d809 | 52 | i = 0; |
mbalourdas9 | 3:9842b3f1d809 | 53 | do { /* generate digits in reverse order */ |
mbalourdas9 | 3:9842b3f1d809 | 54 | s[i++] = n % 10 + '0'; /* get next digit */ |
mbalourdas9 | 3:9842b3f1d809 | 55 | } while ((n /= 10) > 0); /* delete it */ |
mbalourdas9 | 3:9842b3f1d809 | 56 | |
mbalourdas9 | 3:9842b3f1d809 | 57 | } |
4180_1 | 0:e09703934ff4 | 58 | |
mbalourdas9 | 1:1d5055ca2793 | 59 | int main() |
mbalourdas9 | 1:1d5055ca2793 | 60 | { |
mbalourdas9 | 1:1d5055ca2793 | 61 | srand(time(NULL)); |
mbalourdas9 | 1:1d5055ca2793 | 62 | while (true){ |
mbalourdas9 | 1:1d5055ca2793 | 63 | answer = 1; |
mbalourdas9 | 1:1d5055ca2793 | 64 | for (int i=0; i<10; i++){ |
mbalourdas9 | 1:1d5055ca2793 | 65 | v.push_back(i+1); |
mbalourdas9 | 1:1d5055ca2793 | 66 | } |
mbalourdas9 | 1:1d5055ca2793 | 67 | check = 0; |
mbalourdas9 | 1:1d5055ca2793 | 68 | question = 0; |
mbalourdas9 | 3:9842b3f1d809 | 69 | uLCD.baudrate(30); |
mbalourdas9 | 1:1d5055ca2793 | 70 | uLCD.background_color(BLACK); |
mbalourdas9 | 1:1d5055ca2793 | 71 | uLCD.color(BLUE); |
mbalourdas9 | 1:1d5055ca2793 | 72 | uLCD.cls(); |
mbalourdas9 | 3:9842b3f1d809 | 73 | if (mode == 1){ |
mbalourdas9 | 3:9842b3f1d809 | 74 | uLCD.cls(); |
mbalourdas9 | 3:9842b3f1d809 | 75 | uLCD.media_init(); |
mbalourdas9 | 3:9842b3f1d809 | 76 | uLCD.set_sector_address(0x0000, 0x001D); |
mbalourdas9 | 3:9842b3f1d809 | 77 | uLCD.display_image(0,0); |
mbalourdas9 | 3:9842b3f1d809 | 78 | wait(2); |
mbalourdas9 | 3:9842b3f1d809 | 79 | uLCD.cls(); |
mbalourdas9 | 3:9842b3f1d809 | 80 | uLCD.printf("Final Score:%d\n", nScore); |
mbalourdas9 | 3:9842b3f1d809 | 81 | if (nScore > nHighScore){ |
mbalourdas9 | 3:9842b3f1d809 | 82 | nHighScore = nScore; |
mbalourdas9 | 3:9842b3f1d809 | 83 | uLCD.printf("NEW NORMAL\n HIGH SCORE!\n %d", nHighScore); |
mbalourdas9 | 3:9842b3f1d809 | 84 | |
mbalourdas9 | 3:9842b3f1d809 | 85 | wait(2); |
mbalourdas9 | 3:9842b3f1d809 | 86 | } |
mbalourdas9 | 3:9842b3f1d809 | 87 | itoa(nHighScore, nHigh); |
mbalourdas9 | 3:9842b3f1d809 | 88 | pc.puts(nHigh); |
mbalourdas9 | 3:9842b3f1d809 | 89 | uLCD.printf("\nClick New Game"); |
mbalourdas9 | 3:9842b3f1d809 | 90 | } |
mbalourdas9 | 3:9842b3f1d809 | 91 | if (mode == 2){ |
mbalourdas9 | 3:9842b3f1d809 | 92 | uLCD.cls(); |
mbalourdas9 | 3:9842b3f1d809 | 93 | uLCD.media_init(); |
mbalourdas9 | 3:9842b3f1d809 | 94 | uLCD.set_sector_address(0x0000, 0x001D); |
mbalourdas9 | 3:9842b3f1d809 | 95 | uLCD.display_image(0,0); |
mbalourdas9 | 3:9842b3f1d809 | 96 | wait(2); |
mbalourdas9 | 3:9842b3f1d809 | 97 | uLCD.cls(); |
mbalourdas9 | 3:9842b3f1d809 | 98 | uLCD.printf("Final Score:%d\n", tScore); |
mbalourdas9 | 3:9842b3f1d809 | 99 | if (tScore > tHighScore){ |
mbalourdas9 | 3:9842b3f1d809 | 100 | tHighScore = tScore; |
mbalourdas9 | 3:9842b3f1d809 | 101 | uLCD.printf("NEW TIMED\n HIGH SCORE!\n %d", tHighScore); |
mbalourdas9 | 3:9842b3f1d809 | 102 | wait(2); |
mbalourdas9 | 3:9842b3f1d809 | 103 | } |
mbalourdas9 | 3:9842b3f1d809 | 104 | |
mbalourdas9 | 3:9842b3f1d809 | 105 | itoa(tHighScore, tHigh); |
mbalourdas9 | 3:9842b3f1d809 | 106 | pc.puts(tHigh); |
mbalourdas9 | 3:9842b3f1d809 | 107 | uLCD.printf("\nClick New Game"); |
mbalourdas9 | 3:9842b3f1d809 | 108 | } |
mbalourdas9 | 3:9842b3f1d809 | 109 | if (mode == 4){ |
mbalourdas9 | 3:9842b3f1d809 | 110 | uLCD.cls(); |
mbalourdas9 | 3:9842b3f1d809 | 111 | uLCD.media_init(); |
mbalourdas9 | 3:9842b3f1d809 | 112 | uLCD.set_sector_address(0x0000, 0x001D); |
mbalourdas9 | 3:9842b3f1d809 | 113 | uLCD.display_image(0,0); |
mbalourdas9 | 3:9842b3f1d809 | 114 | wait(2); |
mbalourdas9 | 3:9842b3f1d809 | 115 | uLCD.cls(); |
mbalourdas9 | 3:9842b3f1d809 | 116 | uLCD.printf("Final Score: %d\n", cScore); |
mbalourdas9 | 3:9842b3f1d809 | 117 | if (cScore > cHighScore){ |
mbalourdas9 | 3:9842b3f1d809 | 118 | cHighScore = cScore; |
mbalourdas9 | 3:9842b3f1d809 | 119 | uLCD.printf("NEW CHALLENGE\n HIGH SCORE!\n %d", cHighScore); |
mbalourdas9 | 1:1d5055ca2793 | 120 | wait(2); |
mbalourdas9 | 1:1d5055ca2793 | 121 | } |
mbalourdas9 | 3:9842b3f1d809 | 122 | itoa(cHighScore, cHigh); |
mbalourdas9 | 3:9842b3f1d809 | 123 | pc.puts(cHigh); |
mbalourdas9 | 3:9842b3f1d809 | 124 | uLCD.printf("\nClick New Game"); |
mbalourdas9 | 3:9842b3f1d809 | 125 | } |
mbalourdas9 | 3:9842b3f1d809 | 126 | wait(2); |
mbalourdas9 | 3:9842b3f1d809 | 127 | uLCD.cls(); |
mbalourdas9 | 3:9842b3f1d809 | 128 | nScore = 0; |
mbalourdas9 | 3:9842b3f1d809 | 129 | tScore=0; |
mbalourdas9 | 3:9842b3f1d809 | 130 | cScore=0; |
mbalourdas9 | 3:9842b3f1d809 | 131 | counter = 0; |
mbalourdas9 | 3:9842b3f1d809 | 132 | |
mbalourdas9 | 1:1d5055ca2793 | 133 | uLCD.cls(); |
mbalourdas9 | 3:9842b3f1d809 | 134 | uLCD.printf("Choose a Game Mode"); |
mbalourdas9 | 3:9842b3f1d809 | 135 | //uLCD.printf("High Score: %d \n", HighScore); |
mbalourdas9 | 3:9842b3f1d809 | 136 | //uLCD.printf("\n0) Normal Game\n High Score:%d\n1) Timed Game\n High Score:%d\n2)Challenge Game\n High Score:%d", nHighScore, tHighScore, cHighScore); |
mbalourdas9 | 3:9842b3f1d809 | 137 | while (1){ |
mbalourdas9 | 3:9842b3f1d809 | 138 | game = pc.getc(); |
mbalourdas9 | 3:9842b3f1d809 | 139 | //mode=mpr121.read(0x00); |
mbalourdas9 | 3:9842b3f1d809 | 140 | // mode +=mpr121.read(0x01)<<8; |
mbalourdas9 | 3:9842b3f1d809 | 141 | if (game == "1"){ |
mbalourdas9 | 3:9842b3f1d809 | 142 | mode = 1; |
mbalourdas9 | 3:9842b3f1d809 | 143 | break; |
mbalourdas9 | 3:9842b3f1d809 | 144 | } |
mbalourdas9 | 3:9842b3f1d809 | 145 | if (game == "2"){ |
mbalourdas9 | 3:9842b3f1d809 | 146 | mode = 2; |
mbalourdas9 | 3:9842b3f1d809 | 147 | break; |
mbalourdas9 | 1:1d5055ca2793 | 148 | } |
mbalourdas9 | 3:9842b3f1d809 | 149 | if (game == "4"){ |
mbalourdas9 | 3:9842b3f1d809 | 150 | mode = 4; |
mbalourdas9 | 3:9842b3f1d809 | 151 | break; |
mbalourdas9 | 3:9842b3f1d809 | 152 | } |
mbalourdas9 | 3:9842b3f1d809 | 153 | } |
mbalourdas9 | 3:9842b3f1d809 | 154 | |
mbalourdas9 | 1:1d5055ca2793 | 155 | uLCD.cls(); |
mbalourdas9 | 3:9842b3f1d809 | 156 | t.reset(); |
mbalourdas9 | 3:9842b3f1d809 | 157 | t.stop(); |
mbalourdas9 | 3:9842b3f1d809 | 158 | t.start(); |
mbalourdas9 | 3:9842b3f1d809 | 159 | //end of main menu |
mbalourdas9 | 1:1d5055ca2793 | 160 | if (v.size() !=0){ |
mbalourdas9 | 1:1d5055ca2793 | 161 | while (answer == 1){ |
mbalourdas9 | 3:9842b3f1d809 | 162 | if (mode == 2){ |
mbalourdas9 | 3:9842b3f1d809 | 163 | tr = t.read(); |
mbalourdas9 | 3:9842b3f1d809 | 164 | if (tr > 60){ |
mbalourdas9 | 3:9842b3f1d809 | 165 | break; |
mbalourdas9 | 3:9842b3f1d809 | 166 | } |
mbalourdas9 | 3:9842b3f1d809 | 167 | } |
mbalourdas9 | 3:9842b3f1d809 | 168 | if (mode == 4){ |
mbalourdas9 | 3:9842b3f1d809 | 169 | if (counter > 3){ |
mbalourdas9 | 3:9842b3f1d809 | 170 | break; |
mbalourdas9 | 3:9842b3f1d809 | 171 | } |
mbalourdas9 | 3:9842b3f1d809 | 172 | } |
mbalourdas9 | 1:1d5055ca2793 | 173 | if (v.size() == 0){ |
mbalourdas9 | 1:1d5055ca2793 | 174 | break; |
mbalourdas9 | 1:1d5055ca2793 | 175 | } |
mbalourdas9 | 1:1d5055ca2793 | 176 | index = rand() %v.size(); |
mbalourdas9 | 1:1d5055ca2793 | 177 | question = v.at(index); |
mbalourdas9 | 1:1d5055ca2793 | 178 | v.erase(v.begin()+index); |
mbalourdas9 | 1:1d5055ca2793 | 179 | check = 0; |
mbalourdas9 | 1:1d5055ca2793 | 180 | uLCD.cls(); |
mbalourdas9 | 3:9842b3f1d809 | 181 | if (mode == 1){ |
mbalourdas9 | 3:9842b3f1d809 | 182 | uLCD.printf("Score: %d", nScore); |
mbalourdas9 | 3:9842b3f1d809 | 183 | } |
mbalourdas9 | 1:1d5055ca2793 | 184 | wait(1); |
mbalourdas9 | 1:1d5055ca2793 | 185 | if (question == 1){ |
mbalourdas9 | 1:1d5055ca2793 | 186 | value = 0; |
mbalourdas9 | 1:1d5055ca2793 | 187 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 188 | uLCD.locate(1,2); |
mbalourdas9 | 1:1d5055ca2793 | 189 | uLCD.printf("Who won the World Series in 2016?\n\n\n"); |
mbalourdas9 | 1:1d5055ca2793 | 190 | uLCD.printf("1) Cleveland\nIndians\n"); |
mbalourdas9 | 1:1d5055ca2793 | 191 | uLCD.printf("2) Chicago Cubs\n"); |
mbalourdas9 | 1:1d5055ca2793 | 192 | uLCD.printf("3) San Diego\nPadres\n"); |
mbalourdas9 | 1:1d5055ca2793 | 193 | while (check == 0){ |
mbalourdas9 | 1:1d5055ca2793 | 194 | int value=mpr121.read(0x00); |
mbalourdas9 | 1:1d5055ca2793 | 195 | value +=mpr121.read(0x01)<<8; |
mbalourdas9 | 1:1d5055ca2793 | 196 | if (value == 2){ |
mbalourdas9 | 1:1d5055ca2793 | 197 | //play game over |
mbalourdas9 | 1:1d5055ca2793 | 198 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 199 | uLCD.media_init(); |
mbalourdas9 | 3:9842b3f1d809 | 200 | uLCD.set_sector_address(0x0000, 0x001D); |
mbalourdas9 | 1:1d5055ca2793 | 201 | uLCD.display_image(0,0); |
mbalourdas9 | 1:1d5055ca2793 | 202 | FILE *wave_file; |
mbalourdas9 | 1:1d5055ca2793 | 203 | wave_file=fopen("/sd/sounds/wrong_last.wav","r"); |
mbalourdas9 | 1:1d5055ca2793 | 204 | waver.play(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 205 | fclose(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 206 | wait(1); |
mbalourdas9 | 1:1d5055ca2793 | 207 | uLCD.cls(); |
mbalourdas9 | 3:9842b3f1d809 | 208 | if (mode == 1){ |
mbalourdas9 | 1:1d5055ca2793 | 209 | answer = 0; |
mbalourdas9 | 3:9842b3f1d809 | 210 | } |
mbalourdas9 | 3:9842b3f1d809 | 211 | counter = counter +1; |
mbalourdas9 | 3:9842b3f1d809 | 212 | |
mbalourdas9 | 1:1d5055ca2793 | 213 | check = 1; |
mbalourdas9 | 1:1d5055ca2793 | 214 | } |
mbalourdas9 | 1:1d5055ca2793 | 215 | if (value == 4){ |
mbalourdas9 | 1:1d5055ca2793 | 216 | //play correct image |
mbalourdas9 | 1:1d5055ca2793 | 217 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 218 | uLCD.media_init(); |
mbalourdas9 | 1:1d5055ca2793 | 219 | uLCD.set_sector_address(0x0000, 0x005E); |
mbalourdas9 | 1:1d5055ca2793 | 220 | uLCD.display_image(0,0); |
mbalourdas9 | 1:1d5055ca2793 | 221 | FILE *wave_file; |
mbalourdas9 | 1:1d5055ca2793 | 222 | wave_file=fopen("/sd/sounds/right_taught.wav","r"); |
mbalourdas9 | 1:1d5055ca2793 | 223 | waver.play(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 224 | fclose(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 225 | wait(1); |
mbalourdas9 | 1:1d5055ca2793 | 226 | uLCD.cls(); |
mbalourdas9 | 3:9842b3f1d809 | 227 | if (mode == 1){ |
mbalourdas9 | 3:9842b3f1d809 | 228 | nScore = nScore+1; |
mbalourdas9 | 3:9842b3f1d809 | 229 | } |
mbalourdas9 | 3:9842b3f1d809 | 230 | if (mode == 2){ |
mbalourdas9 | 3:9842b3f1d809 | 231 | tScore = tScore+1; |
mbalourdas9 | 3:9842b3f1d809 | 232 | } |
mbalourdas9 | 3:9842b3f1d809 | 233 | if (mode == 4){ |
mbalourdas9 | 3:9842b3f1d809 | 234 | cScore = cScore+1; |
mbalourdas9 | 3:9842b3f1d809 | 235 | } |
mbalourdas9 | 1:1d5055ca2793 | 236 | wait(1); |
mbalourdas9 | 3:9842b3f1d809 | 237 | if (mode == 1){ |
mbalourdas9 | 1:1d5055ca2793 | 238 | answer = 1; |
mbalourdas9 | 3:9842b3f1d809 | 239 | } |
mbalourdas9 | 3:9842b3f1d809 | 240 | counter=counter+1; |
mbalourdas9 | 1:1d5055ca2793 | 241 | check = 1; |
mbalourdas9 | 1:1d5055ca2793 | 242 | } |
mbalourdas9 | 1:1d5055ca2793 | 243 | if (value == 8){ |
mbalourdas9 | 1:1d5055ca2793 | 244 | //play game over |
mbalourdas9 | 1:1d5055ca2793 | 245 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 246 | uLCD.media_init(); |
mbalourdas9 | 3:9842b3f1d809 | 247 | uLCD.set_sector_address(0x0000, 0x001D); |
mbalourdas9 | 1:1d5055ca2793 | 248 | uLCD.display_image(0,0); |
mbalourdas9 | 1:1d5055ca2793 | 249 | FILE *wave_file; |
mbalourdas9 | 1:1d5055ca2793 | 250 | wave_file=fopen("/sd/sounds/wrong_last.wav","r"); |
mbalourdas9 | 1:1d5055ca2793 | 251 | waver.play(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 252 | fclose(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 253 | wait(1); |
mbalourdas9 | 1:1d5055ca2793 | 254 | uLCD.cls(); |
mbalourdas9 | 3:9842b3f1d809 | 255 | if (mode == 1){ |
mbalourdas9 | 1:1d5055ca2793 | 256 | answer = 0; |
mbalourdas9 | 3:9842b3f1d809 | 257 | } |
mbalourdas9 | 3:9842b3f1d809 | 258 | counter = counter+1; |
mbalourdas9 | 1:1d5055ca2793 | 259 | check = 1; |
mbalourdas9 | 1:1d5055ca2793 | 260 | } |
mbalourdas9 | 1:1d5055ca2793 | 261 | } |
mbalourdas9 | 1:1d5055ca2793 | 262 | } |
mbalourdas9 | 1:1d5055ca2793 | 263 | if (question == 2){ |
mbalourdas9 | 1:1d5055ca2793 | 264 | value = 0; |
mbalourdas9 | 1:1d5055ca2793 | 265 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 266 | uLCD.locate(1,2); |
mbalourdas9 | 1:1d5055ca2793 | 267 | uLCD.printf("What is the\n capital of South\n Dakota?\n\n"); |
mbalourdas9 | 1:1d5055ca2793 | 268 | uLCD.printf("1) Pierre\n"); |
mbalourdas9 | 1:1d5055ca2793 | 269 | uLCD.printf("2) Bismarck\n"); |
mbalourdas9 | 1:1d5055ca2793 | 270 | uLCD.printf("3) Lakota\n"); |
mbalourdas9 | 1:1d5055ca2793 | 271 | while (check == 0){ |
mbalourdas9 | 1:1d5055ca2793 | 272 | int value=mpr121.read(0x00); |
mbalourdas9 | 1:1d5055ca2793 | 273 | value +=mpr121.read(0x01)<<8; |
mbalourdas9 | 3:9842b3f1d809 | 274 | if (value == 2){ |
mbalourdas9 | 1:1d5055ca2793 | 275 | //play game over |
mbalourdas9 | 1:1d5055ca2793 | 276 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 277 | uLCD.media_init(); |
mbalourdas9 | 3:9842b3f1d809 | 278 | uLCD.set_sector_address(0x0000, 0x001D); |
mbalourdas9 | 1:1d5055ca2793 | 279 | uLCD.display_image(0,0); |
mbalourdas9 | 1:1d5055ca2793 | 280 | FILE *wave_file; |
mbalourdas9 | 1:1d5055ca2793 | 281 | wave_file=fopen("/sd/sounds/wrong_last.wav","r"); |
mbalourdas9 | 1:1d5055ca2793 | 282 | waver.play(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 283 | fclose(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 284 | wait(1); |
mbalourdas9 | 1:1d5055ca2793 | 285 | uLCD.cls(); |
mbalourdas9 | 3:9842b3f1d809 | 286 | if (mode == 1){ |
mbalourdas9 | 1:1d5055ca2793 | 287 | answer = 0; |
mbalourdas9 | 3:9842b3f1d809 | 288 | } |
mbalourdas9 | 3:9842b3f1d809 | 289 | counter = counter +1; |
mbalourdas9 | 3:9842b3f1d809 | 290 | |
mbalourdas9 | 1:1d5055ca2793 | 291 | check = 1; |
mbalourdas9 | 1:1d5055ca2793 | 292 | } |
mbalourdas9 | 3:9842b3f1d809 | 293 | if (value == 4){ |
mbalourdas9 | 1:1d5055ca2793 | 294 | //play correct image |
mbalourdas9 | 1:1d5055ca2793 | 295 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 296 | uLCD.media_init(); |
mbalourdas9 | 1:1d5055ca2793 | 297 | uLCD.set_sector_address(0x0000, 0x005E); |
mbalourdas9 | 1:1d5055ca2793 | 298 | uLCD.display_image(0,0); |
mbalourdas9 | 1:1d5055ca2793 | 299 | FILE *wave_file; |
mbalourdas9 | 1:1d5055ca2793 | 300 | wave_file=fopen("/sd/sounds/right_taught.wav","r"); |
mbalourdas9 | 1:1d5055ca2793 | 301 | waver.play(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 302 | fclose(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 303 | wait(1); |
mbalourdas9 | 1:1d5055ca2793 | 304 | uLCD.cls(); |
mbalourdas9 | 3:9842b3f1d809 | 305 | if (mode == 1){ |
mbalourdas9 | 3:9842b3f1d809 | 306 | nScore = nScore+1; |
mbalourdas9 | 3:9842b3f1d809 | 307 | } |
mbalourdas9 | 3:9842b3f1d809 | 308 | if (mode == 2){ |
mbalourdas9 | 3:9842b3f1d809 | 309 | tScore = tScore+1; |
mbalourdas9 | 3:9842b3f1d809 | 310 | } |
mbalourdas9 | 3:9842b3f1d809 | 311 | if (mode == 4){ |
mbalourdas9 | 3:9842b3f1d809 | 312 | cScore = cScore+1; |
mbalourdas9 | 3:9842b3f1d809 | 313 | } |
mbalourdas9 | 3:9842b3f1d809 | 314 | //uLCD.printf("Score: %d", Score); |
mbalourdas9 | 1:1d5055ca2793 | 315 | wait(1); |
mbalourdas9 | 3:9842b3f1d809 | 316 | if (mode == 1){ |
mbalourdas9 | 1:1d5055ca2793 | 317 | answer = 1; |
mbalourdas9 | 3:9842b3f1d809 | 318 | } |
mbalourdas9 | 3:9842b3f1d809 | 319 | counter=counter+1; |
mbalourdas9 | 1:1d5055ca2793 | 320 | check = 1; |
mbalourdas9 | 1:1d5055ca2793 | 321 | } |
mbalourdas9 | 1:1d5055ca2793 | 322 | if (value == 8){ |
mbalourdas9 | 1:1d5055ca2793 | 323 | //play game over |
mbalourdas9 | 1:1d5055ca2793 | 324 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 325 | uLCD.media_init(); |
mbalourdas9 | 3:9842b3f1d809 | 326 | uLCD.set_sector_address(0x0000, 0x001D); |
mbalourdas9 | 1:1d5055ca2793 | 327 | uLCD.display_image(0,0); |
mbalourdas9 | 1:1d5055ca2793 | 328 | FILE *wave_file; |
mbalourdas9 | 1:1d5055ca2793 | 329 | wave_file=fopen("/sd/sounds/wrong_last.wav","r"); |
mbalourdas9 | 1:1d5055ca2793 | 330 | waver.play(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 331 | fclose(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 332 | wait(1); |
mbalourdas9 | 1:1d5055ca2793 | 333 | uLCD.cls(); |
mbalourdas9 | 3:9842b3f1d809 | 334 | if (mode == 1){ |
mbalourdas9 | 1:1d5055ca2793 | 335 | answer = 0; |
mbalourdas9 | 3:9842b3f1d809 | 336 | } |
mbalourdas9 | 3:9842b3f1d809 | 337 | counter = counter+1; |
mbalourdas9 | 1:1d5055ca2793 | 338 | check = 1; |
mbalourdas9 | 3:9842b3f1d809 | 339 | } |
mbalourdas9 | 3:9842b3f1d809 | 340 | } |
mbalourdas9 | 3:9842b3f1d809 | 341 | } |
mbalourdas9 | 1:1d5055ca2793 | 342 | if (question == 3){ |
mbalourdas9 | 1:1d5055ca2793 | 343 | value = 0; |
mbalourdas9 | 1:1d5055ca2793 | 344 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 345 | uLCD.locate(1,2); |
mbalourdas9 | 1:1d5055ca2793 | 346 | uLCD.printf("Who wrote The \nGrapes of Wrath?\n\n\n"); |
mbalourdas9 | 1:1d5055ca2793 | 347 | uLCD.printf("1)Ernest Hemingway"); |
mbalourdas9 | 1:1d5055ca2793 | 348 | uLCD.printf("2)George Orwell\n"); |
mbalourdas9 | 1:1d5055ca2793 | 349 | uLCD.printf("3)John Steinbeck\n"); |
mbalourdas9 | 1:1d5055ca2793 | 350 | while (check == 0){ |
mbalourdas9 | 1:1d5055ca2793 | 351 | int value=mpr121.read(0x00); |
mbalourdas9 | 1:1d5055ca2793 | 352 | value +=mpr121.read(0x01)<<8; |
mbalourdas9 | 1:1d5055ca2793 | 353 | if (value == 2){ |
mbalourdas9 | 1:1d5055ca2793 | 354 | //play game over |
mbalourdas9 | 1:1d5055ca2793 | 355 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 356 | uLCD.media_init(); |
mbalourdas9 | 3:9842b3f1d809 | 357 | uLCD.set_sector_address(0x0000, 0x001D); |
mbalourdas9 | 1:1d5055ca2793 | 358 | uLCD.display_image(0,0); |
mbalourdas9 | 1:1d5055ca2793 | 359 | FILE *wave_file; |
mbalourdas9 | 1:1d5055ca2793 | 360 | wave_file=fopen("/sd/sounds/wrong_last.wav","r"); |
mbalourdas9 | 1:1d5055ca2793 | 361 | waver.play(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 362 | fclose(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 363 | wait(1); |
mbalourdas9 | 1:1d5055ca2793 | 364 | uLCD.cls(); |
mbalourdas9 | 3:9842b3f1d809 | 365 | if (mode == 1){ |
mbalourdas9 | 1:1d5055ca2793 | 366 | answer = 0; |
mbalourdas9 | 3:9842b3f1d809 | 367 | } |
mbalourdas9 | 3:9842b3f1d809 | 368 | counter = counter +1; |
mbalourdas9 | 3:9842b3f1d809 | 369 | |
mbalourdas9 | 1:1d5055ca2793 | 370 | check = 1; |
mbalourdas9 | 1:1d5055ca2793 | 371 | } |
mbalourdas9 | 1:1d5055ca2793 | 372 | if (value == 8){ |
mbalourdas9 | 1:1d5055ca2793 | 373 | //play correct image |
mbalourdas9 | 1:1d5055ca2793 | 374 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 375 | uLCD.media_init(); |
mbalourdas9 | 1:1d5055ca2793 | 376 | uLCD.set_sector_address(0x0000, 0x005E); |
mbalourdas9 | 1:1d5055ca2793 | 377 | uLCD.display_image(0,0); |
mbalourdas9 | 1:1d5055ca2793 | 378 | FILE *wave_file; |
mbalourdas9 | 1:1d5055ca2793 | 379 | wave_file=fopen("/sd/sounds/right_taught.wav","r"); |
mbalourdas9 | 1:1d5055ca2793 | 380 | waver.play(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 381 | fclose(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 382 | wait(1); |
mbalourdas9 | 1:1d5055ca2793 | 383 | uLCD.cls(); |
mbalourdas9 | 3:9842b3f1d809 | 384 | if (mode == 1){ |
mbalourdas9 | 3:9842b3f1d809 | 385 | nScore = nScore+1; |
mbalourdas9 | 3:9842b3f1d809 | 386 | } |
mbalourdas9 | 3:9842b3f1d809 | 387 | if (mode == 2){ |
mbalourdas9 | 3:9842b3f1d809 | 388 | tScore = tScore+1; |
mbalourdas9 | 3:9842b3f1d809 | 389 | } |
mbalourdas9 | 3:9842b3f1d809 | 390 | if (mode == 4){ |
mbalourdas9 | 3:9842b3f1d809 | 391 | cScore = cScore+1; |
mbalourdas9 | 3:9842b3f1d809 | 392 | } |
mbalourdas9 | 3:9842b3f1d809 | 393 | //uLCD.printf("Score: %d", Score); |
mbalourdas9 | 1:1d5055ca2793 | 394 | wait(1); |
mbalourdas9 | 3:9842b3f1d809 | 395 | if (mode == 1){ |
mbalourdas9 | 1:1d5055ca2793 | 396 | answer = 1; |
mbalourdas9 | 3:9842b3f1d809 | 397 | } |
mbalourdas9 | 3:9842b3f1d809 | 398 | counter=counter+1; |
mbalourdas9 | 1:1d5055ca2793 | 399 | check = 1; |
mbalourdas9 | 1:1d5055ca2793 | 400 | } |
mbalourdas9 | 1:1d5055ca2793 | 401 | if (value == 4){ |
mbalourdas9 | 1:1d5055ca2793 | 402 | //play game over |
mbalourdas9 | 1:1d5055ca2793 | 403 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 404 | uLCD.media_init(); |
mbalourdas9 | 3:9842b3f1d809 | 405 | uLCD.set_sector_address(0x0000, 0x001D); |
mbalourdas9 | 1:1d5055ca2793 | 406 | uLCD.display_image(0,0); |
mbalourdas9 | 1:1d5055ca2793 | 407 | FILE *wave_file; |
mbalourdas9 | 1:1d5055ca2793 | 408 | wave_file=fopen("/sd/sounds/wrong_last.wav","r"); |
mbalourdas9 | 1:1d5055ca2793 | 409 | waver.play(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 410 | fclose(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 411 | wait(1); |
mbalourdas9 | 1:1d5055ca2793 | 412 | uLCD.cls(); |
mbalourdas9 | 3:9842b3f1d809 | 413 | if (mode == 1){ |
mbalourdas9 | 1:1d5055ca2793 | 414 | answer = 0; |
mbalourdas9 | 3:9842b3f1d809 | 415 | } |
mbalourdas9 | 3:9842b3f1d809 | 416 | counter = counter+1; |
mbalourdas9 | 1:1d5055ca2793 | 417 | check = 1; |
mbalourdas9 | 1:1d5055ca2793 | 418 | } |
mbalourdas9 | 1:1d5055ca2793 | 419 | } |
mbalourdas9 | 1:1d5055ca2793 | 420 | } |
mbalourdas9 | 1:1d5055ca2793 | 421 | if (question == 4){ |
mbalourdas9 | 1:1d5055ca2793 | 422 | value = 0; |
mbalourdas9 | 1:1d5055ca2793 | 423 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 424 | uLCD.locate(1,2); |
mbalourdas9 | 1:1d5055ca2793 | 425 | uLCD.printf("What year was \nEinstein born?\n\n\n"); |
mbalourdas9 | 1:1d5055ca2793 | 426 | uLCD.printf("1) 1900\n"); |
mbalourdas9 | 1:1d5055ca2793 | 427 | uLCD.printf("2) 1879\n"); |
mbalourdas9 | 1:1d5055ca2793 | 428 | uLCD.printf("3) 1873\n"); |
mbalourdas9 | 1:1d5055ca2793 | 429 | while (check == 0){ |
mbalourdas9 | 1:1d5055ca2793 | 430 | int value=mpr121.read(0x00); |
mbalourdas9 | 1:1d5055ca2793 | 431 | value +=mpr121.read(0x01)<<8; |
mbalourdas9 | 1:1d5055ca2793 | 432 | if (value == 2){ |
mbalourdas9 | 1:1d5055ca2793 | 433 | //play game over |
mbalourdas9 | 1:1d5055ca2793 | 434 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 435 | uLCD.media_init(); |
mbalourdas9 | 3:9842b3f1d809 | 436 | uLCD.set_sector_address(0x0000, 0x001D); |
mbalourdas9 | 1:1d5055ca2793 | 437 | uLCD.display_image(0,0); |
mbalourdas9 | 1:1d5055ca2793 | 438 | FILE *wave_file; |
mbalourdas9 | 1:1d5055ca2793 | 439 | wave_file=fopen("/sd/sounds/wrong_last.wav","r"); |
mbalourdas9 | 1:1d5055ca2793 | 440 | waver.play(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 441 | fclose(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 442 | wait(1); |
mbalourdas9 | 1:1d5055ca2793 | 443 | uLCD.cls(); |
mbalourdas9 | 3:9842b3f1d809 | 444 | if (mode == 1){ |
mbalourdas9 | 1:1d5055ca2793 | 445 | answer = 0; |
mbalourdas9 | 3:9842b3f1d809 | 446 | } |
mbalourdas9 | 3:9842b3f1d809 | 447 | counter = counter +1; |
mbalourdas9 | 3:9842b3f1d809 | 448 | |
mbalourdas9 | 1:1d5055ca2793 | 449 | check = 1; |
mbalourdas9 | 1:1d5055ca2793 | 450 | } |
mbalourdas9 | 1:1d5055ca2793 | 451 | if (value == 4){ |
mbalourdas9 | 1:1d5055ca2793 | 452 | //play correct image |
mbalourdas9 | 1:1d5055ca2793 | 453 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 454 | uLCD.media_init(); |
mbalourdas9 | 1:1d5055ca2793 | 455 | uLCD.set_sector_address(0x0000, 0x005E); |
mbalourdas9 | 1:1d5055ca2793 | 456 | uLCD.display_image(0,0); |
mbalourdas9 | 1:1d5055ca2793 | 457 | FILE *wave_file; |
mbalourdas9 | 1:1d5055ca2793 | 458 | wave_file=fopen("/sd/sounds/right_taught.wav","r"); |
mbalourdas9 | 1:1d5055ca2793 | 459 | waver.play(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 460 | fclose(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 461 | wait(1); |
mbalourdas9 | 1:1d5055ca2793 | 462 | uLCD.cls(); |
mbalourdas9 | 3:9842b3f1d809 | 463 | if (mode == 1){ |
mbalourdas9 | 3:9842b3f1d809 | 464 | nScore = nScore+1; |
mbalourdas9 | 3:9842b3f1d809 | 465 | } |
mbalourdas9 | 3:9842b3f1d809 | 466 | if (mode == 2){ |
mbalourdas9 | 3:9842b3f1d809 | 467 | tScore = tScore+1; |
mbalourdas9 | 3:9842b3f1d809 | 468 | } |
mbalourdas9 | 3:9842b3f1d809 | 469 | if (mode == 4){ |
mbalourdas9 | 3:9842b3f1d809 | 470 | cScore = cScore+1; |
mbalourdas9 | 3:9842b3f1d809 | 471 | } |
mbalourdas9 | 3:9842b3f1d809 | 472 | //uLCD.printf("Score: %d", Score); |
mbalourdas9 | 1:1d5055ca2793 | 473 | wait(1); |
mbalourdas9 | 3:9842b3f1d809 | 474 | if (mode == 1){ |
mbalourdas9 | 1:1d5055ca2793 | 475 | answer = 1; |
mbalourdas9 | 3:9842b3f1d809 | 476 | } |
mbalourdas9 | 3:9842b3f1d809 | 477 | counter=counter+1; |
mbalourdas9 | 1:1d5055ca2793 | 478 | check = 1; |
mbalourdas9 | 1:1d5055ca2793 | 479 | } |
mbalourdas9 | 1:1d5055ca2793 | 480 | if (value == 8){ |
mbalourdas9 | 1:1d5055ca2793 | 481 | //play game over |
mbalourdas9 | 1:1d5055ca2793 | 482 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 483 | uLCD.media_init(); |
mbalourdas9 | 3:9842b3f1d809 | 484 | uLCD.set_sector_address(0x0000, 0x001D); |
mbalourdas9 | 1:1d5055ca2793 | 485 | uLCD.display_image(0,0); |
mbalourdas9 | 1:1d5055ca2793 | 486 | FILE *wave_file; |
mbalourdas9 | 1:1d5055ca2793 | 487 | wave_file=fopen("/sd/sounds/wrong_last.wav","r"); |
mbalourdas9 | 1:1d5055ca2793 | 488 | waver.play(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 489 | fclose(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 490 | wait(1); |
mbalourdas9 | 1:1d5055ca2793 | 491 | uLCD.cls(); |
mbalourdas9 | 3:9842b3f1d809 | 492 | if (mode == 1){ |
mbalourdas9 | 1:1d5055ca2793 | 493 | answer = 0; |
mbalourdas9 | 3:9842b3f1d809 | 494 | } |
mbalourdas9 | 3:9842b3f1d809 | 495 | counter = counter+1; |
mbalourdas9 | 1:1d5055ca2793 | 496 | check = 1; |
mbalourdas9 | 1:1d5055ca2793 | 497 | } |
mbalourdas9 | 1:1d5055ca2793 | 498 | } |
mbalourdas9 | 1:1d5055ca2793 | 499 | } |
mbalourdas9 | 1:1d5055ca2793 | 500 | if (question == 5){ |
mbalourdas9 | 1:1d5055ca2793 | 501 | value = 0; |
mbalourdas9 | 1:1d5055ca2793 | 502 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 503 | uLCD.locate(1,2); |
mbalourdas9 | 1:1d5055ca2793 | 504 | uLCD.printf("Which song is by the Rolling Stones?\n\n\n"); |
mbalourdas9 | 1:1d5055ca2793 | 505 | uLCD.printf("1) Paint It Black\n"); |
mbalourdas9 | 1:1d5055ca2793 | 506 | uLCD.printf("2) Feel For \nThe Devil\n"); |
mbalourdas9 | 1:1d5055ca2793 | 507 | uLCD.printf("3) Let It Be\n"); |
mbalourdas9 | 1:1d5055ca2793 | 508 | while (check == 0){ |
mbalourdas9 | 1:1d5055ca2793 | 509 | int value=mpr121.read(0x00); |
mbalourdas9 | 1:1d5055ca2793 | 510 | value +=mpr121.read(0x01)<<8; |
mbalourdas9 | 1:1d5055ca2793 | 511 | if (value == 4){ |
mbalourdas9 | 1:1d5055ca2793 | 512 | //play game over |
mbalourdas9 | 1:1d5055ca2793 | 513 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 514 | uLCD.media_init(); |
mbalourdas9 | 3:9842b3f1d809 | 515 | uLCD.set_sector_address(0x0000, 0x001D); |
mbalourdas9 | 1:1d5055ca2793 | 516 | uLCD.display_image(0,0); |
mbalourdas9 | 1:1d5055ca2793 | 517 | FILE *wave_file; |
mbalourdas9 | 1:1d5055ca2793 | 518 | wave_file=fopen("/sd/sounds/wrong_last.wav","r"); |
mbalourdas9 | 1:1d5055ca2793 | 519 | waver.play(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 520 | fclose(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 521 | wait(1); |
mbalourdas9 | 1:1d5055ca2793 | 522 | uLCD.cls(); |
mbalourdas9 | 3:9842b3f1d809 | 523 | if (mode == 1){ |
mbalourdas9 | 1:1d5055ca2793 | 524 | answer = 0; |
mbalourdas9 | 3:9842b3f1d809 | 525 | } |
mbalourdas9 | 3:9842b3f1d809 | 526 | counter = counter +1; |
mbalourdas9 | 3:9842b3f1d809 | 527 | |
mbalourdas9 | 1:1d5055ca2793 | 528 | check = 1; |
mbalourdas9 | 1:1d5055ca2793 | 529 | } |
mbalourdas9 | 1:1d5055ca2793 | 530 | if (value == 2){ |
mbalourdas9 | 1:1d5055ca2793 | 531 | //play correct image |
mbalourdas9 | 1:1d5055ca2793 | 532 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 533 | uLCD.media_init(); |
mbalourdas9 | 1:1d5055ca2793 | 534 | uLCD.set_sector_address(0x0000, 0x005E); |
mbalourdas9 | 1:1d5055ca2793 | 535 | uLCD.display_image(0,0); |
mbalourdas9 | 1:1d5055ca2793 | 536 | FILE *wave_file; |
mbalourdas9 | 1:1d5055ca2793 | 537 | wave_file=fopen("/sd/sounds/right_taught.wav","r"); |
mbalourdas9 | 1:1d5055ca2793 | 538 | waver.play(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 539 | fclose(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 540 | wait(1); |
mbalourdas9 | 1:1d5055ca2793 | 541 | uLCD.cls(); |
mbalourdas9 | 3:9842b3f1d809 | 542 | if (mode == 1){ |
mbalourdas9 | 3:9842b3f1d809 | 543 | nScore = nScore+1; |
mbalourdas9 | 3:9842b3f1d809 | 544 | } |
mbalourdas9 | 3:9842b3f1d809 | 545 | if (mode == 2){ |
mbalourdas9 | 3:9842b3f1d809 | 546 | tScore = tScore+1; |
mbalourdas9 | 3:9842b3f1d809 | 547 | } |
mbalourdas9 | 3:9842b3f1d809 | 548 | if (mode == 4){ |
mbalourdas9 | 3:9842b3f1d809 | 549 | cScore = cScore+1; |
mbalourdas9 | 3:9842b3f1d809 | 550 | } |
mbalourdas9 | 3:9842b3f1d809 | 551 | //uLCD.printf("Score: %d", Score); |
mbalourdas9 | 1:1d5055ca2793 | 552 | wait(1); |
mbalourdas9 | 3:9842b3f1d809 | 553 | if (mode == 1){ |
mbalourdas9 | 1:1d5055ca2793 | 554 | answer = 1; |
mbalourdas9 | 3:9842b3f1d809 | 555 | } |
mbalourdas9 | 3:9842b3f1d809 | 556 | counter=counter+1; |
mbalourdas9 | 1:1d5055ca2793 | 557 | check = 1; |
mbalourdas9 | 1:1d5055ca2793 | 558 | } |
mbalourdas9 | 1:1d5055ca2793 | 559 | if (value == 8){ |
mbalourdas9 | 1:1d5055ca2793 | 560 | //play game over |
mbalourdas9 | 1:1d5055ca2793 | 561 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 562 | uLCD.media_init(); |
mbalourdas9 | 3:9842b3f1d809 | 563 | uLCD.set_sector_address(0x0000, 0x001D); |
mbalourdas9 | 1:1d5055ca2793 | 564 | uLCD.display_image(0,0); |
mbalourdas9 | 1:1d5055ca2793 | 565 | FILE *wave_file; |
mbalourdas9 | 1:1d5055ca2793 | 566 | wave_file=fopen("/sd/sounds/wrong_last.wav","r"); |
mbalourdas9 | 1:1d5055ca2793 | 567 | waver.play(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 568 | fclose(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 569 | wait(1); |
mbalourdas9 | 1:1d5055ca2793 | 570 | uLCD.cls(); |
mbalourdas9 | 3:9842b3f1d809 | 571 | if (mode == 1){ |
mbalourdas9 | 1:1d5055ca2793 | 572 | answer = 0; |
mbalourdas9 | 3:9842b3f1d809 | 573 | } |
mbalourdas9 | 3:9842b3f1d809 | 574 | counter = counter+1; |
mbalourdas9 | 1:1d5055ca2793 | 575 | check = 1; |
mbalourdas9 | 1:1d5055ca2793 | 576 | } |
mbalourdas9 | 1:1d5055ca2793 | 577 | } |
mbalourdas9 | 1:1d5055ca2793 | 578 | } |
mbalourdas9 | 1:1d5055ca2793 | 579 | if (question == 6){ |
mbalourdas9 | 1:1d5055ca2793 | 580 | value = 0; |
mbalourdas9 | 1:1d5055ca2793 | 581 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 582 | uLCD.locate(1,2); |
mbalourdas9 | 1:1d5055ca2793 | 583 | uLCD.printf("Where was Hitler born?\n\n\n"); |
mbalourdas9 | 1:1d5055ca2793 | 584 | uLCD.printf("1) Poland\n"); |
mbalourdas9 | 1:1d5055ca2793 | 585 | uLCD.printf("2) Germany\n"); |
mbalourdas9 | 1:1d5055ca2793 | 586 | uLCD.printf("3) Austria\n"); |
mbalourdas9 | 1:1d5055ca2793 | 587 | while (check == 0){ |
mbalourdas9 | 1:1d5055ca2793 | 588 | int value=mpr121.read(0x00); |
mbalourdas9 | 1:1d5055ca2793 | 589 | value +=mpr121.read(0x01)<<8; |
mbalourdas9 | 3:9842b3f1d809 | 590 | if (value == 2){ |
mbalourdas9 | 1:1d5055ca2793 | 591 | //play game over |
mbalourdas9 | 1:1d5055ca2793 | 592 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 593 | uLCD.media_init(); |
mbalourdas9 | 3:9842b3f1d809 | 594 | uLCD.set_sector_address(0x0000, 0x001D); |
mbalourdas9 | 1:1d5055ca2793 | 595 | uLCD.display_image(0,0); |
mbalourdas9 | 1:1d5055ca2793 | 596 | FILE *wave_file; |
mbalourdas9 | 1:1d5055ca2793 | 597 | wave_file=fopen("/sd/sounds/wrong_last.wav","r"); |
mbalourdas9 | 1:1d5055ca2793 | 598 | waver.play(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 599 | fclose(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 600 | wait(1); |
mbalourdas9 | 1:1d5055ca2793 | 601 | uLCD.cls(); |
mbalourdas9 | 3:9842b3f1d809 | 602 | if (mode == 1){ |
mbalourdas9 | 1:1d5055ca2793 | 603 | answer = 0; |
mbalourdas9 | 3:9842b3f1d809 | 604 | } |
mbalourdas9 | 3:9842b3f1d809 | 605 | counter = counter +1; |
mbalourdas9 | 3:9842b3f1d809 | 606 | |
mbalourdas9 | 1:1d5055ca2793 | 607 | check = 1; |
mbalourdas9 | 1:1d5055ca2793 | 608 | } |
mbalourdas9 | 1:1d5055ca2793 | 609 | if (value == 8){ |
mbalourdas9 | 1:1d5055ca2793 | 610 | //play correct image |
mbalourdas9 | 1:1d5055ca2793 | 611 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 612 | uLCD.media_init(); |
mbalourdas9 | 1:1d5055ca2793 | 613 | uLCD.set_sector_address(0x0000, 0x005E); |
mbalourdas9 | 1:1d5055ca2793 | 614 | uLCD.display_image(0,0); |
mbalourdas9 | 1:1d5055ca2793 | 615 | FILE *wave_file; |
mbalourdas9 | 1:1d5055ca2793 | 616 | wave_file=fopen("/sd/sounds/right_taught.wav","r"); |
mbalourdas9 | 1:1d5055ca2793 | 617 | waver.play(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 618 | fclose(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 619 | wait(1); |
mbalourdas9 | 1:1d5055ca2793 | 620 | uLCD.cls(); |
mbalourdas9 | 3:9842b3f1d809 | 621 | if (mode == 1){ |
mbalourdas9 | 3:9842b3f1d809 | 622 | nScore = nScore+1; |
mbalourdas9 | 3:9842b3f1d809 | 623 | } |
mbalourdas9 | 3:9842b3f1d809 | 624 | if (mode == 2){ |
mbalourdas9 | 3:9842b3f1d809 | 625 | tScore = tScore+1; |
mbalourdas9 | 3:9842b3f1d809 | 626 | } |
mbalourdas9 | 3:9842b3f1d809 | 627 | if (mode == 4){ |
mbalourdas9 | 3:9842b3f1d809 | 628 | cScore = cScore+1; |
mbalourdas9 | 3:9842b3f1d809 | 629 | } |
mbalourdas9 | 3:9842b3f1d809 | 630 | //uLCD.printf("Score: %d", Score); |
mbalourdas9 | 1:1d5055ca2793 | 631 | wait(1); |
mbalourdas9 | 3:9842b3f1d809 | 632 | if (mode == 1){ |
mbalourdas9 | 1:1d5055ca2793 | 633 | answer = 1; |
mbalourdas9 | 3:9842b3f1d809 | 634 | } |
mbalourdas9 | 3:9842b3f1d809 | 635 | counter=counter+1; |
mbalourdas9 | 1:1d5055ca2793 | 636 | check = 1; |
mbalourdas9 | 1:1d5055ca2793 | 637 | } |
mbalourdas9 | 3:9842b3f1d809 | 638 | if (value == 4){ |
mbalourdas9 | 1:1d5055ca2793 | 639 | //play game over |
mbalourdas9 | 1:1d5055ca2793 | 640 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 641 | uLCD.media_init(); |
mbalourdas9 | 3:9842b3f1d809 | 642 | uLCD.set_sector_address(0x0000, 0x001D); |
mbalourdas9 | 1:1d5055ca2793 | 643 | uLCD.display_image(0,0); |
mbalourdas9 | 1:1d5055ca2793 | 644 | FILE *wave_file; |
mbalourdas9 | 1:1d5055ca2793 | 645 | wave_file=fopen("/sd/sounds/wrong_last.wav","r"); |
mbalourdas9 | 1:1d5055ca2793 | 646 | waver.play(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 647 | fclose(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 648 | wait(1); |
mbalourdas9 | 1:1d5055ca2793 | 649 | uLCD.cls(); |
mbalourdas9 | 3:9842b3f1d809 | 650 | if (mode == 1){ |
mbalourdas9 | 1:1d5055ca2793 | 651 | answer = 0; |
mbalourdas9 | 3:9842b3f1d809 | 652 | } |
mbalourdas9 | 3:9842b3f1d809 | 653 | counter = counter+1; |
mbalourdas9 | 1:1d5055ca2793 | 654 | check = 1; |
mbalourdas9 | 1:1d5055ca2793 | 655 | } |
mbalourdas9 | 1:1d5055ca2793 | 656 | } |
mbalourdas9 | 1:1d5055ca2793 | 657 | } |
mbalourdas9 | 1:1d5055ca2793 | 658 | if (question == 7){ |
mbalourdas9 | 1:1d5055ca2793 | 659 | value = 0; |
mbalourdas9 | 1:1d5055ca2793 | 660 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 661 | uLCD.locate(1,2); |
mbalourdas9 | 1:1d5055ca2793 | 662 | uLCD.printf("The best selling\nmusic single of all time is?\n\n\n"); |
mbalourdas9 | 1:1d5055ca2793 | 663 | uLCD.printf("1) Billie Jean\n"); |
mbalourdas9 | 1:1d5055ca2793 | 664 | uLCD.printf("2) White Christmas\n"); |
mbalourdas9 | 1:1d5055ca2793 | 665 | uLCD.printf("3) Candle in the \nWind\n"); |
mbalourdas9 | 1:1d5055ca2793 | 666 | while (check == 0){ |
mbalourdas9 | 1:1d5055ca2793 | 667 | int value=mpr121.read(0x00); |
mbalourdas9 | 1:1d5055ca2793 | 668 | value +=mpr121.read(0x01)<<8; |
mbalourdas9 | 3:9842b3f1d809 | 669 | if (value == 2){ |
mbalourdas9 | 1:1d5055ca2793 | 670 | //play game over |
mbalourdas9 | 1:1d5055ca2793 | 671 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 672 | uLCD.media_init(); |
mbalourdas9 | 3:9842b3f1d809 | 673 | uLCD.set_sector_address(0x0000, 0x001D); |
mbalourdas9 | 1:1d5055ca2793 | 674 | uLCD.display_image(0,0); |
mbalourdas9 | 1:1d5055ca2793 | 675 | FILE *wave_file; |
mbalourdas9 | 1:1d5055ca2793 | 676 | wave_file=fopen("/sd/sounds/wrong_last.wav","r"); |
mbalourdas9 | 1:1d5055ca2793 | 677 | waver.play(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 678 | fclose(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 679 | wait(1); |
mbalourdas9 | 1:1d5055ca2793 | 680 | uLCD.cls(); |
mbalourdas9 | 3:9842b3f1d809 | 681 | if (mode == 1){ |
mbalourdas9 | 1:1d5055ca2793 | 682 | answer = 0; |
mbalourdas9 | 3:9842b3f1d809 | 683 | } |
mbalourdas9 | 3:9842b3f1d809 | 684 | counter = counter +1; |
mbalourdas9 | 3:9842b3f1d809 | 685 | |
mbalourdas9 | 1:1d5055ca2793 | 686 | check = 1; |
mbalourdas9 | 1:1d5055ca2793 | 687 | } |
mbalourdas9 | 1:1d5055ca2793 | 688 | if (value == 8){ |
mbalourdas9 | 1:1d5055ca2793 | 689 | //play correct image |
mbalourdas9 | 1:1d5055ca2793 | 690 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 691 | uLCD.media_init(); |
mbalourdas9 | 1:1d5055ca2793 | 692 | uLCD.set_sector_address(0x0000, 0x005E); |
mbalourdas9 | 1:1d5055ca2793 | 693 | uLCD.display_image(0,0); |
mbalourdas9 | 1:1d5055ca2793 | 694 | FILE *wave_file; |
mbalourdas9 | 1:1d5055ca2793 | 695 | wave_file=fopen("/sd/sounds/right_taught.wav","r"); |
mbalourdas9 | 1:1d5055ca2793 | 696 | waver.play(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 697 | fclose(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 698 | wait(1); |
mbalourdas9 | 1:1d5055ca2793 | 699 | uLCD.cls(); |
mbalourdas9 | 3:9842b3f1d809 | 700 | if (mode == 1){ |
mbalourdas9 | 3:9842b3f1d809 | 701 | nScore = nScore+1; |
mbalourdas9 | 3:9842b3f1d809 | 702 | } |
mbalourdas9 | 3:9842b3f1d809 | 703 | if (mode == 2){ |
mbalourdas9 | 3:9842b3f1d809 | 704 | tScore = tScore+1; |
mbalourdas9 | 3:9842b3f1d809 | 705 | } |
mbalourdas9 | 3:9842b3f1d809 | 706 | if (mode == 4){ |
mbalourdas9 | 3:9842b3f1d809 | 707 | cScore = cScore+1; |
mbalourdas9 | 3:9842b3f1d809 | 708 | } |
mbalourdas9 | 3:9842b3f1d809 | 709 | //uLCD.printf("Score: %d", Score); |
mbalourdas9 | 1:1d5055ca2793 | 710 | wait(1); |
mbalourdas9 | 3:9842b3f1d809 | 711 | if (mode == 1){ |
mbalourdas9 | 1:1d5055ca2793 | 712 | answer = 1; |
mbalourdas9 | 3:9842b3f1d809 | 713 | } |
mbalourdas9 | 3:9842b3f1d809 | 714 | counter=counter+1; |
mbalourdas9 | 1:1d5055ca2793 | 715 | check = 1; |
mbalourdas9 | 1:1d5055ca2793 | 716 | } |
mbalourdas9 | 3:9842b3f1d809 | 717 | if (value == 4){ |
mbalourdas9 | 1:1d5055ca2793 | 718 | //play game over |
mbalourdas9 | 1:1d5055ca2793 | 719 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 720 | uLCD.media_init(); |
mbalourdas9 | 3:9842b3f1d809 | 721 | uLCD.set_sector_address(0x0000, 0x001D); |
mbalourdas9 | 1:1d5055ca2793 | 722 | uLCD.display_image(0,0); |
mbalourdas9 | 1:1d5055ca2793 | 723 | FILE *wave_file; |
mbalourdas9 | 1:1d5055ca2793 | 724 | wave_file=fopen("/sd/sounds/wrong_last.wav","r"); |
mbalourdas9 | 1:1d5055ca2793 | 725 | waver.play(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 726 | fclose(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 727 | wait(1); |
mbalourdas9 | 1:1d5055ca2793 | 728 | uLCD.cls(); |
mbalourdas9 | 3:9842b3f1d809 | 729 | if (mode == 1){ |
mbalourdas9 | 1:1d5055ca2793 | 730 | answer = 0; |
mbalourdas9 | 3:9842b3f1d809 | 731 | } |
mbalourdas9 | 3:9842b3f1d809 | 732 | counter = counter+1; |
mbalourdas9 | 1:1d5055ca2793 | 733 | check = 1; |
mbalourdas9 | 1:1d5055ca2793 | 734 | } |
mbalourdas9 | 1:1d5055ca2793 | 735 | } |
mbalourdas9 | 1:1d5055ca2793 | 736 | } |
mbalourdas9 | 1:1d5055ca2793 | 737 | if (question == 8){ |
mbalourdas9 | 1:1d5055ca2793 | 738 | value = 0; |
mbalourdas9 | 1:1d5055ca2793 | 739 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 740 | uLCD.locate(1,2); |
mbalourdas9 | 1:1d5055ca2793 | 741 | uLCD.printf("What is the \ncurrency of \nJapan?\n\n\n"); |
mbalourdas9 | 1:1d5055ca2793 | 742 | uLCD.printf("1) Pounds\n"); |
mbalourdas9 | 1:1d5055ca2793 | 743 | uLCD.printf("2) Yen\n"); |
mbalourdas9 | 1:1d5055ca2793 | 744 | uLCD.printf("3) Riki\n"); |
mbalourdas9 | 1:1d5055ca2793 | 745 | while (check == 0){ |
mbalourdas9 | 1:1d5055ca2793 | 746 | int value=mpr121.read(0x00); |
mbalourdas9 | 1:1d5055ca2793 | 747 | value +=mpr121.read(0x01)<<8; |
mbalourdas9 | 1:1d5055ca2793 | 748 | if (value == 2){ |
mbalourdas9 | 1:1d5055ca2793 | 749 | //play game over |
mbalourdas9 | 1:1d5055ca2793 | 750 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 751 | uLCD.media_init(); |
mbalourdas9 | 3:9842b3f1d809 | 752 | uLCD.set_sector_address(0x0000, 0x001D); |
mbalourdas9 | 1:1d5055ca2793 | 753 | uLCD.display_image(0,0); |
mbalourdas9 | 1:1d5055ca2793 | 754 | FILE *wave_file; |
mbalourdas9 | 1:1d5055ca2793 | 755 | wave_file=fopen("/sd/sounds/wrong_last.wav","r"); |
mbalourdas9 | 1:1d5055ca2793 | 756 | waver.play(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 757 | fclose(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 758 | wait(1); |
mbalourdas9 | 1:1d5055ca2793 | 759 | uLCD.cls(); |
mbalourdas9 | 3:9842b3f1d809 | 760 | if (mode == 1){ |
mbalourdas9 | 1:1d5055ca2793 | 761 | answer = 0; |
mbalourdas9 | 3:9842b3f1d809 | 762 | } |
mbalourdas9 | 3:9842b3f1d809 | 763 | counter = counter +1; |
mbalourdas9 | 3:9842b3f1d809 | 764 | |
mbalourdas9 | 1:1d5055ca2793 | 765 | check = 1; |
mbalourdas9 | 1:1d5055ca2793 | 766 | } |
mbalourdas9 | 1:1d5055ca2793 | 767 | if (value == 4){ |
mbalourdas9 | 1:1d5055ca2793 | 768 | //play correct image |
mbalourdas9 | 1:1d5055ca2793 | 769 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 770 | uLCD.media_init(); |
mbalourdas9 | 1:1d5055ca2793 | 771 | uLCD.set_sector_address(0x0000, 0x005E); |
mbalourdas9 | 1:1d5055ca2793 | 772 | uLCD.display_image(0,0); |
mbalourdas9 | 1:1d5055ca2793 | 773 | FILE *wave_file; |
mbalourdas9 | 1:1d5055ca2793 | 774 | wave_file=fopen("/sd/sounds/right_taught.wav","r"); |
mbalourdas9 | 1:1d5055ca2793 | 775 | waver.play(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 776 | fclose(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 777 | wait(1); |
mbalourdas9 | 1:1d5055ca2793 | 778 | uLCD.cls(); |
mbalourdas9 | 3:9842b3f1d809 | 779 | if (mode == 1){ |
mbalourdas9 | 3:9842b3f1d809 | 780 | nScore = nScore+1; |
mbalourdas9 | 3:9842b3f1d809 | 781 | } |
mbalourdas9 | 3:9842b3f1d809 | 782 | if (mode == 2){ |
mbalourdas9 | 3:9842b3f1d809 | 783 | tScore = tScore+1; |
mbalourdas9 | 3:9842b3f1d809 | 784 | } |
mbalourdas9 | 3:9842b3f1d809 | 785 | if (mode == 4){ |
mbalourdas9 | 3:9842b3f1d809 | 786 | cScore = cScore+1; |
mbalourdas9 | 3:9842b3f1d809 | 787 | } |
mbalourdas9 | 3:9842b3f1d809 | 788 | //uLCD.printf("Score: %d", Score); |
mbalourdas9 | 1:1d5055ca2793 | 789 | wait(1); |
mbalourdas9 | 3:9842b3f1d809 | 790 | if (mode == 1){ |
mbalourdas9 | 1:1d5055ca2793 | 791 | answer = 1; |
mbalourdas9 | 3:9842b3f1d809 | 792 | } |
mbalourdas9 | 3:9842b3f1d809 | 793 | counter=counter+1; |
mbalourdas9 | 1:1d5055ca2793 | 794 | check = 1; |
mbalourdas9 | 1:1d5055ca2793 | 795 | } |
mbalourdas9 | 1:1d5055ca2793 | 796 | if (value == 8){ |
mbalourdas9 | 1:1d5055ca2793 | 797 | //play game over |
mbalourdas9 | 1:1d5055ca2793 | 798 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 799 | uLCD.media_init(); |
mbalourdas9 | 3:9842b3f1d809 | 800 | uLCD.set_sector_address(0x0000, 0x001D); |
mbalourdas9 | 1:1d5055ca2793 | 801 | uLCD.display_image(0,0); |
mbalourdas9 | 1:1d5055ca2793 | 802 | FILE *wave_file; |
mbalourdas9 | 1:1d5055ca2793 | 803 | wave_file=fopen("/sd/sounds/wrong_last.wav","r"); |
mbalourdas9 | 1:1d5055ca2793 | 804 | waver.play(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 805 | fclose(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 806 | wait(1); |
mbalourdas9 | 1:1d5055ca2793 | 807 | uLCD.cls(); |
mbalourdas9 | 3:9842b3f1d809 | 808 | if (mode == 1){ |
mbalourdas9 | 1:1d5055ca2793 | 809 | answer = 0; |
mbalourdas9 | 3:9842b3f1d809 | 810 | } |
mbalourdas9 | 3:9842b3f1d809 | 811 | counter = counter+1; |
mbalourdas9 | 1:1d5055ca2793 | 812 | check = 1; |
mbalourdas9 | 1:1d5055ca2793 | 813 | } |
mbalourdas9 | 1:1d5055ca2793 | 814 | } |
mbalourdas9 | 1:1d5055ca2793 | 815 | } |
mbalourdas9 | 1:1d5055ca2793 | 816 | if (question == 9){ |
mbalourdas9 | 1:1d5055ca2793 | 817 | value = 0; |
mbalourdas9 | 1:1d5055ca2793 | 818 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 819 | uLCD.locate(1,2); |
mbalourdas9 | 1:1d5055ca2793 | 820 | uLCD.printf("Who was Harry \nHoudini?\n\n\n"); |
mbalourdas9 | 1:1d5055ca2793 | 821 | uLCD.printf("1)An Escape Artist\n"); |
mbalourdas9 | 1:1d5055ca2793 | 822 | uLCD.printf("2)Fighter Pilot in WWII\n"); |
mbalourdas9 | 1:1d5055ca2793 | 823 | uLCD.printf("3) Harry Potter's Cousin\n"); |
mbalourdas9 | 1:1d5055ca2793 | 824 | while (check == 0){ |
mbalourdas9 | 1:1d5055ca2793 | 825 | int value=mpr121.read(0x00); |
mbalourdas9 | 1:1d5055ca2793 | 826 | value +=mpr121.read(0x01)<<8; |
mbalourdas9 | 1:1d5055ca2793 | 827 | if (value == 4){ |
mbalourdas9 | 1:1d5055ca2793 | 828 | //play game over |
mbalourdas9 | 1:1d5055ca2793 | 829 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 830 | uLCD.media_init(); |
mbalourdas9 | 3:9842b3f1d809 | 831 | uLCD.set_sector_address(0x0000, 0x001D); |
mbalourdas9 | 1:1d5055ca2793 | 832 | uLCD.display_image(0,0); |
mbalourdas9 | 1:1d5055ca2793 | 833 | FILE *wave_file; |
mbalourdas9 | 1:1d5055ca2793 | 834 | wave_file=fopen("/sd/sounds/wrong_last.wav","r"); |
mbalourdas9 | 1:1d5055ca2793 | 835 | waver.play(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 836 | fclose(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 837 | wait(1); |
mbalourdas9 | 1:1d5055ca2793 | 838 | uLCD.cls(); |
mbalourdas9 | 3:9842b3f1d809 | 839 | if (mode == 1){ |
mbalourdas9 | 1:1d5055ca2793 | 840 | answer = 0; |
mbalourdas9 | 3:9842b3f1d809 | 841 | } |
mbalourdas9 | 3:9842b3f1d809 | 842 | counter = counter +1; |
mbalourdas9 | 3:9842b3f1d809 | 843 | |
mbalourdas9 | 1:1d5055ca2793 | 844 | check = 1; |
mbalourdas9 | 1:1d5055ca2793 | 845 | } |
mbalourdas9 | 1:1d5055ca2793 | 846 | if (value == 2){ |
mbalourdas9 | 1:1d5055ca2793 | 847 | //play correct image |
mbalourdas9 | 1:1d5055ca2793 | 848 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 849 | uLCD.media_init(); |
mbalourdas9 | 1:1d5055ca2793 | 850 | uLCD.set_sector_address(0x0000, 0x005E); |
mbalourdas9 | 1:1d5055ca2793 | 851 | uLCD.display_image(0,0); |
mbalourdas9 | 1:1d5055ca2793 | 852 | FILE *wave_file; |
mbalourdas9 | 1:1d5055ca2793 | 853 | wave_file=fopen("/sd/sounds/right_taught.wav","r"); |
mbalourdas9 | 1:1d5055ca2793 | 854 | waver.play(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 855 | fclose(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 856 | wait(1); |
mbalourdas9 | 1:1d5055ca2793 | 857 | uLCD.cls(); |
mbalourdas9 | 3:9842b3f1d809 | 858 | if (mode == 1){ |
mbalourdas9 | 3:9842b3f1d809 | 859 | nScore = nScore+1; |
mbalourdas9 | 3:9842b3f1d809 | 860 | } |
mbalourdas9 | 3:9842b3f1d809 | 861 | if (mode == 2){ |
mbalourdas9 | 3:9842b3f1d809 | 862 | tScore = tScore+1; |
mbalourdas9 | 3:9842b3f1d809 | 863 | } |
mbalourdas9 | 3:9842b3f1d809 | 864 | if (mode == 4){ |
mbalourdas9 | 3:9842b3f1d809 | 865 | cScore = cScore+1; |
mbalourdas9 | 3:9842b3f1d809 | 866 | } |
mbalourdas9 | 3:9842b3f1d809 | 867 | //uLCD.printf("Score: %d", Score); |
mbalourdas9 | 1:1d5055ca2793 | 868 | wait(1); |
mbalourdas9 | 3:9842b3f1d809 | 869 | if (mode == 1){ |
mbalourdas9 | 1:1d5055ca2793 | 870 | answer = 1; |
mbalourdas9 | 3:9842b3f1d809 | 871 | } |
mbalourdas9 | 3:9842b3f1d809 | 872 | counter=counter+1; |
mbalourdas9 | 1:1d5055ca2793 | 873 | check = 1; |
mbalourdas9 | 1:1d5055ca2793 | 874 | } |
mbalourdas9 | 1:1d5055ca2793 | 875 | if (value == 8){ |
mbalourdas9 | 1:1d5055ca2793 | 876 | //play game over |
mbalourdas9 | 1:1d5055ca2793 | 877 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 878 | uLCD.media_init(); |
mbalourdas9 | 3:9842b3f1d809 | 879 | uLCD.set_sector_address(0x0000, 0x001D); |
mbalourdas9 | 1:1d5055ca2793 | 880 | uLCD.display_image(0,0); |
mbalourdas9 | 1:1d5055ca2793 | 881 | FILE *wave_file; |
mbalourdas9 | 1:1d5055ca2793 | 882 | wave_file=fopen("/sd/sounds/wrong_last.wav","r"); |
mbalourdas9 | 1:1d5055ca2793 | 883 | waver.play(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 884 | fclose(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 885 | wait(1); |
mbalourdas9 | 1:1d5055ca2793 | 886 | uLCD.cls(); |
mbalourdas9 | 3:9842b3f1d809 | 887 | if (mode == 1){ |
mbalourdas9 | 1:1d5055ca2793 | 888 | answer = 0; |
mbalourdas9 | 3:9842b3f1d809 | 889 | } |
mbalourdas9 | 3:9842b3f1d809 | 890 | counter = counter+1; |
mbalourdas9 | 1:1d5055ca2793 | 891 | check = 1; |
mbalourdas9 | 1:1d5055ca2793 | 892 | } |
mbalourdas9 | 1:1d5055ca2793 | 893 | } |
mbalourdas9 | 1:1d5055ca2793 | 894 | } |
mbalourdas9 | 1:1d5055ca2793 | 895 | if (question == 10){ |
mbalourdas9 | 1:1d5055ca2793 | 896 | value = 0; |
mbalourdas9 | 1:1d5055ca2793 | 897 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 898 | uLCD.locate(1,2); |
mbalourdas9 | 1:1d5055ca2793 | 899 | uLCD.printf("What is glass \nmainly made up \nof?\n\n\n"); |
mbalourdas9 | 1:1d5055ca2793 | 900 | uLCD.printf("1) Sand\n"); |
mbalourdas9 | 1:1d5055ca2793 | 901 | uLCD.printf("2) Crystals\n"); |
mbalourdas9 | 1:1d5055ca2793 | 902 | uLCD.printf("3) Highly \nCompressed \nWater\n"); |
mbalourdas9 | 1:1d5055ca2793 | 903 | while (check == 0){ |
mbalourdas9 | 1:1d5055ca2793 | 904 | int value=mpr121.read(0x00); |
mbalourdas9 | 1:1d5055ca2793 | 905 | value +=mpr121.read(0x01)<<8; |
mbalourdas9 | 1:1d5055ca2793 | 906 | if (value == 4){ |
mbalourdas9 | 1:1d5055ca2793 | 907 | //play game over |
mbalourdas9 | 1:1d5055ca2793 | 908 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 909 | uLCD.media_init(); |
mbalourdas9 | 3:9842b3f1d809 | 910 | uLCD.set_sector_address(0x0000, 0x001D); |
mbalourdas9 | 1:1d5055ca2793 | 911 | uLCD.display_image(0,0); |
mbalourdas9 | 1:1d5055ca2793 | 912 | FILE *wave_file; |
mbalourdas9 | 1:1d5055ca2793 | 913 | wave_file=fopen("/sd/sounds/wrong_last.wav","r"); |
mbalourdas9 | 1:1d5055ca2793 | 914 | waver.play(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 915 | fclose(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 916 | wait(1); |
mbalourdas9 | 1:1d5055ca2793 | 917 | uLCD.cls(); |
mbalourdas9 | 3:9842b3f1d809 | 918 | if (mode == 1){ |
mbalourdas9 | 1:1d5055ca2793 | 919 | answer = 0; |
mbalourdas9 | 3:9842b3f1d809 | 920 | } |
mbalourdas9 | 3:9842b3f1d809 | 921 | counter = counter +1; |
mbalourdas9 | 3:9842b3f1d809 | 922 | |
mbalourdas9 | 1:1d5055ca2793 | 923 | check = 1; |
mbalourdas9 | 1:1d5055ca2793 | 924 | } |
mbalourdas9 | 1:1d5055ca2793 | 925 | if (value == 2){ |
mbalourdas9 | 1:1d5055ca2793 | 926 | //play correct image |
mbalourdas9 | 1:1d5055ca2793 | 927 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 928 | uLCD.media_init(); |
mbalourdas9 | 1:1d5055ca2793 | 929 | uLCD.set_sector_address(0x0000, 0x005E); |
mbalourdas9 | 1:1d5055ca2793 | 930 | uLCD.display_image(0,0); |
mbalourdas9 | 1:1d5055ca2793 | 931 | FILE *wave_file; |
mbalourdas9 | 1:1d5055ca2793 | 932 | wave_file=fopen("/sd/sounds/right_taught.wav","r"); |
mbalourdas9 | 1:1d5055ca2793 | 933 | waver.play(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 934 | fclose(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 935 | wait(1); |
mbalourdas9 | 1:1d5055ca2793 | 936 | uLCD.cls(); |
mbalourdas9 | 3:9842b3f1d809 | 937 | if (mode == 1){ |
mbalourdas9 | 3:9842b3f1d809 | 938 | nScore = nScore+1; |
mbalourdas9 | 3:9842b3f1d809 | 939 | } |
mbalourdas9 | 3:9842b3f1d809 | 940 | if (mode == 2){ |
mbalourdas9 | 3:9842b3f1d809 | 941 | tScore = tScore+1; |
mbalourdas9 | 3:9842b3f1d809 | 942 | } |
mbalourdas9 | 3:9842b3f1d809 | 943 | if (mode == 4){ |
mbalourdas9 | 3:9842b3f1d809 | 944 | cScore = cScore+1; |
mbalourdas9 | 3:9842b3f1d809 | 945 | } |
mbalourdas9 | 3:9842b3f1d809 | 946 | //uLCD.printf("Score: %d", Score); |
mbalourdas9 | 1:1d5055ca2793 | 947 | wait(1); |
mbalourdas9 | 3:9842b3f1d809 | 948 | if (mode == 1){ |
mbalourdas9 | 1:1d5055ca2793 | 949 | answer = 1; |
mbalourdas9 | 3:9842b3f1d809 | 950 | } |
mbalourdas9 | 3:9842b3f1d809 | 951 | counter=counter+1; |
mbalourdas9 | 1:1d5055ca2793 | 952 | check = 1; |
mbalourdas9 | 1:1d5055ca2793 | 953 | } |
mbalourdas9 | 1:1d5055ca2793 | 954 | if (value == 8){ |
mbalourdas9 | 1:1d5055ca2793 | 955 | //play game over |
mbalourdas9 | 1:1d5055ca2793 | 956 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 957 | uLCD.media_init(); |
mbalourdas9 | 3:9842b3f1d809 | 958 | uLCD.set_sector_address(0x0000, 0x001D); |
mbalourdas9 | 1:1d5055ca2793 | 959 | uLCD.display_image(0,0); |
mbalourdas9 | 1:1d5055ca2793 | 960 | FILE *wave_file; |
mbalourdas9 | 1:1d5055ca2793 | 961 | wave_file=fopen("/sd/sounds/wrong_last.wav","r"); |
mbalourdas9 | 1:1d5055ca2793 | 962 | waver.play(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 963 | fclose(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 964 | wait(1); |
mbalourdas9 | 1:1d5055ca2793 | 965 | uLCD.cls(); |
mbalourdas9 | 3:9842b3f1d809 | 966 | if (mode == 1){ |
mbalourdas9 | 1:1d5055ca2793 | 967 | answer = 0; |
mbalourdas9 | 3:9842b3f1d809 | 968 | } |
mbalourdas9 | 3:9842b3f1d809 | 969 | counter = counter+1; |
mbalourdas9 | 1:1d5055ca2793 | 970 | check = 1; |
mbalourdas9 | 1:1d5055ca2793 | 971 | } |
mbalourdas9 | 1:1d5055ca2793 | 972 | } |
mbalourdas9 | 1:1d5055ca2793 | 973 | } |
mbalourdas9 | 1:1d5055ca2793 | 974 | } |
mbalourdas9 | 1:1d5055ca2793 | 975 | |
mbalourdas9 | 1:1d5055ca2793 | 976 | |
mbalourdas9 | 1:1d5055ca2793 | 977 | |
mbalourdas9 | 1:1d5055ca2793 | 978 | |
mbalourdas9 | 1:1d5055ca2793 | 979 | |
mbalourdas9 | 1:1d5055ca2793 | 980 | } |
mbalourdas9 | 1:1d5055ca2793 | 981 | else{ |
mbalourdas9 | 1:1d5055ca2793 | 982 | uLCD.printf("CONGRATS!"); |
mbalourdas9 | 1:1d5055ca2793 | 983 | wait(1); |
mbalourdas9 | 1:1d5055ca2793 | 984 | } |
mbalourdas9 | 1:1d5055ca2793 | 985 | |
mbalourdas9 | 1:1d5055ca2793 | 986 | } |
mbalourdas9 | 1:1d5055ca2793 | 987 | } |