f
Dependencies: 4DGL-uLCD-SE SDFileSystem mbed wave_player
Fork of MPR121_Demo by
main.cpp@1:1d5055ca2793, 2016-11-04 (annotated)
- Committer:
- mbalourdas9
- Date:
- Fri Nov 04 15:43:36 2016 +0000
- Revision:
- 1:1d5055ca2793
- Parent:
- 0:e09703934ff4
for publish
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> |
4180_1 | 0:e09703934ff4 | 7 | |
mbalourdas9 | 1:1d5055ca2793 | 8 | AnalogOut DACout(p18); // used to play sound on speaker |
mbalourdas9 | 1:1d5055ca2793 | 9 | //wave player plays a *.wav file to D/A and a PWM |
mbalourdas9 | 1:1d5055ca2793 | 10 | wave_player waver(&DACout); |
4180_1 | 0:e09703934ff4 | 11 | InterruptIn interrupt(p26); |
4180_1 | 0:e09703934ff4 | 12 | I2C i2c(p9, p10); |
4180_1 | 0:e09703934ff4 | 13 | Mpr121 mpr121(&i2c, Mpr121::ADD_VSS); |
4180_1 | 0:e09703934ff4 | 14 | |
mbalourdas9 | 1:1d5055ca2793 | 15 | uLCD_4DGL uLCD(p28,p27,p29); // serial tx, serial rx, reset pin; |
mbalourdas9 | 1:1d5055ca2793 | 16 | SDFileSystem sd(p5, p6, p7, p8, "sd"); //SD card setup |
mbalourdas9 | 1:1d5055ca2793 | 17 | int Score; |
mbalourdas9 | 1:1d5055ca2793 | 18 | int HighScore = 0; |
mbalourdas9 | 1:1d5055ca2793 | 19 | int question = 0; |
mbalourdas9 | 1:1d5055ca2793 | 20 | bool answer = 1; |
mbalourdas9 | 1:1d5055ca2793 | 21 | int index = 0; |
mbalourdas9 | 1:1d5055ca2793 | 22 | bool check = 0; |
mbalourdas9 | 1:1d5055ca2793 | 23 | int value = 0; |
mbalourdas9 | 1:1d5055ca2793 | 24 | std::vector<int> v; |
4180_1 | 0:e09703934ff4 | 25 | |
4180_1 | 0:e09703934ff4 | 26 | |
mbalourdas9 | 1:1d5055ca2793 | 27 | int main() |
mbalourdas9 | 1:1d5055ca2793 | 28 | { |
mbalourdas9 | 1:1d5055ca2793 | 29 | srand(time(NULL)); |
mbalourdas9 | 1:1d5055ca2793 | 30 | while (true){ |
mbalourdas9 | 1:1d5055ca2793 | 31 | answer = 1; |
mbalourdas9 | 1:1d5055ca2793 | 32 | for (int i=0; i<10; i++){ |
mbalourdas9 | 1:1d5055ca2793 | 33 | v.push_back(i+1); |
mbalourdas9 | 1:1d5055ca2793 | 34 | } |
mbalourdas9 | 1:1d5055ca2793 | 35 | check = 0; |
mbalourdas9 | 1:1d5055ca2793 | 36 | question = 0; |
mbalourdas9 | 1:1d5055ca2793 | 37 | uLCD.baudrate(3000000); |
mbalourdas9 | 1:1d5055ca2793 | 38 | uLCD.background_color(BLACK); |
mbalourdas9 | 1:1d5055ca2793 | 39 | uLCD.color(BLUE); |
mbalourdas9 | 1:1d5055ca2793 | 40 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 41 | if (Score > HighScore){ |
mbalourdas9 | 1:1d5055ca2793 | 42 | HighScore = Score; |
mbalourdas9 | 1:1d5055ca2793 | 43 | uLCD.printf("NEW HIGH SCORE!\n %d", HighScore); |
mbalourdas9 | 1:1d5055ca2793 | 44 | wait(2); |
mbalourdas9 | 1:1d5055ca2793 | 45 | } |
mbalourdas9 | 1:1d5055ca2793 | 46 | Score = 0; |
mbalourdas9 | 1:1d5055ca2793 | 47 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 48 | uLCD.printf("\nTrivia Game \n Main Menu\n\n"); |
mbalourdas9 | 1:1d5055ca2793 | 49 | uLCD.printf("High Score: %d \n", HighScore); |
mbalourdas9 | 1:1d5055ca2793 | 50 | uLCD.printf("\nFor New Game \n Press 0"); |
mbalourdas9 | 1:1d5055ca2793 | 51 | while (value != 1){ |
mbalourdas9 | 1:1d5055ca2793 | 52 | value=mpr121.read(0x00); |
mbalourdas9 | 1:1d5055ca2793 | 53 | value +=mpr121.read(0x01)<<8; |
mbalourdas9 | 1:1d5055ca2793 | 54 | } |
mbalourdas9 | 1:1d5055ca2793 | 55 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 56 | if (v.size() !=0){ |
mbalourdas9 | 1:1d5055ca2793 | 57 | while (answer == 1){ |
mbalourdas9 | 1:1d5055ca2793 | 58 | if (v.size() == 0){ |
mbalourdas9 | 1:1d5055ca2793 | 59 | break; |
mbalourdas9 | 1:1d5055ca2793 | 60 | } |
mbalourdas9 | 1:1d5055ca2793 | 61 | index = rand() %v.size(); |
mbalourdas9 | 1:1d5055ca2793 | 62 | question = v.at(index); |
mbalourdas9 | 1:1d5055ca2793 | 63 | v.erase(v.begin()+index); |
mbalourdas9 | 1:1d5055ca2793 | 64 | check = 0; |
mbalourdas9 | 1:1d5055ca2793 | 65 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 66 | wait(1); |
mbalourdas9 | 1:1d5055ca2793 | 67 | if (question == 1){ |
mbalourdas9 | 1:1d5055ca2793 | 68 | value = 0; |
mbalourdas9 | 1:1d5055ca2793 | 69 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 70 | uLCD.locate(1,2); |
mbalourdas9 | 1:1d5055ca2793 | 71 | uLCD.printf("Who won the World Series in 2016?\n\n\n"); |
mbalourdas9 | 1:1d5055ca2793 | 72 | uLCD.printf("1) Cleveland\nIndians\n"); |
mbalourdas9 | 1:1d5055ca2793 | 73 | uLCD.printf("2) Chicago Cubs\n"); |
mbalourdas9 | 1:1d5055ca2793 | 74 | uLCD.printf("3) San Diego\nPadres\n"); |
mbalourdas9 | 1:1d5055ca2793 | 75 | while (check == 0){ |
mbalourdas9 | 1:1d5055ca2793 | 76 | int value=mpr121.read(0x00); |
mbalourdas9 | 1:1d5055ca2793 | 77 | value +=mpr121.read(0x01)<<8; |
mbalourdas9 | 1:1d5055ca2793 | 78 | if (value == 2){ |
mbalourdas9 | 1:1d5055ca2793 | 79 | //play game over |
mbalourdas9 | 1:1d5055ca2793 | 80 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 81 | uLCD.media_init(); |
mbalourdas9 | 1:1d5055ca2793 | 82 | uLCD.set_sector_address(0x0000, 0x009F); |
mbalourdas9 | 1:1d5055ca2793 | 83 | uLCD.display_image(0,0); |
mbalourdas9 | 1:1d5055ca2793 | 84 | FILE *wave_file; |
mbalourdas9 | 1:1d5055ca2793 | 85 | wave_file=fopen("/sd/sounds/wrong_last.wav","r"); |
mbalourdas9 | 1:1d5055ca2793 | 86 | waver.play(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 87 | fclose(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 88 | wait(1); |
mbalourdas9 | 1:1d5055ca2793 | 89 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 90 | answer = 0; |
mbalourdas9 | 1:1d5055ca2793 | 91 | check = 1; |
mbalourdas9 | 1:1d5055ca2793 | 92 | } |
mbalourdas9 | 1:1d5055ca2793 | 93 | if (value == 4){ |
mbalourdas9 | 1:1d5055ca2793 | 94 | //play correct image |
mbalourdas9 | 1:1d5055ca2793 | 95 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 96 | uLCD.media_init(); |
mbalourdas9 | 1:1d5055ca2793 | 97 | uLCD.set_sector_address(0x0000, 0x005E); |
mbalourdas9 | 1:1d5055ca2793 | 98 | uLCD.display_image(0,0); |
mbalourdas9 | 1:1d5055ca2793 | 99 | FILE *wave_file; |
mbalourdas9 | 1:1d5055ca2793 | 100 | wave_file=fopen("/sd/sounds/right_taught.wav","r"); |
mbalourdas9 | 1:1d5055ca2793 | 101 | waver.play(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 102 | fclose(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 103 | wait(1); |
mbalourdas9 | 1:1d5055ca2793 | 104 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 105 | Score = Score+1; |
mbalourdas9 | 1:1d5055ca2793 | 106 | uLCD.printf("Score: %d", Score); |
mbalourdas9 | 1:1d5055ca2793 | 107 | wait(1); |
mbalourdas9 | 1:1d5055ca2793 | 108 | answer = 1; |
mbalourdas9 | 1:1d5055ca2793 | 109 | check = 1; |
mbalourdas9 | 1:1d5055ca2793 | 110 | } |
mbalourdas9 | 1:1d5055ca2793 | 111 | if (value == 8){ |
mbalourdas9 | 1:1d5055ca2793 | 112 | //play game over |
mbalourdas9 | 1:1d5055ca2793 | 113 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 114 | uLCD.media_init(); |
mbalourdas9 | 1:1d5055ca2793 | 115 | uLCD.set_sector_address(0x0000, 0x009F); |
mbalourdas9 | 1:1d5055ca2793 | 116 | uLCD.display_image(0,0); |
mbalourdas9 | 1:1d5055ca2793 | 117 | FILE *wave_file; |
mbalourdas9 | 1:1d5055ca2793 | 118 | wave_file=fopen("/sd/sounds/wrong_last.wav","r"); |
mbalourdas9 | 1:1d5055ca2793 | 119 | waver.play(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 120 | fclose(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 121 | wait(1); |
mbalourdas9 | 1:1d5055ca2793 | 122 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 123 | answer = 0; |
mbalourdas9 | 1:1d5055ca2793 | 124 | check = 1; |
mbalourdas9 | 1:1d5055ca2793 | 125 | } |
mbalourdas9 | 1:1d5055ca2793 | 126 | } |
mbalourdas9 | 1:1d5055ca2793 | 127 | } |
mbalourdas9 | 1:1d5055ca2793 | 128 | if (question == 2){ |
mbalourdas9 | 1:1d5055ca2793 | 129 | value = 0; |
mbalourdas9 | 1:1d5055ca2793 | 130 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 131 | uLCD.locate(1,2); |
mbalourdas9 | 1:1d5055ca2793 | 132 | uLCD.printf("What is the\n capital of South\n Dakota?\n\n"); |
mbalourdas9 | 1:1d5055ca2793 | 133 | uLCD.printf("1) Pierre\n"); |
mbalourdas9 | 1:1d5055ca2793 | 134 | uLCD.printf("2) Bismarck\n"); |
mbalourdas9 | 1:1d5055ca2793 | 135 | uLCD.printf("3) Lakota\n"); |
mbalourdas9 | 1:1d5055ca2793 | 136 | while (check == 0){ |
mbalourdas9 | 1:1d5055ca2793 | 137 | int value=mpr121.read(0x00); |
mbalourdas9 | 1:1d5055ca2793 | 138 | value +=mpr121.read(0x01)<<8; |
mbalourdas9 | 1:1d5055ca2793 | 139 | if (value == 4){ |
mbalourdas9 | 1:1d5055ca2793 | 140 | //play game over |
mbalourdas9 | 1:1d5055ca2793 | 141 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 142 | uLCD.media_init(); |
mbalourdas9 | 1:1d5055ca2793 | 143 | uLCD.set_sector_address(0x0000, 0x009F); |
mbalourdas9 | 1:1d5055ca2793 | 144 | uLCD.display_image(0,0); |
mbalourdas9 | 1:1d5055ca2793 | 145 | FILE *wave_file; |
mbalourdas9 | 1:1d5055ca2793 | 146 | wave_file=fopen("/sd/sounds/wrong_last.wav","r"); |
mbalourdas9 | 1:1d5055ca2793 | 147 | waver.play(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 148 | fclose(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 149 | wait(1); |
mbalourdas9 | 1:1d5055ca2793 | 150 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 151 | answer = 0; |
mbalourdas9 | 1:1d5055ca2793 | 152 | check = 1; |
mbalourdas9 | 1:1d5055ca2793 | 153 | } |
mbalourdas9 | 1:1d5055ca2793 | 154 | if (value == 2){ |
mbalourdas9 | 1:1d5055ca2793 | 155 | //play correct image |
mbalourdas9 | 1:1d5055ca2793 | 156 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 157 | uLCD.media_init(); |
mbalourdas9 | 1:1d5055ca2793 | 158 | uLCD.set_sector_address(0x0000, 0x005E); |
mbalourdas9 | 1:1d5055ca2793 | 159 | uLCD.display_image(0,0); |
mbalourdas9 | 1:1d5055ca2793 | 160 | FILE *wave_file; |
mbalourdas9 | 1:1d5055ca2793 | 161 | wave_file=fopen("/sd/sounds/right_taught.wav","r"); |
mbalourdas9 | 1:1d5055ca2793 | 162 | waver.play(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 163 | fclose(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 164 | wait(1); |
mbalourdas9 | 1:1d5055ca2793 | 165 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 166 | Score=Score+1;; |
mbalourdas9 | 1:1d5055ca2793 | 167 | uLCD.printf("Score: %d", Score); |
mbalourdas9 | 1:1d5055ca2793 | 168 | wait(1); |
mbalourdas9 | 1:1d5055ca2793 | 169 | answer = 1; |
mbalourdas9 | 1:1d5055ca2793 | 170 | check = 1; |
mbalourdas9 | 1:1d5055ca2793 | 171 | } |
mbalourdas9 | 1:1d5055ca2793 | 172 | if (value == 8){ |
mbalourdas9 | 1:1d5055ca2793 | 173 | //play game over |
mbalourdas9 | 1:1d5055ca2793 | 174 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 175 | uLCD.media_init(); |
mbalourdas9 | 1:1d5055ca2793 | 176 | uLCD.set_sector_address(0x0000, 0x009F); |
mbalourdas9 | 1:1d5055ca2793 | 177 | uLCD.display_image(0,0); |
mbalourdas9 | 1:1d5055ca2793 | 178 | FILE *wave_file; |
mbalourdas9 | 1:1d5055ca2793 | 179 | wave_file=fopen("/sd/sounds/wrong_last.wav","r"); |
mbalourdas9 | 1:1d5055ca2793 | 180 | waver.play(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 181 | fclose(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 182 | wait(1); |
mbalourdas9 | 1:1d5055ca2793 | 183 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 184 | answer = 0; |
mbalourdas9 | 1:1d5055ca2793 | 185 | check = 1; |
mbalourdas9 | 1:1d5055ca2793 | 186 | } |
mbalourdas9 | 1:1d5055ca2793 | 187 | } |
mbalourdas9 | 1:1d5055ca2793 | 188 | |
mbalourdas9 | 1:1d5055ca2793 | 189 | } |
mbalourdas9 | 1:1d5055ca2793 | 190 | if (question == 3){ |
mbalourdas9 | 1:1d5055ca2793 | 191 | value = 0; |
mbalourdas9 | 1:1d5055ca2793 | 192 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 193 | uLCD.locate(1,2); |
mbalourdas9 | 1:1d5055ca2793 | 194 | uLCD.printf("Who wrote The \nGrapes of Wrath?\n\n\n"); |
mbalourdas9 | 1:1d5055ca2793 | 195 | uLCD.printf("1)Ernest Hemingway"); |
mbalourdas9 | 1:1d5055ca2793 | 196 | uLCD.printf("2)George Orwell\n"); |
mbalourdas9 | 1:1d5055ca2793 | 197 | uLCD.printf("3)John Steinbeck\n"); |
mbalourdas9 | 1:1d5055ca2793 | 198 | while (check == 0){ |
mbalourdas9 | 1:1d5055ca2793 | 199 | int value=mpr121.read(0x00); |
mbalourdas9 | 1:1d5055ca2793 | 200 | value +=mpr121.read(0x01)<<8; |
mbalourdas9 | 1:1d5055ca2793 | 201 | if (value == 2){ |
mbalourdas9 | 1:1d5055ca2793 | 202 | //play game over |
mbalourdas9 | 1:1d5055ca2793 | 203 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 204 | uLCD.media_init(); |
mbalourdas9 | 1:1d5055ca2793 | 205 | uLCD.set_sector_address(0x0000, 0x009F); |
mbalourdas9 | 1:1d5055ca2793 | 206 | uLCD.display_image(0,0); |
mbalourdas9 | 1:1d5055ca2793 | 207 | FILE *wave_file; |
mbalourdas9 | 1:1d5055ca2793 | 208 | wave_file=fopen("/sd/sounds/wrong_last.wav","r"); |
mbalourdas9 | 1:1d5055ca2793 | 209 | waver.play(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 210 | fclose(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 211 | wait(1); |
mbalourdas9 | 1:1d5055ca2793 | 212 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 213 | answer = 0; |
mbalourdas9 | 1:1d5055ca2793 | 214 | check = 1; |
mbalourdas9 | 1:1d5055ca2793 | 215 | } |
mbalourdas9 | 1:1d5055ca2793 | 216 | if (value == 8){ |
mbalourdas9 | 1:1d5055ca2793 | 217 | //play correct image |
mbalourdas9 | 1:1d5055ca2793 | 218 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 219 | uLCD.media_init(); |
mbalourdas9 | 1:1d5055ca2793 | 220 | uLCD.set_sector_address(0x0000, 0x005E); |
mbalourdas9 | 1:1d5055ca2793 | 221 | uLCD.display_image(0,0); |
mbalourdas9 | 1:1d5055ca2793 | 222 | FILE *wave_file; |
mbalourdas9 | 1:1d5055ca2793 | 223 | wave_file=fopen("/sd/sounds/right_taught.wav","r"); |
mbalourdas9 | 1:1d5055ca2793 | 224 | waver.play(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 225 | fclose(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 226 | wait(1); |
mbalourdas9 | 1:1d5055ca2793 | 227 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 228 | Score = Score+1; |
mbalourdas9 | 1:1d5055ca2793 | 229 | uLCD.printf("Score: %d", Score); |
mbalourdas9 | 1:1d5055ca2793 | 230 | wait(1); |
mbalourdas9 | 1:1d5055ca2793 | 231 | answer = 1; |
mbalourdas9 | 1:1d5055ca2793 | 232 | check = 1; |
mbalourdas9 | 1:1d5055ca2793 | 233 | } |
mbalourdas9 | 1:1d5055ca2793 | 234 | if (value == 4){ |
mbalourdas9 | 1:1d5055ca2793 | 235 | //play game over |
mbalourdas9 | 1:1d5055ca2793 | 236 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 237 | uLCD.media_init(); |
mbalourdas9 | 1:1d5055ca2793 | 238 | uLCD.set_sector_address(0x0000, 0x009F); |
mbalourdas9 | 1:1d5055ca2793 | 239 | uLCD.display_image(0,0); |
mbalourdas9 | 1:1d5055ca2793 | 240 | FILE *wave_file; |
mbalourdas9 | 1:1d5055ca2793 | 241 | wave_file=fopen("/sd/sounds/wrong_last.wav","r"); |
mbalourdas9 | 1:1d5055ca2793 | 242 | waver.play(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 243 | fclose(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 244 | wait(1); |
mbalourdas9 | 1:1d5055ca2793 | 245 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 246 | answer = 0; |
mbalourdas9 | 1:1d5055ca2793 | 247 | check = 1; |
mbalourdas9 | 1:1d5055ca2793 | 248 | } |
mbalourdas9 | 1:1d5055ca2793 | 249 | } |
mbalourdas9 | 1:1d5055ca2793 | 250 | } |
mbalourdas9 | 1:1d5055ca2793 | 251 | if (question == 4){ |
mbalourdas9 | 1:1d5055ca2793 | 252 | value = 0; |
mbalourdas9 | 1:1d5055ca2793 | 253 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 254 | uLCD.locate(1,2); |
mbalourdas9 | 1:1d5055ca2793 | 255 | uLCD.printf("What year was \nEinstein born?\n\n\n"); |
mbalourdas9 | 1:1d5055ca2793 | 256 | uLCD.printf("1) 1900\n"); |
mbalourdas9 | 1:1d5055ca2793 | 257 | uLCD.printf("2) 1879\n"); |
mbalourdas9 | 1:1d5055ca2793 | 258 | uLCD.printf("3) 1873\n"); |
mbalourdas9 | 1:1d5055ca2793 | 259 | while (check == 0){ |
mbalourdas9 | 1:1d5055ca2793 | 260 | int value=mpr121.read(0x00); |
mbalourdas9 | 1:1d5055ca2793 | 261 | value +=mpr121.read(0x01)<<8; |
mbalourdas9 | 1:1d5055ca2793 | 262 | if (value == 2){ |
mbalourdas9 | 1:1d5055ca2793 | 263 | //play game over |
mbalourdas9 | 1:1d5055ca2793 | 264 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 265 | uLCD.media_init(); |
mbalourdas9 | 1:1d5055ca2793 | 266 | uLCD.set_sector_address(0x0000, 0x009F); |
mbalourdas9 | 1:1d5055ca2793 | 267 | uLCD.display_image(0,0); |
mbalourdas9 | 1:1d5055ca2793 | 268 | FILE *wave_file; |
mbalourdas9 | 1:1d5055ca2793 | 269 | wave_file=fopen("/sd/sounds/wrong_last.wav","r"); |
mbalourdas9 | 1:1d5055ca2793 | 270 | waver.play(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 271 | fclose(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 272 | wait(1); |
mbalourdas9 | 1:1d5055ca2793 | 273 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 274 | answer = 0; |
mbalourdas9 | 1:1d5055ca2793 | 275 | check = 1; |
mbalourdas9 | 1:1d5055ca2793 | 276 | } |
mbalourdas9 | 1:1d5055ca2793 | 277 | if (value == 4){ |
mbalourdas9 | 1:1d5055ca2793 | 278 | //play correct image |
mbalourdas9 | 1:1d5055ca2793 | 279 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 280 | uLCD.media_init(); |
mbalourdas9 | 1:1d5055ca2793 | 281 | uLCD.set_sector_address(0x0000, 0x005E); |
mbalourdas9 | 1:1d5055ca2793 | 282 | uLCD.display_image(0,0); |
mbalourdas9 | 1:1d5055ca2793 | 283 | FILE *wave_file; |
mbalourdas9 | 1:1d5055ca2793 | 284 | wave_file=fopen("/sd/sounds/right_taught.wav","r"); |
mbalourdas9 | 1:1d5055ca2793 | 285 | waver.play(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 286 | fclose(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 287 | wait(1); |
mbalourdas9 | 1:1d5055ca2793 | 288 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 289 | Score = Score+1; |
mbalourdas9 | 1:1d5055ca2793 | 290 | uLCD.printf("Score: %d", Score); |
mbalourdas9 | 1:1d5055ca2793 | 291 | wait(1); |
mbalourdas9 | 1:1d5055ca2793 | 292 | answer = 1; |
mbalourdas9 | 1:1d5055ca2793 | 293 | check = 1; |
mbalourdas9 | 1:1d5055ca2793 | 294 | } |
mbalourdas9 | 1:1d5055ca2793 | 295 | if (value == 8){ |
mbalourdas9 | 1:1d5055ca2793 | 296 | //play game over |
mbalourdas9 | 1:1d5055ca2793 | 297 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 298 | uLCD.media_init(); |
mbalourdas9 | 1:1d5055ca2793 | 299 | uLCD.set_sector_address(0x0000, 0x009F); |
mbalourdas9 | 1:1d5055ca2793 | 300 | uLCD.display_image(0,0); |
mbalourdas9 | 1:1d5055ca2793 | 301 | FILE *wave_file; |
mbalourdas9 | 1:1d5055ca2793 | 302 | wave_file=fopen("/sd/sounds/wrong_last.wav","r"); |
mbalourdas9 | 1:1d5055ca2793 | 303 | waver.play(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 304 | fclose(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 305 | wait(1); |
mbalourdas9 | 1:1d5055ca2793 | 306 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 307 | answer = 0; |
mbalourdas9 | 1:1d5055ca2793 | 308 | check = 1; |
mbalourdas9 | 1:1d5055ca2793 | 309 | } |
mbalourdas9 | 1:1d5055ca2793 | 310 | } |
mbalourdas9 | 1:1d5055ca2793 | 311 | } |
mbalourdas9 | 1:1d5055ca2793 | 312 | if (question == 5){ |
mbalourdas9 | 1:1d5055ca2793 | 313 | value = 0; |
mbalourdas9 | 1:1d5055ca2793 | 314 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 315 | uLCD.locate(1,2); |
mbalourdas9 | 1:1d5055ca2793 | 316 | uLCD.printf("Which song is by the Rolling Stones?\n\n\n"); |
mbalourdas9 | 1:1d5055ca2793 | 317 | uLCD.printf("1) Paint It Black\n"); |
mbalourdas9 | 1:1d5055ca2793 | 318 | uLCD.printf("2) Feel For \nThe Devil\n"); |
mbalourdas9 | 1:1d5055ca2793 | 319 | uLCD.printf("3) Let It Be\n"); |
mbalourdas9 | 1:1d5055ca2793 | 320 | while (check == 0){ |
mbalourdas9 | 1:1d5055ca2793 | 321 | int value=mpr121.read(0x00); |
mbalourdas9 | 1:1d5055ca2793 | 322 | value +=mpr121.read(0x01)<<8; |
mbalourdas9 | 1:1d5055ca2793 | 323 | if (value == 4){ |
mbalourdas9 | 1:1d5055ca2793 | 324 | //play game over |
mbalourdas9 | 1:1d5055ca2793 | 325 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 326 | uLCD.media_init(); |
mbalourdas9 | 1:1d5055ca2793 | 327 | uLCD.set_sector_address(0x0000, 0x009F); |
mbalourdas9 | 1:1d5055ca2793 | 328 | uLCD.display_image(0,0); |
mbalourdas9 | 1:1d5055ca2793 | 329 | FILE *wave_file; |
mbalourdas9 | 1:1d5055ca2793 | 330 | wave_file=fopen("/sd/sounds/wrong_last.wav","r"); |
mbalourdas9 | 1:1d5055ca2793 | 331 | waver.play(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 332 | fclose(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 333 | wait(1); |
mbalourdas9 | 1:1d5055ca2793 | 334 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 335 | answer = 0; |
mbalourdas9 | 1:1d5055ca2793 | 336 | check = 1; |
mbalourdas9 | 1:1d5055ca2793 | 337 | } |
mbalourdas9 | 1:1d5055ca2793 | 338 | if (value == 2){ |
mbalourdas9 | 1:1d5055ca2793 | 339 | //play correct image |
mbalourdas9 | 1:1d5055ca2793 | 340 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 341 | uLCD.media_init(); |
mbalourdas9 | 1:1d5055ca2793 | 342 | uLCD.set_sector_address(0x0000, 0x005E); |
mbalourdas9 | 1:1d5055ca2793 | 343 | uLCD.display_image(0,0); |
mbalourdas9 | 1:1d5055ca2793 | 344 | FILE *wave_file; |
mbalourdas9 | 1:1d5055ca2793 | 345 | wave_file=fopen("/sd/sounds/right_taught.wav","r"); |
mbalourdas9 | 1:1d5055ca2793 | 346 | waver.play(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 347 | fclose(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 348 | wait(1); |
mbalourdas9 | 1:1d5055ca2793 | 349 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 350 | Score = Score+1; |
mbalourdas9 | 1:1d5055ca2793 | 351 | uLCD.printf("Score: %d", Score); |
mbalourdas9 | 1:1d5055ca2793 | 352 | wait(1); |
mbalourdas9 | 1:1d5055ca2793 | 353 | answer = 1; |
mbalourdas9 | 1:1d5055ca2793 | 354 | check = 1; |
mbalourdas9 | 1:1d5055ca2793 | 355 | } |
mbalourdas9 | 1:1d5055ca2793 | 356 | if (value == 8){ |
mbalourdas9 | 1:1d5055ca2793 | 357 | //play game over |
mbalourdas9 | 1:1d5055ca2793 | 358 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 359 | uLCD.media_init(); |
mbalourdas9 | 1:1d5055ca2793 | 360 | uLCD.set_sector_address(0x0000, 0x009F); |
mbalourdas9 | 1:1d5055ca2793 | 361 | uLCD.display_image(0,0); |
mbalourdas9 | 1:1d5055ca2793 | 362 | FILE *wave_file; |
mbalourdas9 | 1:1d5055ca2793 | 363 | wave_file=fopen("/sd/sounds/wrong_last.wav","r"); |
mbalourdas9 | 1:1d5055ca2793 | 364 | waver.play(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 365 | fclose(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 366 | wait(1); |
mbalourdas9 | 1:1d5055ca2793 | 367 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 368 | answer = 0; |
mbalourdas9 | 1:1d5055ca2793 | 369 | check = 1; |
mbalourdas9 | 1:1d5055ca2793 | 370 | } |
mbalourdas9 | 1:1d5055ca2793 | 371 | } |
mbalourdas9 | 1:1d5055ca2793 | 372 | } |
mbalourdas9 | 1:1d5055ca2793 | 373 | if (question == 6){ |
mbalourdas9 | 1:1d5055ca2793 | 374 | value = 0; |
mbalourdas9 | 1:1d5055ca2793 | 375 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 376 | uLCD.locate(1,2); |
mbalourdas9 | 1:1d5055ca2793 | 377 | uLCD.printf("Where was Hitler born?\n\n\n"); |
mbalourdas9 | 1:1d5055ca2793 | 378 | uLCD.printf("1) Poland\n"); |
mbalourdas9 | 1:1d5055ca2793 | 379 | uLCD.printf("2) Germany\n"); |
mbalourdas9 | 1:1d5055ca2793 | 380 | uLCD.printf("3) Austria\n"); |
mbalourdas9 | 1:1d5055ca2793 | 381 | while (check == 0){ |
mbalourdas9 | 1:1d5055ca2793 | 382 | int value=mpr121.read(0x00); |
mbalourdas9 | 1:1d5055ca2793 | 383 | value +=mpr121.read(0x01)<<8; |
mbalourdas9 | 1:1d5055ca2793 | 384 | if (value == 4){ |
mbalourdas9 | 1:1d5055ca2793 | 385 | //play game over |
mbalourdas9 | 1:1d5055ca2793 | 386 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 387 | uLCD.media_init(); |
mbalourdas9 | 1:1d5055ca2793 | 388 | uLCD.set_sector_address(0x0000, 0x009F); |
mbalourdas9 | 1:1d5055ca2793 | 389 | uLCD.display_image(0,0); |
mbalourdas9 | 1:1d5055ca2793 | 390 | FILE *wave_file; |
mbalourdas9 | 1:1d5055ca2793 | 391 | wave_file=fopen("/sd/sounds/wrong_last.wav","r"); |
mbalourdas9 | 1:1d5055ca2793 | 392 | waver.play(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 393 | fclose(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 394 | wait(1); |
mbalourdas9 | 1:1d5055ca2793 | 395 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 396 | answer = 0; |
mbalourdas9 | 1:1d5055ca2793 | 397 | check = 1; |
mbalourdas9 | 1:1d5055ca2793 | 398 | } |
mbalourdas9 | 1:1d5055ca2793 | 399 | if (value == 8){ |
mbalourdas9 | 1:1d5055ca2793 | 400 | //play correct image |
mbalourdas9 | 1:1d5055ca2793 | 401 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 402 | uLCD.media_init(); |
mbalourdas9 | 1:1d5055ca2793 | 403 | uLCD.set_sector_address(0x0000, 0x005E); |
mbalourdas9 | 1:1d5055ca2793 | 404 | uLCD.display_image(0,0); |
mbalourdas9 | 1:1d5055ca2793 | 405 | FILE *wave_file; |
mbalourdas9 | 1:1d5055ca2793 | 406 | wave_file=fopen("/sd/sounds/right_taught.wav","r"); |
mbalourdas9 | 1:1d5055ca2793 | 407 | waver.play(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 408 | fclose(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 409 | wait(1); |
mbalourdas9 | 1:1d5055ca2793 | 410 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 411 | Score = Score+1; |
mbalourdas9 | 1:1d5055ca2793 | 412 | uLCD.printf("Score: %d", Score); |
mbalourdas9 | 1:1d5055ca2793 | 413 | wait(1); |
mbalourdas9 | 1:1d5055ca2793 | 414 | answer = 1; |
mbalourdas9 | 1:1d5055ca2793 | 415 | check = 1; |
mbalourdas9 | 1:1d5055ca2793 | 416 | } |
mbalourdas9 | 1:1d5055ca2793 | 417 | if (value == 2){ |
mbalourdas9 | 1:1d5055ca2793 | 418 | //play game over |
mbalourdas9 | 1:1d5055ca2793 | 419 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 420 | uLCD.media_init(); |
mbalourdas9 | 1:1d5055ca2793 | 421 | uLCD.set_sector_address(0x0000, 0x009F); |
mbalourdas9 | 1:1d5055ca2793 | 422 | uLCD.display_image(0,0); |
mbalourdas9 | 1:1d5055ca2793 | 423 | FILE *wave_file; |
mbalourdas9 | 1:1d5055ca2793 | 424 | wave_file=fopen("/sd/sounds/wrong_last.wav","r"); |
mbalourdas9 | 1:1d5055ca2793 | 425 | waver.play(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 426 | fclose(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 427 | wait(1); |
mbalourdas9 | 1:1d5055ca2793 | 428 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 429 | answer = 0; |
mbalourdas9 | 1:1d5055ca2793 | 430 | check = 1; |
mbalourdas9 | 1:1d5055ca2793 | 431 | } |
mbalourdas9 | 1:1d5055ca2793 | 432 | } |
mbalourdas9 | 1:1d5055ca2793 | 433 | } |
mbalourdas9 | 1:1d5055ca2793 | 434 | if (question == 7){ |
mbalourdas9 | 1:1d5055ca2793 | 435 | value = 0; |
mbalourdas9 | 1:1d5055ca2793 | 436 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 437 | uLCD.locate(1,2); |
mbalourdas9 | 1:1d5055ca2793 | 438 | uLCD.printf("The best selling\nmusic single of all time is?\n\n\n"); |
mbalourdas9 | 1:1d5055ca2793 | 439 | uLCD.printf("1) Billie Jean\n"); |
mbalourdas9 | 1:1d5055ca2793 | 440 | uLCD.printf("2) White Christmas\n"); |
mbalourdas9 | 1:1d5055ca2793 | 441 | uLCD.printf("3) Candle in the \nWind\n"); |
mbalourdas9 | 1:1d5055ca2793 | 442 | while (check == 0){ |
mbalourdas9 | 1:1d5055ca2793 | 443 | int value=mpr121.read(0x00); |
mbalourdas9 | 1:1d5055ca2793 | 444 | value +=mpr121.read(0x01)<<8; |
mbalourdas9 | 1:1d5055ca2793 | 445 | if (value == 4){ |
mbalourdas9 | 1:1d5055ca2793 | 446 | //play game over |
mbalourdas9 | 1:1d5055ca2793 | 447 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 448 | uLCD.media_init(); |
mbalourdas9 | 1:1d5055ca2793 | 449 | uLCD.set_sector_address(0x0000, 0x009F); |
mbalourdas9 | 1:1d5055ca2793 | 450 | uLCD.display_image(0,0); |
mbalourdas9 | 1:1d5055ca2793 | 451 | FILE *wave_file; |
mbalourdas9 | 1:1d5055ca2793 | 452 | wave_file=fopen("/sd/sounds/wrong_last.wav","r"); |
mbalourdas9 | 1:1d5055ca2793 | 453 | waver.play(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 454 | fclose(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 455 | wait(1); |
mbalourdas9 | 1:1d5055ca2793 | 456 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 457 | answer = 0; |
mbalourdas9 | 1:1d5055ca2793 | 458 | check = 1; |
mbalourdas9 | 1:1d5055ca2793 | 459 | } |
mbalourdas9 | 1:1d5055ca2793 | 460 | if (value == 8){ |
mbalourdas9 | 1:1d5055ca2793 | 461 | //play correct image |
mbalourdas9 | 1:1d5055ca2793 | 462 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 463 | uLCD.media_init(); |
mbalourdas9 | 1:1d5055ca2793 | 464 | uLCD.set_sector_address(0x0000, 0x005E); |
mbalourdas9 | 1:1d5055ca2793 | 465 | uLCD.display_image(0,0); |
mbalourdas9 | 1:1d5055ca2793 | 466 | FILE *wave_file; |
mbalourdas9 | 1:1d5055ca2793 | 467 | wave_file=fopen("/sd/sounds/right_taught.wav","r"); |
mbalourdas9 | 1:1d5055ca2793 | 468 | waver.play(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 469 | fclose(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 470 | wait(1); |
mbalourdas9 | 1:1d5055ca2793 | 471 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 472 | Score = Score+1; |
mbalourdas9 | 1:1d5055ca2793 | 473 | uLCD.printf("Score: %d", Score); |
mbalourdas9 | 1:1d5055ca2793 | 474 | wait(1); |
mbalourdas9 | 1:1d5055ca2793 | 475 | answer = 1; |
mbalourdas9 | 1:1d5055ca2793 | 476 | check = 1; |
mbalourdas9 | 1:1d5055ca2793 | 477 | } |
mbalourdas9 | 1:1d5055ca2793 | 478 | if (value == 2){ |
mbalourdas9 | 1:1d5055ca2793 | 479 | //play game over |
mbalourdas9 | 1:1d5055ca2793 | 480 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 481 | uLCD.media_init(); |
mbalourdas9 | 1:1d5055ca2793 | 482 | uLCD.set_sector_address(0x0000, 0x009F); |
mbalourdas9 | 1:1d5055ca2793 | 483 | uLCD.display_image(0,0); |
mbalourdas9 | 1:1d5055ca2793 | 484 | FILE *wave_file; |
mbalourdas9 | 1:1d5055ca2793 | 485 | wave_file=fopen("/sd/sounds/wrong_last.wav","r"); |
mbalourdas9 | 1:1d5055ca2793 | 486 | waver.play(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 487 | fclose(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 488 | wait(1); |
mbalourdas9 | 1:1d5055ca2793 | 489 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 490 | answer = 0; |
mbalourdas9 | 1:1d5055ca2793 | 491 | check = 1; |
mbalourdas9 | 1:1d5055ca2793 | 492 | } |
mbalourdas9 | 1:1d5055ca2793 | 493 | } |
mbalourdas9 | 1:1d5055ca2793 | 494 | } |
mbalourdas9 | 1:1d5055ca2793 | 495 | if (question == 8){ |
mbalourdas9 | 1:1d5055ca2793 | 496 | value = 0; |
mbalourdas9 | 1:1d5055ca2793 | 497 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 498 | uLCD.locate(1,2); |
mbalourdas9 | 1:1d5055ca2793 | 499 | uLCD.printf("What is the \ncurrency of \nJapan?\n\n\n"); |
mbalourdas9 | 1:1d5055ca2793 | 500 | uLCD.printf("1) Pounds\n"); |
mbalourdas9 | 1:1d5055ca2793 | 501 | uLCD.printf("2) Yen\n"); |
mbalourdas9 | 1:1d5055ca2793 | 502 | uLCD.printf("3) Riki\n"); |
mbalourdas9 | 1:1d5055ca2793 | 503 | while (check == 0){ |
mbalourdas9 | 1:1d5055ca2793 | 504 | int value=mpr121.read(0x00); |
mbalourdas9 | 1:1d5055ca2793 | 505 | value +=mpr121.read(0x01)<<8; |
mbalourdas9 | 1:1d5055ca2793 | 506 | if (value == 2){ |
mbalourdas9 | 1:1d5055ca2793 | 507 | //play game over |
mbalourdas9 | 1:1d5055ca2793 | 508 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 509 | uLCD.media_init(); |
mbalourdas9 | 1:1d5055ca2793 | 510 | uLCD.set_sector_address(0x0000, 0x009F); |
mbalourdas9 | 1:1d5055ca2793 | 511 | uLCD.display_image(0,0); |
mbalourdas9 | 1:1d5055ca2793 | 512 | FILE *wave_file; |
mbalourdas9 | 1:1d5055ca2793 | 513 | wave_file=fopen("/sd/sounds/wrong_last.wav","r"); |
mbalourdas9 | 1:1d5055ca2793 | 514 | waver.play(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 515 | fclose(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 516 | wait(1); |
mbalourdas9 | 1:1d5055ca2793 | 517 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 518 | answer = 0; |
mbalourdas9 | 1:1d5055ca2793 | 519 | check = 1; |
mbalourdas9 | 1:1d5055ca2793 | 520 | } |
mbalourdas9 | 1:1d5055ca2793 | 521 | if (value == 4){ |
mbalourdas9 | 1:1d5055ca2793 | 522 | //play correct image |
mbalourdas9 | 1:1d5055ca2793 | 523 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 524 | uLCD.media_init(); |
mbalourdas9 | 1:1d5055ca2793 | 525 | uLCD.set_sector_address(0x0000, 0x005E); |
mbalourdas9 | 1:1d5055ca2793 | 526 | uLCD.display_image(0,0); |
mbalourdas9 | 1:1d5055ca2793 | 527 | FILE *wave_file; |
mbalourdas9 | 1:1d5055ca2793 | 528 | wave_file=fopen("/sd/sounds/right_taught.wav","r"); |
mbalourdas9 | 1:1d5055ca2793 | 529 | waver.play(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 530 | fclose(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 531 | wait(1); |
mbalourdas9 | 1:1d5055ca2793 | 532 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 533 | Score = Score+1; |
mbalourdas9 | 1:1d5055ca2793 | 534 | uLCD.printf("Score: %d", Score); |
mbalourdas9 | 1:1d5055ca2793 | 535 | wait(1); |
mbalourdas9 | 1:1d5055ca2793 | 536 | answer = 1; |
mbalourdas9 | 1:1d5055ca2793 | 537 | check = 1; |
mbalourdas9 | 1:1d5055ca2793 | 538 | } |
mbalourdas9 | 1:1d5055ca2793 | 539 | if (value == 8){ |
mbalourdas9 | 1:1d5055ca2793 | 540 | //play game over |
mbalourdas9 | 1:1d5055ca2793 | 541 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 542 | uLCD.media_init(); |
mbalourdas9 | 1:1d5055ca2793 | 543 | uLCD.set_sector_address(0x0000, 0x009F); |
mbalourdas9 | 1:1d5055ca2793 | 544 | uLCD.display_image(0,0); |
mbalourdas9 | 1:1d5055ca2793 | 545 | FILE *wave_file; |
mbalourdas9 | 1:1d5055ca2793 | 546 | wave_file=fopen("/sd/sounds/wrong_last.wav","r"); |
mbalourdas9 | 1:1d5055ca2793 | 547 | waver.play(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 548 | fclose(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 549 | wait(1); |
mbalourdas9 | 1:1d5055ca2793 | 550 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 551 | answer = 0; |
mbalourdas9 | 1:1d5055ca2793 | 552 | check = 1; |
mbalourdas9 | 1:1d5055ca2793 | 553 | } |
mbalourdas9 | 1:1d5055ca2793 | 554 | } |
mbalourdas9 | 1:1d5055ca2793 | 555 | } |
mbalourdas9 | 1:1d5055ca2793 | 556 | if (question == 9){ |
mbalourdas9 | 1:1d5055ca2793 | 557 | value = 0; |
mbalourdas9 | 1:1d5055ca2793 | 558 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 559 | uLCD.locate(1,2); |
mbalourdas9 | 1:1d5055ca2793 | 560 | uLCD.printf("Who was Harry \nHoudini?\n\n\n"); |
mbalourdas9 | 1:1d5055ca2793 | 561 | uLCD.printf("1)An Escape Artist\n"); |
mbalourdas9 | 1:1d5055ca2793 | 562 | uLCD.printf("2)Fighter Pilot in WWII\n"); |
mbalourdas9 | 1:1d5055ca2793 | 563 | uLCD.printf("3) Harry Potter's Cousin\n"); |
mbalourdas9 | 1:1d5055ca2793 | 564 | while (check == 0){ |
mbalourdas9 | 1:1d5055ca2793 | 565 | int value=mpr121.read(0x00); |
mbalourdas9 | 1:1d5055ca2793 | 566 | value +=mpr121.read(0x01)<<8; |
mbalourdas9 | 1:1d5055ca2793 | 567 | if (value == 4){ |
mbalourdas9 | 1:1d5055ca2793 | 568 | //play game over |
mbalourdas9 | 1:1d5055ca2793 | 569 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 570 | uLCD.media_init(); |
mbalourdas9 | 1:1d5055ca2793 | 571 | uLCD.set_sector_address(0x0000, 0x009F); |
mbalourdas9 | 1:1d5055ca2793 | 572 | uLCD.display_image(0,0); |
mbalourdas9 | 1:1d5055ca2793 | 573 | FILE *wave_file; |
mbalourdas9 | 1:1d5055ca2793 | 574 | wave_file=fopen("/sd/sounds/wrong_last.wav","r"); |
mbalourdas9 | 1:1d5055ca2793 | 575 | waver.play(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 576 | fclose(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 577 | wait(1); |
mbalourdas9 | 1:1d5055ca2793 | 578 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 579 | answer = 0; |
mbalourdas9 | 1:1d5055ca2793 | 580 | check = 1; |
mbalourdas9 | 1:1d5055ca2793 | 581 | } |
mbalourdas9 | 1:1d5055ca2793 | 582 | if (value == 2){ |
mbalourdas9 | 1:1d5055ca2793 | 583 | //play correct image |
mbalourdas9 | 1:1d5055ca2793 | 584 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 585 | uLCD.media_init(); |
mbalourdas9 | 1:1d5055ca2793 | 586 | uLCD.set_sector_address(0x0000, 0x005E); |
mbalourdas9 | 1:1d5055ca2793 | 587 | uLCD.display_image(0,0); |
mbalourdas9 | 1:1d5055ca2793 | 588 | FILE *wave_file; |
mbalourdas9 | 1:1d5055ca2793 | 589 | wave_file=fopen("/sd/sounds/right_taught.wav","r"); |
mbalourdas9 | 1:1d5055ca2793 | 590 | waver.play(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 591 | fclose(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 592 | wait(1); |
mbalourdas9 | 1:1d5055ca2793 | 593 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 594 | Score = Score+1; |
mbalourdas9 | 1:1d5055ca2793 | 595 | uLCD.printf("Score: %d", Score); |
mbalourdas9 | 1:1d5055ca2793 | 596 | wait(1); |
mbalourdas9 | 1:1d5055ca2793 | 597 | answer = 1; |
mbalourdas9 | 1:1d5055ca2793 | 598 | check = 1; |
mbalourdas9 | 1:1d5055ca2793 | 599 | } |
mbalourdas9 | 1:1d5055ca2793 | 600 | if (value == 8){ |
mbalourdas9 | 1:1d5055ca2793 | 601 | //play game over |
mbalourdas9 | 1:1d5055ca2793 | 602 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 603 | uLCD.media_init(); |
mbalourdas9 | 1:1d5055ca2793 | 604 | uLCD.set_sector_address(0x0000, 0x009F); |
mbalourdas9 | 1:1d5055ca2793 | 605 | uLCD.display_image(0,0); |
mbalourdas9 | 1:1d5055ca2793 | 606 | FILE *wave_file; |
mbalourdas9 | 1:1d5055ca2793 | 607 | wave_file=fopen("/sd/sounds/wrong_last.wav","r"); |
mbalourdas9 | 1:1d5055ca2793 | 608 | waver.play(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 609 | fclose(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 610 | wait(1); |
mbalourdas9 | 1:1d5055ca2793 | 611 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 612 | answer = 0; |
mbalourdas9 | 1:1d5055ca2793 | 613 | check = 1; |
mbalourdas9 | 1:1d5055ca2793 | 614 | } |
mbalourdas9 | 1:1d5055ca2793 | 615 | } |
mbalourdas9 | 1:1d5055ca2793 | 616 | } |
mbalourdas9 | 1:1d5055ca2793 | 617 | if (question == 10){ |
mbalourdas9 | 1:1d5055ca2793 | 618 | value = 0; |
mbalourdas9 | 1:1d5055ca2793 | 619 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 620 | uLCD.locate(1,2); |
mbalourdas9 | 1:1d5055ca2793 | 621 | uLCD.printf("What is glass \nmainly made up \nof?\n\n\n"); |
mbalourdas9 | 1:1d5055ca2793 | 622 | uLCD.printf("1) Sand\n"); |
mbalourdas9 | 1:1d5055ca2793 | 623 | uLCD.printf("2) Crystals\n"); |
mbalourdas9 | 1:1d5055ca2793 | 624 | uLCD.printf("3) Highly \nCompressed \nWater\n"); |
mbalourdas9 | 1:1d5055ca2793 | 625 | while (check == 0){ |
mbalourdas9 | 1:1d5055ca2793 | 626 | int value=mpr121.read(0x00); |
mbalourdas9 | 1:1d5055ca2793 | 627 | value +=mpr121.read(0x01)<<8; |
mbalourdas9 | 1:1d5055ca2793 | 628 | if (value == 4){ |
mbalourdas9 | 1:1d5055ca2793 | 629 | //play game over |
mbalourdas9 | 1:1d5055ca2793 | 630 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 631 | uLCD.media_init(); |
mbalourdas9 | 1:1d5055ca2793 | 632 | uLCD.set_sector_address(0x0000, 0x009F); |
mbalourdas9 | 1:1d5055ca2793 | 633 | uLCD.display_image(0,0); |
mbalourdas9 | 1:1d5055ca2793 | 634 | FILE *wave_file; |
mbalourdas9 | 1:1d5055ca2793 | 635 | wave_file=fopen("/sd/sounds/wrong_last.wav","r"); |
mbalourdas9 | 1:1d5055ca2793 | 636 | waver.play(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 637 | fclose(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 638 | wait(1); |
mbalourdas9 | 1:1d5055ca2793 | 639 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 640 | answer = 0; |
mbalourdas9 | 1:1d5055ca2793 | 641 | check = 1; |
mbalourdas9 | 1:1d5055ca2793 | 642 | } |
mbalourdas9 | 1:1d5055ca2793 | 643 | if (value == 2){ |
mbalourdas9 | 1:1d5055ca2793 | 644 | //play correct image |
mbalourdas9 | 1:1d5055ca2793 | 645 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 646 | uLCD.media_init(); |
mbalourdas9 | 1:1d5055ca2793 | 647 | uLCD.set_sector_address(0x0000, 0x005E); |
mbalourdas9 | 1:1d5055ca2793 | 648 | uLCD.display_image(0,0); |
mbalourdas9 | 1:1d5055ca2793 | 649 | FILE *wave_file; |
mbalourdas9 | 1:1d5055ca2793 | 650 | wave_file=fopen("/sd/sounds/right_taught.wav","r"); |
mbalourdas9 | 1:1d5055ca2793 | 651 | waver.play(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 652 | fclose(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 653 | wait(1); |
mbalourdas9 | 1:1d5055ca2793 | 654 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 655 | Score = Score+1; |
mbalourdas9 | 1:1d5055ca2793 | 656 | uLCD.printf("Score: %d", Score); |
mbalourdas9 | 1:1d5055ca2793 | 657 | wait(1); |
mbalourdas9 | 1:1d5055ca2793 | 658 | answer = 1; |
mbalourdas9 | 1:1d5055ca2793 | 659 | check = 1; |
mbalourdas9 | 1:1d5055ca2793 | 660 | } |
mbalourdas9 | 1:1d5055ca2793 | 661 | if (value == 8){ |
mbalourdas9 | 1:1d5055ca2793 | 662 | //play game over |
mbalourdas9 | 1:1d5055ca2793 | 663 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 664 | uLCD.media_init(); |
mbalourdas9 | 1:1d5055ca2793 | 665 | uLCD.set_sector_address(0x0000, 0x009F); |
mbalourdas9 | 1:1d5055ca2793 | 666 | uLCD.display_image(0,0); |
mbalourdas9 | 1:1d5055ca2793 | 667 | FILE *wave_file; |
mbalourdas9 | 1:1d5055ca2793 | 668 | wave_file=fopen("/sd/sounds/wrong_last.wav","r"); |
mbalourdas9 | 1:1d5055ca2793 | 669 | waver.play(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 670 | fclose(wave_file); |
mbalourdas9 | 1:1d5055ca2793 | 671 | wait(1); |
mbalourdas9 | 1:1d5055ca2793 | 672 | uLCD.cls(); |
mbalourdas9 | 1:1d5055ca2793 | 673 | answer = 0; |
mbalourdas9 | 1:1d5055ca2793 | 674 | check = 1; |
mbalourdas9 | 1:1d5055ca2793 | 675 | } |
mbalourdas9 | 1:1d5055ca2793 | 676 | } |
mbalourdas9 | 1:1d5055ca2793 | 677 | } |
mbalourdas9 | 1:1d5055ca2793 | 678 | } |
mbalourdas9 | 1:1d5055ca2793 | 679 | |
mbalourdas9 | 1:1d5055ca2793 | 680 | |
mbalourdas9 | 1:1d5055ca2793 | 681 | |
mbalourdas9 | 1:1d5055ca2793 | 682 | |
mbalourdas9 | 1:1d5055ca2793 | 683 | |
mbalourdas9 | 1:1d5055ca2793 | 684 | } |
mbalourdas9 | 1:1d5055ca2793 | 685 | else{ |
mbalourdas9 | 1:1d5055ca2793 | 686 | uLCD.printf("CONGRATS!"); |
mbalourdas9 | 1:1d5055ca2793 | 687 | wait(1); |
mbalourdas9 | 1:1d5055ca2793 | 688 | } |
mbalourdas9 | 1:1d5055ca2793 | 689 | |
mbalourdas9 | 1:1d5055ca2793 | 690 | } |
mbalourdas9 | 1:1d5055ca2793 | 691 | } |