![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Guitar Hero Project on LPC1768 using push buttons, analog joystick. speaker and LCD Display
Dependencies: mbed wave_player mbed-rtos 4DGL-uLCD-SE SparkfunAnalogJoystick SDFileSystem_OldbutworkswithRTOS PinDetect
main.cpp@6:4bc137ec1022, 2020-11-26 (annotated)
- Committer:
- rpatel397
- Date:
- Thu Nov 26 16:40:43 2020 +0000
- Revision:
- 6:4bc137ec1022
- Parent:
- 5:2f09b457f690
- Child:
- 7:5ac5056cde2c
Added score to each attribute in Game Over Screen
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rpatel397 | 3:6f639d41aef3 | 1 | |
4180_1 | 1:5b8e223e983d | 2 | |
4180_1 | 1:5b8e223e983d | 3 | #include "mbed.h" |
4180_1 | 2:c2afd0c426af | 4 | #include "rtos.h" |
4180_1 | 1:5b8e223e983d | 5 | #include "SDFileSystem.h" |
rpatel397 | 3:6f639d41aef3 | 6 | #include "uLCD_4DGL.h" |
rpatel397 | 3:6f639d41aef3 | 7 | #include "PinDetect.h" |
rpatel397 | 5:2f09b457f690 | 8 | #include "song1.h" |
rpatel397 | 5:2f09b457f690 | 9 | |
rpatel397 | 5:2f09b457f690 | 10 | #define sample_freq 8000.0 |
rpatel397 | 4:577404e4d53f | 11 | //code change |
rpatel397 | 3:6f639d41aef3 | 12 | Mutex lcd_mut; |
rpatel397 | 3:6f639d41aef3 | 13 | //SDFileSystem sd(p5, p6, p7, p8, "sd"); //SD card |
rpatel397 | 3:6f639d41aef3 | 14 | uLCD_4DGL uLCD(p28,p27,p30); // serial tx, serial rx, reset pin; |
rpatel397 | 5:2f09b457f690 | 15 | AnalogOut speaker(p18); |
rpatel397 | 3:6f639d41aef3 | 16 | PinDetect pb_1(p9, PullUp); |
rpatel397 | 3:6f639d41aef3 | 17 | PinDetect pb_2(p10, PullUp); |
rpatel397 | 3:6f639d41aef3 | 18 | PinDetect pb_3(p11, PullUp); |
rpatel397 | 3:6f639d41aef3 | 19 | PinDetect pb_4(p12, PullUp); |
rpatel397 | 3:6f639d41aef3 | 20 | |
rpatel397 | 3:6f639d41aef3 | 21 | #define Main_Menu 0 // the first screen being shown |
rpatel397 | 3:6f639d41aef3 | 22 | #define Choose_Difficulty 1 // after hitting start, player chooses difficult |
rpatel397 | 3:6f639d41aef3 | 23 | #define Choose_Song 2 // after choosing difficullyt, choose song |
rpatel397 | 3:6f639d41aef3 | 24 | #define Start_Game 3 // the game has started |
rpatel397 | 3:6f639d41aef3 | 25 | #define Game_Over 4 // the game is done |
rpatel397 | 3:6f639d41aef3 | 26 | |
rpatel397 | 3:6f639d41aef3 | 27 | |
rpatel397 | 3:6f639d41aef3 | 28 | //colors |
rpatel397 | 3:6f639d41aef3 | 29 | #define YELLOW 16709376 |
rpatel397 | 3:6f639d41aef3 | 30 | |
rpatel397 | 3:6f639d41aef3 | 31 | //speed based on difficulty |
rpatel397 | 3:6f639d41aef3 | 32 | #define Easy 2 |
rpatel397 | 3:6f639d41aef3 | 33 | #define Medium 5 |
rpatel397 | 3:6f639d41aef3 | 34 | #define Hard 8 |
4180_1 | 1:5b8e223e983d | 35 | |
4180_1 | 1:5b8e223e983d | 36 | |
rpatel397 | 3:6f639d41aef3 | 37 | DigitalOut myled1(LED1); |
rpatel397 | 3:6f639d41aef3 | 38 | DigitalOut myled2(LED2); |
rpatel397 | 3:6f639d41aef3 | 39 | DigitalOut myled3(LED3); |
rpatel397 | 3:6f639d41aef3 | 40 | DigitalOut myled4(LED4); |
rpatel397 | 3:6f639d41aef3 | 41 | |
rpatel397 | 5:2f09b457f690 | 42 | Ticker sampletick; |
rpatel397 | 5:2f09b457f690 | 43 | |
rpatel397 | 3:6f639d41aef3 | 44 | volatile int Game_State = Game_Over; |
rpatel397 | 3:6f639d41aef3 | 45 | volatile bool draw_enable = true; |
rpatel397 | 3:6f639d41aef3 | 46 | volatile int Speed = Easy; |
rpatel397 | 3:6f639d41aef3 | 47 | |
rpatel397 | 6:4bc137ec1022 | 48 | volatile int score = 0; |
rpatel397 | 6:4bc137ec1022 | 49 | volatile int high_score = 0; |
rpatel397 | 6:4bc137ec1022 | 50 | volatile int hits = 0; |
rpatel397 | 6:4bc137ec1022 | 51 | volatile int misses = 0; |
rpatel397 | 5:2f09b457f690 | 52 | int i=0; |
rpatel397 | 5:2f09b457f690 | 53 | void audio_sample () |
rpatel397 | 5:2f09b457f690 | 54 | { |
rpatel397 | 5:2f09b457f690 | 55 | speaker.write_u16(sound_data[i]); |
rpatel397 | 5:2f09b457f690 | 56 | i++; |
rpatel397 | 5:2f09b457f690 | 57 | if (i>= NUM_ELEMENTS) { |
rpatel397 | 5:2f09b457f690 | 58 | i = 0; |
rpatel397 | 5:2f09b457f690 | 59 | sampletick.detach(); |
rpatel397 | 5:2f09b457f690 | 60 | Game_State = Game_Over; |
rpatel397 | 5:2f09b457f690 | 61 | } |
rpatel397 | 5:2f09b457f690 | 62 | } |
4180_1 | 1:5b8e223e983d | 63 | |
rpatel397 | 3:6f639d41aef3 | 64 | void LCD(void const *args) { |
rpatel397 | 5:2f09b457f690 | 65 | |
rpatel397 | 3:6f639d41aef3 | 66 | while(1) { |
rpatel397 | 3:6f639d41aef3 | 67 | switch (Game_State) { |
rpatel397 | 3:6f639d41aef3 | 68 | case Start_Game : |
rpatel397 | 3:6f639d41aef3 | 69 | if (draw_enable) { |
rpatel397 | 3:6f639d41aef3 | 70 | lcd_mut.lock(); |
rpatel397 | 3:6f639d41aef3 | 71 | uLCD.cls(); |
rpatel397 | 3:6f639d41aef3 | 72 | uLCD.printf("Start_Game"); |
rpatel397 | 3:6f639d41aef3 | 73 | lcd_mut.unlock(); |
rpatel397 | 3:6f639d41aef3 | 74 | } |
rpatel397 | 3:6f639d41aef3 | 75 | break; |
rpatel397 | 3:6f639d41aef3 | 76 | case Game_Over : |
rpatel397 | 3:6f639d41aef3 | 77 | if (draw_enable) { |
rpatel397 | 3:6f639d41aef3 | 78 | draw_enable = false; |
rpatel397 | 3:6f639d41aef3 | 79 | lcd_mut.lock(); |
rpatel397 | 3:6f639d41aef3 | 80 | uLCD.cls(); |
rpatel397 | 3:6f639d41aef3 | 81 | uLCD.line(0, 0, 127, 0, RED); |
rpatel397 | 3:6f639d41aef3 | 82 | uLCD.line(127, 0, 127, 127, BLUE); |
rpatel397 | 3:6f639d41aef3 | 83 | uLCD.line(127, 127, 0, 127, GREEN); |
rpatel397 | 3:6f639d41aef3 | 84 | uLCD.line(0, 127, 0, 0, YELLOW); |
rpatel397 | 3:6f639d41aef3 | 85 | uLCD.text_width(1); |
rpatel397 | 3:6f639d41aef3 | 86 | uLCD.text_height(2); |
rpatel397 | 3:6f639d41aef3 | 87 | uLCD.text_string("Game Over",4,0,FONT_8X8, BLUE); |
rpatel397 | 6:4bc137ec1022 | 88 | |
rpatel397 | 3:6f639d41aef3 | 89 | uLCD.text_width(1); |
rpatel397 | 3:6f639d41aef3 | 90 | uLCD.text_height(1); |
rpatel397 | 6:4bc137ec1022 | 91 | uLCD.color(YELLOW); |
rpatel397 | 6:4bc137ec1022 | 92 | uLCD.locate(2,3); |
rpatel397 | 6:4bc137ec1022 | 93 | uLCD.printf("Score:%d", score); |
rpatel397 | 6:4bc137ec1022 | 94 | |
rpatel397 | 6:4bc137ec1022 | 95 | uLCD.color(GREEN); |
rpatel397 | 6:4bc137ec1022 | 96 | uLCD.locate(2,5); |
rpatel397 | 6:4bc137ec1022 | 97 | uLCD.printf("Hits:%d", hits); |
rpatel397 | 6:4bc137ec1022 | 98 | |
rpatel397 | 6:4bc137ec1022 | 99 | uLCD.color(RED); |
rpatel397 | 6:4bc137ec1022 | 100 | uLCD.locate(2,7); |
rpatel397 | 6:4bc137ec1022 | 101 | uLCD.printf("Misses:%d", misses); |
rpatel397 | 3:6f639d41aef3 | 102 | uLCD.text_height(2); |
rpatel397 | 6:4bc137ec1022 | 103 | |
rpatel397 | 6:4bc137ec1022 | 104 | uLCD.color(WHITE); |
rpatel397 | 6:4bc137ec1022 | 105 | uLCD.text_underline(ON); |
rpatel397 | 6:4bc137ec1022 | 106 | uLCD.text_string("High Score",4,5,FONT_8X8, WHITE); |
rpatel397 | 6:4bc137ec1022 | 107 | uLCD.text_underline(OFF); |
rpatel397 | 6:4bc137ec1022 | 108 | uLCD.text_height(1); |
rpatel397 | 6:4bc137ec1022 | 109 | uLCD.locate(4,13); |
rpatel397 | 6:4bc137ec1022 | 110 | uLCD.text_height(2); |
rpatel397 | 6:4bc137ec1022 | 111 | uLCD.printf("%d", high_score); |
rpatel397 | 3:6f639d41aef3 | 112 | uLCD.text_height(1); |
rpatel397 | 3:6f639d41aef3 | 113 | |
rpatel397 | 3:6f639d41aef3 | 114 | lcd_mut.unlock(); |
rpatel397 | 3:6f639d41aef3 | 115 | } |
rpatel397 | 3:6f639d41aef3 | 116 | break; |
rpatel397 | 3:6f639d41aef3 | 117 | case Choose_Song : |
rpatel397 | 3:6f639d41aef3 | 118 | if (draw_enable) { |
rpatel397 | 3:6f639d41aef3 | 119 | draw_enable = false; |
rpatel397 | 3:6f639d41aef3 | 120 | lcd_mut.lock(); |
rpatel397 | 3:6f639d41aef3 | 121 | uLCD.cls(); |
rpatel397 | 3:6f639d41aef3 | 122 | uLCD.text_width(1); |
rpatel397 | 3:6f639d41aef3 | 123 | uLCD.text_height(1); |
rpatel397 | 3:6f639d41aef3 | 124 | uLCD.locate(1,1); |
rpatel397 | 3:6f639d41aef3 | 125 | uLCD.color(BLUE); |
rpatel397 | 3:6f639d41aef3 | 126 | uLCD.text_underline(ON); |
rpatel397 | 3:6f639d41aef3 | 127 | uLCD.text_string("Choose Song",4,1,FONT_8X8, BLUE); |
rpatel397 | 3:6f639d41aef3 | 128 | uLCD.text_underline(OFF); |
rpatel397 | 3:6f639d41aef3 | 129 | uLCD.set_font(FONT_7X8); |
rpatel397 | 3:6f639d41aef3 | 130 | uLCD.triangle(64, 32,58, 40, 70, 40, WHITE); |
rpatel397 | 3:6f639d41aef3 | 131 | uLCD.triangle(64, 92 ,58, 84, 70, 84, WHITE); |
rpatel397 | 3:6f639d41aef3 | 132 | uLCD.color(GREEN); |
rpatel397 | 3:6f639d41aef3 | 133 | uLCD.rectangle(10,44,118, 80, LGREY); |
rpatel397 | 3:6f639d41aef3 | 134 | uLCD.text_width(2); |
rpatel397 | 3:6f639d41aef3 | 135 | uLCD.text_height(2); |
rpatel397 | 3:6f639d41aef3 | 136 | uLCD.text_string("Schools\nOut",1,3,FONT_8X8, GREEN); |
rpatel397 | 3:6f639d41aef3 | 137 | uLCD.text_width(1); |
rpatel397 | 3:6f639d41aef3 | 138 | uLCD.text_height(1); |
rpatel397 | 3:6f639d41aef3 | 139 | lcd_mut.unlock(); |
rpatel397 | 3:6f639d41aef3 | 140 | } |
rpatel397 | 3:6f639d41aef3 | 141 | break; |
rpatel397 | 3:6f639d41aef3 | 142 | case Choose_Difficulty : |
rpatel397 | 3:6f639d41aef3 | 143 | if (draw_enable) { |
rpatel397 | 3:6f639d41aef3 | 144 | draw_enable = false; |
rpatel397 | 3:6f639d41aef3 | 145 | lcd_mut.lock(); |
rpatel397 | 3:6f639d41aef3 | 146 | uLCD.cls(); |
rpatel397 | 3:6f639d41aef3 | 147 | uLCD.text_width(1.5); |
rpatel397 | 3:6f639d41aef3 | 148 | uLCD.text_height(1.5); |
rpatel397 | 3:6f639d41aef3 | 149 | uLCD.locate(1,1); |
rpatel397 | 3:6f639d41aef3 | 150 | uLCD.color(BLUE); |
rpatel397 | 3:6f639d41aef3 | 151 | uLCD.text_underline(ON); |
rpatel397 | 3:6f639d41aef3 | 152 | uLCD.text_string("Choose Difficulty",1,1,FONT_8X8, BLUE); |
rpatel397 | 3:6f639d41aef3 | 153 | uLCD.text_underline(OFF); |
rpatel397 | 3:6f639d41aef3 | 154 | uLCD.set_font(FONT_7X8); |
rpatel397 | 3:6f639d41aef3 | 155 | uLCD.text_width(2); |
rpatel397 | 3:6f639d41aef3 | 156 | uLCD.text_height(2); |
rpatel397 | 3:6f639d41aef3 | 157 | uLCD.color(GREEN); |
rpatel397 | 3:6f639d41aef3 | 158 | uLCD.locate(1,2); |
rpatel397 | 3:6f639d41aef3 | 159 | uLCD.printf("1|EASY"); |
rpatel397 | 3:6f639d41aef3 | 160 | uLCD.locate(1,4); |
rpatel397 | 3:6f639d41aef3 | 161 | uLCD.color(YELLOW); |
rpatel397 | 3:6f639d41aef3 | 162 | |
rpatel397 | 3:6f639d41aef3 | 163 | uLCD.printf("2|MEDIUM"); |
rpatel397 | 3:6f639d41aef3 | 164 | uLCD.locate(1,6); |
rpatel397 | 3:6f639d41aef3 | 165 | uLCD.color(RED); |
rpatel397 | 3:6f639d41aef3 | 166 | uLCD.printf("3|HARD"); |
rpatel397 | 3:6f639d41aef3 | 167 | uLCD.text_width(1); |
rpatel397 | 3:6f639d41aef3 | 168 | uLCD.text_height(1); |
rpatel397 | 3:6f639d41aef3 | 169 | lcd_mut.unlock(); |
rpatel397 | 3:6f639d41aef3 | 170 | } |
rpatel397 | 3:6f639d41aef3 | 171 | break; |
rpatel397 | 3:6f639d41aef3 | 172 | case Main_Menu : |
rpatel397 | 3:6f639d41aef3 | 173 | if (draw_enable) { |
rpatel397 | 3:6f639d41aef3 | 174 | draw_enable = false; |
rpatel397 | 3:6f639d41aef3 | 175 | lcd_mut.lock(); |
rpatel397 | 3:6f639d41aef3 | 176 | uLCD.cls(); |
rpatel397 | 3:6f639d41aef3 | 177 | uLCD.line(0, 0, 127, 0, RED); |
rpatel397 | 3:6f639d41aef3 | 178 | uLCD.line(127, 0, 127, 127, BLUE); |
rpatel397 | 3:6f639d41aef3 | 179 | uLCD.line(127, 127, 0, 127, GREEN); |
rpatel397 | 3:6f639d41aef3 | 180 | uLCD.line(0, 127, 0, 0, YELLOW); |
rpatel397 | 3:6f639d41aef3 | 181 | uLCD.text_width(2); |
rpatel397 | 3:6f639d41aef3 | 182 | uLCD.text_height(2); |
rpatel397 | 3:6f639d41aef3 | 183 | uLCD.locate(2,2); |
rpatel397 | 3:6f639d41aef3 | 184 | uLCD.color(RED); |
rpatel397 | 3:6f639d41aef3 | 185 | uLCD.printf("Guitar"); |
rpatel397 | 3:6f639d41aef3 | 186 | uLCD.color(BLUE); |
rpatel397 | 3:6f639d41aef3 | 187 | uLCD.locate(3,4); |
rpatel397 | 3:6f639d41aef3 | 188 | uLCD.printf("Hero"); |
rpatel397 | 3:6f639d41aef3 | 189 | |
rpatel397 | 3:6f639d41aef3 | 190 | uLCD.text_width(1); |
rpatel397 | 3:6f639d41aef3 | 191 | uLCD.text_height(1); |
rpatel397 | 3:6f639d41aef3 | 192 | uLCD.locate(3,12); |
rpatel397 | 3:6f639d41aef3 | 193 | uLCD.color(GREEN); |
rpatel397 | 3:6f639d41aef3 | 194 | uLCD.printf("Press to start"); |
rpatel397 | 3:6f639d41aef3 | 195 | |
rpatel397 | 3:6f639d41aef3 | 196 | lcd_mut.unlock(); |
rpatel397 | 3:6f639d41aef3 | 197 | } |
rpatel397 | 3:6f639d41aef3 | 198 | break; |
rpatel397 | 3:6f639d41aef3 | 199 | default: |
rpatel397 | 3:6f639d41aef3 | 200 | break; |
rpatel397 | 3:6f639d41aef3 | 201 | } |
rpatel397 | 3:6f639d41aef3 | 202 | Thread::wait(10); |
rpatel397 | 3:6f639d41aef3 | 203 | } |
rpatel397 | 3:6f639d41aef3 | 204 | } |
rpatel397 | 3:6f639d41aef3 | 205 | void lights(void const *args) { |
rpatel397 | 3:6f639d41aef3 | 206 | while(1) { |
rpatel397 | 3:6f639d41aef3 | 207 | switch (Game_State) { |
rpatel397 | 3:6f639d41aef3 | 208 | case Start_Game : |
rpatel397 | 3:6f639d41aef3 | 209 | myled1 = 0; |
rpatel397 | 3:6f639d41aef3 | 210 | myled2 = 0; |
rpatel397 | 3:6f639d41aef3 | 211 | myled3 = 0; |
rpatel397 | 3:6f639d41aef3 | 212 | myled4 = 1; |
rpatel397 | 3:6f639d41aef3 | 213 | break; |
rpatel397 | 3:6f639d41aef3 | 214 | case Game_Over : |
rpatel397 | 3:6f639d41aef3 | 215 | myled1 = 1; |
rpatel397 | 3:6f639d41aef3 | 216 | myled2 = 1; |
rpatel397 | 3:6f639d41aef3 | 217 | myled3 = 1; |
rpatel397 | 3:6f639d41aef3 | 218 | myled4 = 1; |
rpatel397 | 3:6f639d41aef3 | 219 | break; |
rpatel397 | 3:6f639d41aef3 | 220 | case Choose_Song : |
rpatel397 | 3:6f639d41aef3 | 221 | myled1 = 0; |
rpatel397 | 3:6f639d41aef3 | 222 | myled2 = 0; |
rpatel397 | 3:6f639d41aef3 | 223 | myled3 = 1; |
rpatel397 | 3:6f639d41aef3 | 224 | myled4 = 0; |
rpatel397 | 3:6f639d41aef3 | 225 | break; |
rpatel397 | 3:6f639d41aef3 | 226 | case Choose_Difficulty : |
rpatel397 | 3:6f639d41aef3 | 227 | |
rpatel397 | 3:6f639d41aef3 | 228 | myled1 = 0; |
rpatel397 | 3:6f639d41aef3 | 229 | myled2 = 1; |
rpatel397 | 3:6f639d41aef3 | 230 | myled3 = 0; |
rpatel397 | 3:6f639d41aef3 | 231 | myled4 = 0; |
rpatel397 | 3:6f639d41aef3 | 232 | |
rpatel397 | 3:6f639d41aef3 | 233 | |
rpatel397 | 3:6f639d41aef3 | 234 | break; |
rpatel397 | 3:6f639d41aef3 | 235 | case Main_Menu : |
rpatel397 | 3:6f639d41aef3 | 236 | |
rpatel397 | 3:6f639d41aef3 | 237 | myled1 = 1; |
rpatel397 | 3:6f639d41aef3 | 238 | myled2 = 0; |
rpatel397 | 3:6f639d41aef3 | 239 | myled3 = 0; |
rpatel397 | 3:6f639d41aef3 | 240 | myled4 = 0; |
rpatel397 | 3:6f639d41aef3 | 241 | |
rpatel397 | 3:6f639d41aef3 | 242 | break; |
rpatel397 | 3:6f639d41aef3 | 243 | default: |
rpatel397 | 3:6f639d41aef3 | 244 | break; |
rpatel397 | 3:6f639d41aef3 | 245 | } |
rpatel397 | 3:6f639d41aef3 | 246 | Thread::wait(500); |
rpatel397 | 3:6f639d41aef3 | 247 | } |
rpatel397 | 3:6f639d41aef3 | 248 | } |
4180_1 | 1:5b8e223e983d | 249 | |
rpatel397 | 3:6f639d41aef3 | 250 | void Thread3(void const *args) { |
rpatel397 | 3:6f639d41aef3 | 251 | |
rpatel397 | 3:6f639d41aef3 | 252 | while(1) { |
rpatel397 | 3:6f639d41aef3 | 253 | Thread::wait(1000); |
rpatel397 | 3:6f639d41aef3 | 254 | } |
rpatel397 | 3:6f639d41aef3 | 255 | |
rpatel397 | 3:6f639d41aef3 | 256 | } |
rpatel397 | 3:6f639d41aef3 | 257 | |
rpatel397 | 3:6f639d41aef3 | 258 | void Thread4(void const *args) { |
rpatel397 | 3:6f639d41aef3 | 259 | |
rpatel397 | 3:6f639d41aef3 | 260 | while(1){ |
rpatel397 | 3:6f639d41aef3 | 261 | Thread::wait(1000); |
rpatel397 | 3:6f639d41aef3 | 262 | } |
rpatel397 | 3:6f639d41aef3 | 263 | |
rpatel397 | 3:6f639d41aef3 | 264 | } |
rpatel397 | 5:2f09b457f690 | 265 | void startGame() { |
rpatel397 | 5:2f09b457f690 | 266 | Game_State = Start_Game; |
rpatel397 | 5:2f09b457f690 | 267 | sampletick.attach(&audio_sample, 1.0 / sample_freq); |
rpatel397 | 5:2f09b457f690 | 268 | } |
4180_1 | 1:5b8e223e983d | 269 | |
rpatel397 | 3:6f639d41aef3 | 270 | void pb_1_pressed(void) { |
rpatel397 | 3:6f639d41aef3 | 271 | switch (Game_State) { |
rpatel397 | 3:6f639d41aef3 | 272 | case Start_Game : |
rpatel397 | 3:6f639d41aef3 | 273 | draw_enable = true; |
rpatel397 | 3:6f639d41aef3 | 274 | break; |
rpatel397 | 3:6f639d41aef3 | 275 | case Game_Over : |
rpatel397 | 3:6f639d41aef3 | 276 | draw_enable = true; |
rpatel397 | 3:6f639d41aef3 | 277 | Game_State = Main_Menu; |
rpatel397 | 3:6f639d41aef3 | 278 | break; |
rpatel397 | 3:6f639d41aef3 | 279 | case Choose_Song : |
rpatel397 | 3:6f639d41aef3 | 280 | draw_enable = true; |
rpatel397 | 5:2f09b457f690 | 281 | startGame(); |
rpatel397 | 3:6f639d41aef3 | 282 | break; |
rpatel397 | 3:6f639d41aef3 | 283 | case Choose_Difficulty : |
rpatel397 | 3:6f639d41aef3 | 284 | |
rpatel397 | 3:6f639d41aef3 | 285 | draw_enable = true; |
rpatel397 | 3:6f639d41aef3 | 286 | Game_State = Choose_Song; |
rpatel397 | 3:6f639d41aef3 | 287 | Speed = Easy; |
rpatel397 | 3:6f639d41aef3 | 288 | |
rpatel397 | 3:6f639d41aef3 | 289 | break; |
rpatel397 | 3:6f639d41aef3 | 290 | case Main_Menu : |
rpatel397 | 3:6f639d41aef3 | 291 | |
rpatel397 | 3:6f639d41aef3 | 292 | draw_enable = true; |
rpatel397 | 3:6f639d41aef3 | 293 | Game_State = Choose_Difficulty; |
rpatel397 | 3:6f639d41aef3 | 294 | |
rpatel397 | 3:6f639d41aef3 | 295 | break; |
rpatel397 | 3:6f639d41aef3 | 296 | default: |
rpatel397 | 3:6f639d41aef3 | 297 | break; |
rpatel397 | 3:6f639d41aef3 | 298 | } |
rpatel397 | 3:6f639d41aef3 | 299 | } |
rpatel397 | 3:6f639d41aef3 | 300 | void pb_2_pressed(void) { |
rpatel397 | 3:6f639d41aef3 | 301 | switch (Game_State) { |
rpatel397 | 3:6f639d41aef3 | 302 | case Start_Game : |
rpatel397 | 3:6f639d41aef3 | 303 | draw_enable = true; |
rpatel397 | 3:6f639d41aef3 | 304 | break; |
rpatel397 | 3:6f639d41aef3 | 305 | case Game_Over : |
rpatel397 | 3:6f639d41aef3 | 306 | draw_enable = true; |
rpatel397 | 3:6f639d41aef3 | 307 | Game_State = Main_Menu; |
rpatel397 | 3:6f639d41aef3 | 308 | break; |
rpatel397 | 3:6f639d41aef3 | 309 | case Choose_Song : |
rpatel397 | 3:6f639d41aef3 | 310 | draw_enable = true; |
rpatel397 | 5:2f09b457f690 | 311 | startGame(); |
rpatel397 | 3:6f639d41aef3 | 312 | break; |
rpatel397 | 3:6f639d41aef3 | 313 | case Choose_Difficulty : |
rpatel397 | 3:6f639d41aef3 | 314 | |
rpatel397 | 3:6f639d41aef3 | 315 | draw_enable = true; |
rpatel397 | 3:6f639d41aef3 | 316 | Game_State = Choose_Song; |
rpatel397 | 3:6f639d41aef3 | 317 | Speed = Medium; |
rpatel397 | 3:6f639d41aef3 | 318 | break; |
rpatel397 | 3:6f639d41aef3 | 319 | case Main_Menu : |
rpatel397 | 3:6f639d41aef3 | 320 | |
rpatel397 | 3:6f639d41aef3 | 321 | draw_enable = true; |
rpatel397 | 3:6f639d41aef3 | 322 | Game_State = Choose_Difficulty; |
rpatel397 | 3:6f639d41aef3 | 323 | |
rpatel397 | 3:6f639d41aef3 | 324 | break; |
rpatel397 | 3:6f639d41aef3 | 325 | default: |
rpatel397 | 3:6f639d41aef3 | 326 | break; |
rpatel397 | 3:6f639d41aef3 | 327 | } |
rpatel397 | 3:6f639d41aef3 | 328 | |
rpatel397 | 3:6f639d41aef3 | 329 | } |
rpatel397 | 3:6f639d41aef3 | 330 | void pb_3_pressed(void) { |
rpatel397 | 3:6f639d41aef3 | 331 | switch (Game_State) { |
rpatel397 | 3:6f639d41aef3 | 332 | case Start_Game : |
rpatel397 | 3:6f639d41aef3 | 333 | draw_enable = true; |
rpatel397 | 3:6f639d41aef3 | 334 | break; |
rpatel397 | 3:6f639d41aef3 | 335 | case Game_Over : |
rpatel397 | 3:6f639d41aef3 | 336 | draw_enable = true; |
rpatel397 | 3:6f639d41aef3 | 337 | Game_State = Main_Menu; |
rpatel397 | 3:6f639d41aef3 | 338 | break; |
rpatel397 | 3:6f639d41aef3 | 339 | case Choose_Song : |
rpatel397 | 3:6f639d41aef3 | 340 | draw_enable = true; |
rpatel397 | 5:2f09b457f690 | 341 | startGame(); |
rpatel397 | 3:6f639d41aef3 | 342 | break; |
rpatel397 | 3:6f639d41aef3 | 343 | case Choose_Difficulty : |
rpatel397 | 3:6f639d41aef3 | 344 | |
rpatel397 | 3:6f639d41aef3 | 345 | draw_enable = true; |
rpatel397 | 3:6f639d41aef3 | 346 | Game_State = Choose_Song; |
rpatel397 | 3:6f639d41aef3 | 347 | Speed = Hard; |
rpatel397 | 3:6f639d41aef3 | 348 | |
rpatel397 | 3:6f639d41aef3 | 349 | break; |
rpatel397 | 3:6f639d41aef3 | 350 | case Main_Menu : |
rpatel397 | 3:6f639d41aef3 | 351 | |
rpatel397 | 3:6f639d41aef3 | 352 | draw_enable = true; |
rpatel397 | 3:6f639d41aef3 | 353 | Game_State = Choose_Difficulty; |
rpatel397 | 3:6f639d41aef3 | 354 | |
rpatel397 | 3:6f639d41aef3 | 355 | break; |
rpatel397 | 3:6f639d41aef3 | 356 | default: |
rpatel397 | 3:6f639d41aef3 | 357 | break; |
rpatel397 | 3:6f639d41aef3 | 358 | } |
rpatel397 | 3:6f639d41aef3 | 359 | } |
rpatel397 | 3:6f639d41aef3 | 360 | void pb_4_pressed(void) { |
rpatel397 | 3:6f639d41aef3 | 361 | switch (Game_State) { |
rpatel397 | 3:6f639d41aef3 | 362 | case Start_Game : |
rpatel397 | 3:6f639d41aef3 | 363 | draw_enable = true; |
rpatel397 | 3:6f639d41aef3 | 364 | break; |
rpatel397 | 3:6f639d41aef3 | 365 | case Game_Over : |
rpatel397 | 3:6f639d41aef3 | 366 | draw_enable = true; |
rpatel397 | 3:6f639d41aef3 | 367 | Game_State = Main_Menu; |
rpatel397 | 3:6f639d41aef3 | 368 | break; |
rpatel397 | 3:6f639d41aef3 | 369 | case Choose_Song : |
rpatel397 | 3:6f639d41aef3 | 370 | draw_enable = true; |
rpatel397 | 5:2f09b457f690 | 371 | startGame(); |
rpatel397 | 3:6f639d41aef3 | 372 | break; |
rpatel397 | 3:6f639d41aef3 | 373 | case Choose_Difficulty : |
rpatel397 | 3:6f639d41aef3 | 374 | //not used |
rpatel397 | 3:6f639d41aef3 | 375 | break; |
rpatel397 | 3:6f639d41aef3 | 376 | case Main_Menu : |
rpatel397 | 3:6f639d41aef3 | 377 | |
rpatel397 | 3:6f639d41aef3 | 378 | draw_enable = true; |
rpatel397 | 3:6f639d41aef3 | 379 | Game_State = Choose_Difficulty; |
rpatel397 | 3:6f639d41aef3 | 380 | |
rpatel397 | 3:6f639d41aef3 | 381 | break; |
rpatel397 | 3:6f639d41aef3 | 382 | default: |
rpatel397 | 3:6f639d41aef3 | 383 | break; |
rpatel397 | 3:6f639d41aef3 | 384 | } |
rpatel397 | 3:6f639d41aef3 | 385 | } |
rpatel397 | 3:6f639d41aef3 | 386 | |
4180_1 | 1:5b8e223e983d | 387 | int main() |
4180_1 | 1:5b8e223e983d | 388 | { |
rpatel397 | 5:2f09b457f690 | 389 | speaker.write_u16(0); |
rpatel397 | 3:6f639d41aef3 | 390 | pb_1.attach_deasserted( &pb_1_pressed ); |
rpatel397 | 3:6f639d41aef3 | 391 | pb_2.attach_deasserted( &pb_2_pressed ); |
rpatel397 | 3:6f639d41aef3 | 392 | pb_3.attach_deasserted( &pb_3_pressed ); |
rpatel397 | 3:6f639d41aef3 | 393 | pb_4.attach_deasserted( &pb_4_pressed ); |
rpatel397 | 3:6f639d41aef3 | 394 | pb_1.setSampleFrequency(); |
rpatel397 | 3:6f639d41aef3 | 395 | pb_2.setSampleFrequency(); |
rpatel397 | 3:6f639d41aef3 | 396 | pb_3.setSampleFrequency(); |
rpatel397 | 3:6f639d41aef3 | 397 | pb_4.setSampleFrequency(); |
rpatel397 | 3:6f639d41aef3 | 398 | lcd_mut.lock(); |
rpatel397 | 3:6f639d41aef3 | 399 | uLCD.cls(); |
rpatel397 | 3:6f639d41aef3 | 400 | uLCD.printf("starting..."); |
rpatel397 | 3:6f639d41aef3 | 401 | uLCD.background_color(BLACK); |
rpatel397 | 3:6f639d41aef3 | 402 | uLCD.baudrate(3000000); |
rpatel397 | 3:6f639d41aef3 | 403 | lcd_mut.unlock(); |
4180_1 | 2:c2afd0c426af | 404 | Thread::wait(1000); |
rpatel397 | 3:6f639d41aef3 | 405 | Thread Thread1(LCD); |
rpatel397 | 3:6f639d41aef3 | 406 | Thread Thread2(lights); |
rpatel397 | 3:6f639d41aef3 | 407 | |
rpatel397 | 3:6f639d41aef3 | 408 | |
rpatel397 | 3:6f639d41aef3 | 409 | while(1) { |
rpatel397 | 3:6f639d41aef3 | 410 | Thread::wait(1000); |
rpatel397 | 3:6f639d41aef3 | 411 | } |
rpatel397 | 3:6f639d41aef3 | 412 | |
rpatel397 | 3:6f639d41aef3 | 413 | } |