![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
ECE 4180 Final
Dependencies: mbed wave_player mbed-rtos C12832_lcd 4DGL-uLCD-SE LCD_fonts SDFileSystem
main.cpp@20:7d56cdcbc9a5, 2019-12-06 (annotated)
- Committer:
- jcrane32
- Date:
- Fri Dec 06 18:00:11 2019 +0000
- Revision:
- 20:7d56cdcbc9a5
- Parent:
- 19:d65f9fb1023b
- Parent:
- 17:13e45fdcf0b0
- Child:
- 21:cbcbb3480cad
TODO: fix status LED (tracks bubblesMissed) and add in scoreboard at the end.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yqin70 | 0:4f77ae831ee7 | 1 | #include "mbed.h" |
jcrane32 | 7:15fdc55dbf66 | 2 | #include "rtos.h" |
jcrane32 | 19:d65f9fb1023b | 3 | #include "stdio.h" |
jcrane32 | 20:7d56cdcbc9a5 | 4 | #include <stdlib.h> |
jcrane32 | 20:7d56cdcbc9a5 | 5 | #include <time.h> |
yqin70 | 0:4f77ae831ee7 | 6 | #include "SDFileSystem.h" |
yqin70 | 0:4f77ae831ee7 | 7 | #include "wave_player.h" |
ShelbyC22 | 16:13b65f6139be | 8 | #include "mpr121.h" |
jcrane32 | 6:cd24147b5e50 | 9 | |
yqin70 | 0:4f77ae831ee7 | 10 | #include "uLCD_4DGL.h" |
yqin70 | 0:4f77ae831ee7 | 11 | #include "Small_6.h" |
yqin70 | 0:4f77ae831ee7 | 12 | #include "Small_7.h" |
yqin70 | 0:4f77ae831ee7 | 13 | #include "Arial_9.h" |
yqin70 | 0:4f77ae831ee7 | 14 | #include "C12832_lcd.h" |
yqin70 | 0:4f77ae831ee7 | 15 | |
jcrane32 | 19:d65f9fb1023b | 16 | #include "globals.h" |
jcrane32 | 19:d65f9fb1023b | 17 | |
jcrane32 | 20:7d56cdcbc9a5 | 18 | //#include "bubbles.h" |
yqin70 | 11:362e25f659a5 | 19 | #include "stacys_mom.h" |
jcrane32 | 19:d65f9fb1023b | 20 | //#include "the_middle.h" |
yqin70 | 11:362e25f659a5 | 21 | #include "fireflies.h" |
yqin70 | 11:362e25f659a5 | 22 | #include "sins.h" |
jcrane32 | 7:15fdc55dbf66 | 23 | #include "LED.hpp" |
jcrane32 | 6:cd24147b5e50 | 24 | |
jcrane32 | 19:d65f9fb1023b | 25 | #include "Lane.hpp" |
jcrane32 | 19:d65f9fb1023b | 26 | #include "Bubble.hpp" |
jcrane32 | 19:d65f9fb1023b | 27 | |
jcrane32 | 19:d65f9fb1023b | 28 | |
yqin70 | 0:4f77ae831ee7 | 29 | //Setup RGB led using PWM pins and class |
ShelbyC22 | 4:59b73f321c0e | 30 | RGBLed myRGBled(p24,p23,p22); //RGB PWM pins |
yqin70 | 0:4f77ae831ee7 | 31 | char bred=0; |
yqin70 | 0:4f77ae831ee7 | 32 | char bgreen=0; |
yqin70 | 0:4f77ae831ee7 | 33 | char bblue=0; |
yqin70 | 0:4f77ae831ee7 | 34 | |
yqin70 | 0:4f77ae831ee7 | 35 | volatile bool songselect = false; |
yqin70 | 0:4f77ae831ee7 | 36 | volatile bool homescreen = true; |
ShelbyC22 | 5:b2cf15651d4e | 37 | volatile bool songchange = false; |
jcrane32 | 7:15fdc55dbf66 | 38 | volatile bool playing = false; |
jcrane32 | 7:15fdc55dbf66 | 39 | uLCD_4DGL uLCD(p28,p27,p30); |
yqin70 | 0:4f77ae831ee7 | 40 | SDFileSystem sd(p5, p6, p7, p8, "sd"); //SD card |
jcrane32 | 19:d65f9fb1023b | 41 | AnalogIn joy_pot(p16); |
yqin70 | 0:4f77ae831ee7 | 42 | DigitalOut myled(LED1); |
yqin70 | 0:4f77ae831ee7 | 43 | DigitalIn pb1(p20); |
yqin70 | 0:4f77ae831ee7 | 44 | DigitalIn pb2(p19); |
yqin70 | 1:a1aa9a79070a | 45 | AnalogOut DACout(p18); |
ShelbyC22 | 16:13b65f6139be | 46 | // Create the interrupt receiver object on pin 26 for touch pad IRQ |
ShelbyC22 | 16:13b65f6139be | 47 | InterruptIn interrupt(p26); |
ShelbyC22 | 16:13b65f6139be | 48 | // Setup the i2c bus on pins 9 and 10 |
ShelbyC22 | 16:13b65f6139be | 49 | I2C i2c(p9, p10); |
ShelbyC22 | 16:13b65f6139be | 50 | // Setup the Mpr121: |
ShelbyC22 | 16:13b65f6139be | 51 | // constructor(i2c object, i2c address of the mpr121) |
ShelbyC22 | 16:13b65f6139be | 52 | Mpr121 mpr121(&i2c, Mpr121::ADD_VSS); |
ShelbyC22 | 16:13b65f6139be | 53 | |
ShelbyC22 | 16:13b65f6139be | 54 | // Key hit/release interrupt routine |
jcrane32 | 20:7d56cdcbc9a5 | 55 | //void fallInterrupt() { |
jcrane32 | 20:7d56cdcbc9a5 | 56 | // int key_code=0; |
jcrane32 | 20:7d56cdcbc9a5 | 57 | // int i=0; |
jcrane32 | 20:7d56cdcbc9a5 | 58 | // int value=mpr121.read(0x00); |
jcrane32 | 20:7d56cdcbc9a5 | 59 | // value +=mpr121.read(0x01)<<8; |
jcrane32 | 20:7d56cdcbc9a5 | 60 | // for (i=0; i<12; i++) { |
jcrane32 | 20:7d56cdcbc9a5 | 61 | // if (((value>>i)&0x01)==1) { |
jcrane32 | 20:7d56cdcbc9a5 | 62 | // key_code=i+1; |
jcrane32 | 20:7d56cdcbc9a5 | 63 | // } |
jcrane32 | 20:7d56cdcbc9a5 | 64 | // } |
jcrane32 | 20:7d56cdcbc9a5 | 65 | //} |
ShelbyC22 | 16:13b65f6139be | 66 | |
yqin70 | 1:a1aa9a79070a | 67 | wave_player waver(&DACout); |
jcrane32 | 19:d65f9fb1023b | 68 | Thread thread1, thread2, thread3, thread4; |
jcrane32 | 19:d65f9fb1023b | 69 | |
jcrane32 | 7:15fdc55dbf66 | 70 | Ticker nextsample; |
jcrane32 | 19:d65f9fb1023b | 71 | volatile int songNdx = 0; |
jcrane32 | 19:d65f9fb1023b | 72 | unsigned char *playingSong = NULL; |
yqin70 | 0:4f77ae831ee7 | 73 | |
yqin70 | 0:4f77ae831ee7 | 74 | // mutex to make the lcd lib thread safe |
yqin70 | 0:4f77ae831ee7 | 75 | Mutex lcd_mutex; |
yqin70 | 0:4f77ae831ee7 | 76 | int songnum = 1; |
jcrane32 | 19:d65f9fb1023b | 77 | |
jcrane32 | 19:d65f9fb1023b | 78 | unsigned short **currentBubbles = NULL; |
jcrane32 | 19:d65f9fb1023b | 79 | int bubbleNdx = 0; |
jcrane32 | 20:7d56cdcbc9a5 | 80 | volatile int bubblesDrawn = 0; |
jcrane32 | 20:7d56cdcbc9a5 | 81 | volatile int bubblesMissed = 0; |
jcrane32 | 19:d65f9fb1023b | 82 | |
jcrane32 | 19:d65f9fb1023b | 83 | |
jcrane32 | 6:cd24147b5e50 | 84 | |
yqin70 | 0:4f77ae831ee7 | 85 | // Thread 1 |
yqin70 | 1:a1aa9a79070a | 86 | // print homescreen to LCD |
jcrane32 | 6:cd24147b5e50 | 87 | void homescreen_thread() |
yqin70 | 0:4f77ae831ee7 | 88 | { |
jcrane32 | 19:d65f9fb1023b | 89 | while (true) { // thread loop |
ShelbyC22 | 5:b2cf15651d4e | 90 | lcd_mutex.lock(); |
yqin70 | 0:4f77ae831ee7 | 91 | if (homescreen){ |
yqin70 | 0:4f77ae831ee7 | 92 | uLCD.cls(); |
ShelbyC22 | 5:b2cf15651d4e | 93 | uLCD.text_height(1.3); |
yqin70 | 2:765774781bb1 | 94 | uLCD.text_width(1.9); |
yqin70 | 0:4f77ae831ee7 | 95 | uLCD.color(WHITE); |
ShelbyC22 | 5:b2cf15651d4e | 96 | uLCD.locate(5,0); |
ShelbyC22 | 5:b2cf15651d4e | 97 | uLCD.printf("Tap Tap"); |
ShelbyC22 | 5:b2cf15651d4e | 98 | uLCD.locate(4,1); |
ShelbyC22 | 5:b2cf15651d4e | 99 | uLCD.printf("Revolution"); |
ShelbyC22 | 5:b2cf15651d4e | 100 | uLCD.locate(0,3); |
jcrane32 | 7:15fdc55dbf66 | 101 | uLCD.printf("Pick a song!"); |
ShelbyC22 | 5:b2cf15651d4e | 102 | uLCD.text_height(1.3); |
yqin70 | 2:765774781bb1 | 103 | uLCD.text_width(1.9); |
ShelbyC22 | 5:b2cf15651d4e | 104 | uLCD.locate(3,5); |
ShelbyC22 | 4:59b73f321c0e | 105 | uLCD.printf("Fireflies"); |
ShelbyC22 | 5:b2cf15651d4e | 106 | uLCD.locate(3,7); |
jcrane32 | 19:d65f9fb1023b | 107 | uLCD.printf("Stacy's Mom"); |
ShelbyC22 | 5:b2cf15651d4e | 108 | uLCD.locate(3,9); |
jcrane32 | 7:15fdc55dbf66 | 109 | uLCD.printf("I Write Sins \n \t Not Tragedies"); |
jcrane32 | 19:d65f9fb1023b | 110 | uLCD.filled_circle(6, 43, 4, WHITE); //new selection with circle instead of rectangle |
jcrane32 | 19:d65f9fb1023b | 111 | homescreen = false; |
jcrane32 | 19:d65f9fb1023b | 112 | } |
jcrane32 | 19:d65f9fb1023b | 113 | if (songchange) { |
jcrane32 | 19:d65f9fb1023b | 114 | for (int i = 0; i < 3; i++){ |
jcrane32 | 19:d65f9fb1023b | 115 | uLCD.filled_circle(6, i*15+43, 4,BLACK); |
ShelbyC22 | 5:b2cf15651d4e | 116 | } |
jcrane32 | 19:d65f9fb1023b | 117 | uLCD.filled_circle(6, (songnum-1)*15+43, 4,WHITE); |
ShelbyC22 | 5:b2cf15651d4e | 118 | songchange = false; |
jcrane32 | 19:d65f9fb1023b | 119 | } |
jcrane32 | 19:d65f9fb1023b | 120 | |
jcrane32 | 19:d65f9fb1023b | 121 | lcd_mutex.unlock(); |
jcrane32 | 20:7d56cdcbc9a5 | 122 | Thread::wait(500); |
yqin70 | 0:4f77ae831ee7 | 123 | } |
yqin70 | 0:4f77ae831ee7 | 124 | } |
yqin70 | 0:4f77ae831ee7 | 125 | |
jcrane32 | 6:cd24147b5e50 | 126 | // Thread 2 |
jcrane32 | 7:15fdc55dbf66 | 127 | // joystick control for song selection during homescreen |
jcrane32 | 19:d65f9fb1023b | 128 | void joystick_thread() { |
jcrane32 | 19:d65f9fb1023b | 129 | while (true) { |
jcrane32 | 19:d65f9fb1023b | 130 | if (!playing) { // we dont want to be able to change the song if we're playing |
yqin70 | 0:4f77ae831ee7 | 131 | if ((joy_pot <= (1.4/3.3)) && songnum>1) { |
jcrane32 | 19:d65f9fb1023b | 132 | songnum--; |
jcrane32 | 19:d65f9fb1023b | 133 | songchange = true; |
jcrane32 | 19:d65f9fb1023b | 134 | } else if ((joy_pot >= (1.8/3.3)) && songnum<3){ |
yqin70 | 0:4f77ae831ee7 | 135 | songnum++; |
ShelbyC22 | 5:b2cf15651d4e | 136 | songchange = true; |
jcrane32 | 19:d65f9fb1023b | 137 | } |
jcrane32 | 19:d65f9fb1023b | 138 | Thread::wait(250); |
jcrane32 | 19:d65f9fb1023b | 139 | } |
jcrane32 | 19:d65f9fb1023b | 140 | |
yqin70 | 0:4f77ae831ee7 | 141 | } |
yqin70 | 0:4f77ae831ee7 | 142 | } |
yqin70 | 0:4f77ae831ee7 | 143 | |
yqin70 | 0:4f77ae831ee7 | 144 | // Thread 3 |
jcrane32 | 19:d65f9fb1023b | 145 | // reads pushbuttons to control menu |
jcrane32 | 6:cd24147b5e50 | 146 | void pbcontrol_thread() |
yqin70 | 0:4f77ae831ee7 | 147 | { |
jcrane32 | 19:d65f9fb1023b | 148 | // The pb variables will be zero when the pushbutton is pressed |
jcrane32 | 19:d65f9fb1023b | 149 | pb1.mode(PullUp); //pb1 is to select song |
jcrane32 | 19:d65f9fb1023b | 150 | pb2.mode(PullUp); //pb2 is to return to homescreen |
yqin70 | 0:4f77ae831ee7 | 151 | while(true) { // thread loop |
jcrane32 | 19:d65f9fb1023b | 152 | if (!pb2) { |
yqin70 | 0:4f77ae831ee7 | 153 | homescreen = true; |
yqin70 | 0:4f77ae831ee7 | 154 | songselect = false; |
jcrane32 | 19:d65f9fb1023b | 155 | playing = false; |
jcrane32 | 19:d65f9fb1023b | 156 | } |
jcrane32 | 19:d65f9fb1023b | 157 | if (!pb1) { |
yqin70 | 0:4f77ae831ee7 | 158 | songselect = true; |
jcrane32 | 19:d65f9fb1023b | 159 | } |
jcrane32 | 19:d65f9fb1023b | 160 | Thread::wait(100); |
yqin70 | 0:4f77ae831ee7 | 161 | } |
yqin70 | 0:4f77ae831ee7 | 162 | } |
yqin70 | 0:4f77ae831ee7 | 163 | |
jcrane32 | 7:15fdc55dbf66 | 164 | // Thread 4 |
jcrane32 | 19:d65f9fb1023b | 165 | // control LED effects |
jcrane32 | 19:d65f9fb1023b | 166 | void LED_thread() { |
jcrane32 | 19:d65f9fb1023b | 167 | while (true) { |
jcrane32 | 19:d65f9fb1023b | 168 | if (!playing) { //spin LED colors at start menu |
jcrane32 | 19:d65f9fb1023b | 169 | myRGBled = red; |
jcrane32 | 19:d65f9fb1023b | 170 | Thread::wait(200); |
jcrane32 | 19:d65f9fb1023b | 171 | myRGBled = yellow; |
jcrane32 | 19:d65f9fb1023b | 172 | Thread::wait(200); |
jcrane32 | 19:d65f9fb1023b | 173 | myRGBled = orange; |
jcrane32 | 19:d65f9fb1023b | 174 | Thread::wait(200); |
jcrane32 | 19:d65f9fb1023b | 175 | myRGBled = blue; |
jcrane32 | 19:d65f9fb1023b | 176 | Thread::wait(200); |
jcrane32 | 19:d65f9fb1023b | 177 | myRGBled = green; |
jcrane32 | 19:d65f9fb1023b | 178 | Thread::wait(200); |
jcrane32 | 19:d65f9fb1023b | 179 | } else if (playing) { |
jcrane32 | 20:7d56cdcbc9a5 | 180 | //lcd_mutex.lock(); |
jcrane32 | 20:7d56cdcbc9a5 | 181 | // uLCD.printf("%d", bubblesMissed); |
jcrane32 | 20:7d56cdcbc9a5 | 182 | // lcd_mutex.unlock(); |
jcrane32 | 20:7d56cdcbc9a5 | 183 | if (bubblesMissed <= 1) { |
jcrane32 | 19:d65f9fb1023b | 184 | myRGBled = green; |
jcrane32 | 20:7d56cdcbc9a5 | 185 | } else if (bubblesMissed <= 3) { |
jcrane32 | 20:7d56cdcbc9a5 | 186 | myRGBled = blue; |
jcrane32 | 19:d65f9fb1023b | 187 | } else { |
jcrane32 | 19:d65f9fb1023b | 188 | myRGBled = red; |
jcrane32 | 19:d65f9fb1023b | 189 | } |
jcrane32 | 19:d65f9fb1023b | 190 | Thread::wait(300); |
jcrane32 | 19:d65f9fb1023b | 191 | |
jcrane32 | 19:d65f9fb1023b | 192 | } |
jcrane32 | 19:d65f9fb1023b | 193 | } |
jcrane32 | 19:d65f9fb1023b | 194 | } |
jcrane32 | 19:d65f9fb1023b | 195 | |
jcrane32 | 19:d65f9fb1023b | 196 | // Thread 5 |
jcrane32 | 7:15fdc55dbf66 | 197 | // this thread plays music using the ticker class |
jcrane32 | 7:15fdc55dbf66 | 198 | void playsound() { |
jcrane32 | 7:15fdc55dbf66 | 199 | if (playing) { |
jcrane32 | 19:d65f9fb1023b | 200 | DACout.write(playingSong[songNdx++] / 255.0); |
jcrane32 | 19:d65f9fb1023b | 201 | if (songNdx>120000) { |
jcrane32 | 19:d65f9fb1023b | 202 | playing = false; |
jcrane32 | 19:d65f9fb1023b | 203 | songNdx = 0; |
jcrane32 | 19:d65f9fb1023b | 204 | } |
jcrane32 | 7:15fdc55dbf66 | 205 | } else { |
jcrane32 | 19:d65f9fb1023b | 206 | DACout.write(0.0); |
jcrane32 | 7:15fdc55dbf66 | 207 | songNdx = 0; |
jcrane32 | 7:15fdc55dbf66 | 208 | } |
jcrane32 | 7:15fdc55dbf66 | 209 | } |
jcrane32 | 7:15fdc55dbf66 | 210 | |
jcrane32 | 19:d65f9fb1023b | 211 | void pickSong() { |
jcrane32 | 19:d65f9fb1023b | 212 | switch (songnum) { |
jcrane32 | 19:d65f9fb1023b | 213 | case 1: |
jcrane32 | 19:d65f9fb1023b | 214 | { |
jcrane32 | 19:d65f9fb1023b | 215 | playingSong = (unsigned char *) fireflies; |
jcrane32 | 19:d65f9fb1023b | 216 | playing = true; |
jcrane32 | 19:d65f9fb1023b | 217 | break; |
jcrane32 | 19:d65f9fb1023b | 218 | } |
jcrane32 | 19:d65f9fb1023b | 219 | |
jcrane32 | 19:d65f9fb1023b | 220 | case 2: |
jcrane32 | 19:d65f9fb1023b | 221 | { |
jcrane32 | 19:d65f9fb1023b | 222 | playingSong = (unsigned char *) stacys_mom; |
jcrane32 | 19:d65f9fb1023b | 223 | playing = true; |
jcrane32 | 19:d65f9fb1023b | 224 | break; |
jcrane32 | 19:d65f9fb1023b | 225 | } |
jcrane32 | 19:d65f9fb1023b | 226 | case 3: |
jcrane32 | 19:d65f9fb1023b | 227 | { |
jcrane32 | 19:d65f9fb1023b | 228 | playingSong = (unsigned char *) sins; |
jcrane32 | 19:d65f9fb1023b | 229 | playing = true; |
jcrane32 | 19:d65f9fb1023b | 230 | break; |
jcrane32 | 19:d65f9fb1023b | 231 | } |
jcrane32 | 19:d65f9fb1023b | 232 | default: |
jcrane32 | 19:d65f9fb1023b | 233 | break; |
jcrane32 | 19:d65f9fb1023b | 234 | } |
jcrane32 | 19:d65f9fb1023b | 235 | } |
jcrane32 | 19:d65f9fb1023b | 236 | |
jcrane32 | 19:d65f9fb1023b | 237 | |
jcrane32 | 19:d65f9fb1023b | 238 | |
jcrane32 | 19:d65f9fb1023b | 239 | void showScore () { |
jcrane32 | 19:d65f9fb1023b | 240 | uLCD.color(0x00FF00); // Change text color and set up menu |
jcrane32 | 19:d65f9fb1023b | 241 | uLCD.text_bold(ON); |
jcrane32 | 19:d65f9fb1023b | 242 | uLCD.locate(1,1); |
jcrane32 | 19:d65f9fb1023b | 243 | uLCD.text_width(2); //4X size text |
jcrane32 | 19:d65f9fb1023b | 244 | uLCD.text_height(2); |
jcrane32 | 19:d65f9fb1023b | 245 | uLCD.printf("Thanks for playing Tap Tap Revolution!"); |
jcrane32 | 19:d65f9fb1023b | 246 | // winSound(); |
jcrane32 | 19:d65f9fb1023b | 247 | wait(1.5); |
jcrane32 | 19:d65f9fb1023b | 248 | |
jcrane32 | 19:d65f9fb1023b | 249 | uLCD.text_width(1); //4X size text |
jcrane32 | 19:d65f9fb1023b | 250 | uLCD.text_height(1); |
jcrane32 | 19:d65f9fb1023b | 251 | uLCD.text_bold(OFF); |
jcrane32 | 19:d65f9fb1023b | 252 | uLCD.color(0xFFFFFF); |
jcrane32 | 19:d65f9fb1023b | 253 | uLCD.locate(2,8); |
jcrane32 | 19:d65f9fb1023b | 254 | uLCD.printf("Your Score:"); |
jcrane32 | 19:d65f9fb1023b | 255 | uLCD.color(0x00FF00); |
jcrane32 | 19:d65f9fb1023b | 256 | uLCD.locate(2,10); |
jcrane32 | 19:d65f9fb1023b | 257 | |
jcrane32 | 19:d65f9fb1023b | 258 | float scorePercent = ((bubblesDrawn - bubblesMissed) / bubblesDrawn) * 100; |
jcrane32 | 19:d65f9fb1023b | 259 | uLCD.printf("%d %", scorePercent); |
jcrane32 | 19:d65f9fb1023b | 260 | wait(1.2); |
yqin70 | 14:6f5432bb44c0 | 261 | uLCD.cls(); |
jcrane32 | 19:d65f9fb1023b | 262 | uLCD.locate(5,0); |
jcrane32 | 19:d65f9fb1023b | 263 | |
jcrane32 | 19:d65f9fb1023b | 264 | Thread::wait(2000); |
jcrane32 | 19:d65f9fb1023b | 265 | } |
jcrane32 | 19:d65f9fb1023b | 266 | |
jcrane32 | 20:7d56cdcbc9a5 | 267 | int main() { |
jcrane32 | 20:7d56cdcbc9a5 | 268 | //<<<<<<< working copy |
jcrane32 | 20:7d56cdcbc9a5 | 269 | // |
jcrane32 | 20:7d56cdcbc9a5 | 270 | // uLCD.baudrate(3000000); // set baud rate to max |
jcrane32 | 20:7d56cdcbc9a5 | 271 | // |
jcrane32 | 20:7d56cdcbc9a5 | 272 | //======= |
jcrane32 | 20:7d56cdcbc9a5 | 273 | // interrupt.fall(&fallInterrupt); |
jcrane32 | 20:7d56cdcbc9a5 | 274 | // interrupt.mode(PullUp); //for touch keypad |
jcrane32 | 20:7d56cdcbc9a5 | 275 | // lcd_mutex.lock(); |
jcrane32 | 20:7d56cdcbc9a5 | 276 | // uLCD.baudrate(3000000); |
jcrane32 | 20:7d56cdcbc9a5 | 277 | // uLCD.cls(); |
jcrane32 | 20:7d56cdcbc9a5 | 278 | // uLCD.media_init(); |
jcrane32 | 20:7d56cdcbc9a5 | 279 | // uLCD.set_sector_address(0x0077, 0x4002); |
jcrane32 | 20:7d56cdcbc9a5 | 280 | // uLCD.display_video(0,0); |
jcrane32 | 20:7d56cdcbc9a5 | 281 | // wait(4); |
jcrane32 | 20:7d56cdcbc9a5 | 282 | // lcd_mutex.unlock(); |
jcrane32 | 20:7d56cdcbc9a5 | 283 | //>>>>>>> merge rev |
jcrane32 | 19:d65f9fb1023b | 284 | |
jcrane32 | 20:7d56cdcbc9a5 | 285 | // seed random |
jcrane32 | 20:7d56cdcbc9a5 | 286 | srand (time(NULL)); |
jcrane32 | 19:d65f9fb1023b | 287 | |
jcrane32 | 6:cd24147b5e50 | 288 | thread1.start(homescreen_thread); |
jcrane32 | 7:15fdc55dbf66 | 289 | thread2.start(joystick_thread); |
jcrane32 | 6:cd24147b5e50 | 290 | thread3.start(pbcontrol_thread); |
jcrane32 | 19:d65f9fb1023b | 291 | thread4.start(LED_thread); |
jcrane32 | 19:d65f9fb1023b | 292 | nextsample.attach(&playsound, 1.0/8000.0); |
jcrane32 | 19:d65f9fb1023b | 293 | |
jcrane32 | 19:d65f9fb1023b | 294 | Lane *bubbleLanes[3]; |
jcrane32 | 19:d65f9fb1023b | 295 | // these positions may need to be adjusted as I assume they're positioned incorrectly... |
jcrane32 | 20:7d56cdcbc9a5 | 296 | bubbleLanes[0] = new Lane(20,15); |
jcrane32 | 20:7d56cdcbc9a5 | 297 | bubbleLanes[1] = new Lane(60,15); |
jcrane32 | 20:7d56cdcbc9a5 | 298 | bubbleLanes[2] = new Lane(100,15); |
jcrane32 | 19:d65f9fb1023b | 299 | |
jcrane32 | 19:d65f9fb1023b | 300 | //startup sound? |
jcrane32 | 19:d65f9fb1023b | 301 | |
jcrane32 | 19:d65f9fb1023b | 302 | while(true) { |
jcrane32 | 19:d65f9fb1023b | 303 | if (songselect) { |
jcrane32 | 19:d65f9fb1023b | 304 | homescreen = false; |
jcrane32 | 19:d65f9fb1023b | 305 | // lcd_mutex.lock(); |
jcrane32 | 19:d65f9fb1023b | 306 | // uLCD.cls(); |
jcrane32 | 19:d65f9fb1023b | 307 | // uLCD.printf("You selected song %2d", songnum); |
jcrane32 | 19:d65f9fb1023b | 308 | // lcd_mutex.unlock(); |
jcrane32 | 19:d65f9fb1023b | 309 | pickSong(); |
jcrane32 | 20:7d56cdcbc9a5 | 310 | homescreen = false; |
jcrane32 | 19:d65f9fb1023b | 311 | |
jcrane32 | 19:d65f9fb1023b | 312 | // "playing" is updated by playsound() thread |
jcrane32 | 20:7d56cdcbc9a5 | 313 | bubbleLanes[0]->add(); |
jcrane32 | 20:7d56cdcbc9a5 | 314 | // bubbleLanes[1]->add(); |
jcrane32 | 20:7d56cdcbc9a5 | 315 | // bubbleLanes[2]->add(); |
jcrane32 | 20:7d56cdcbc9a5 | 316 | bubbleNdx = 0; |
jcrane32 | 20:7d56cdcbc9a5 | 317 | bool runninggame = true; |
jcrane32 | 20:7d56cdcbc9a5 | 318 | bubblesMissed = 0; |
jcrane32 | 20:7d56cdcbc9a5 | 319 | lcd_mutex.lock(); |
jcrane32 | 20:7d56cdcbc9a5 | 320 | uLCD.cls(); |
jcrane32 | 20:7d56cdcbc9a5 | 321 | lcd_mutex.unlock(); |
jcrane32 | 20:7d56cdcbc9a5 | 322 | while (runninggame) { |
jcrane32 | 20:7d56cdcbc9a5 | 323 | |
jcrane32 | 19:d65f9fb1023b | 324 | // draw unufilled circles at the bottom of the screen where the user should "tap" |
yqin70 | 1:a1aa9a79070a | 325 | lcd_mutex.lock(); |
jcrane32 | 20:7d56cdcbc9a5 | 326 | uLCD.circle(20,110, 10, GREEN); |
jcrane32 | 20:7d56cdcbc9a5 | 327 | uLCD.circle(60,110, 10, GREEN); |
jcrane32 | 20:7d56cdcbc9a5 | 328 | uLCD.circle(100,110, 10, GREEN); |
yqin70 | 1:a1aa9a79070a | 329 | lcd_mutex.unlock(); |
jcrane32 | 19:d65f9fb1023b | 330 | |
jcrane32 | 19:d65f9fb1023b | 331 | // add bubbles to lanes |
jcrane32 | 20:7d56cdcbc9a5 | 332 | // uLCD.printf("%d", fireflies_bubbles[bubbleNdx][0]); |
jcrane32 | 20:7d56cdcbc9a5 | 333 | /*if (songNdx > fireflies_bubbles[bubbleNdx][0]) { // check if it's time to load a bubble |
jcrane32 | 19:d65f9fb1023b | 334 | bool addedbubbles = false; |
jcrane32 | 20:7d56cdcbc9a5 | 335 | if (fireflies_bubbles[bubbleNdx][2]) { // check if add bubble at ndx |
jcrane32 | 19:d65f9fb1023b | 336 | bubbleLanes[0]->add(); |
jcrane32 | 19:d65f9fb1023b | 337 | addedbubbles = true; |
jcrane32 | 19:d65f9fb1023b | 338 | } |
jcrane32 | 19:d65f9fb1023b | 339 | |
jcrane32 | 20:7d56cdcbc9a5 | 340 | if (fireflies_bubbles[bubbleNdx][3]) { // check if add bubble at ndx |
jcrane32 | 19:d65f9fb1023b | 341 | bubbleLanes[1]->add(); |
jcrane32 | 19:d65f9fb1023b | 342 | addedbubbles = true; |
jcrane32 | 19:d65f9fb1023b | 343 | } |
jcrane32 | 19:d65f9fb1023b | 344 | |
jcrane32 | 20:7d56cdcbc9a5 | 345 | if (fireflies_bubbles[bubbleNdx][4]) { // check if add bubble at ndx |
jcrane32 | 19:d65f9fb1023b | 346 | bubbleLanes[2]->add(); |
jcrane32 | 19:d65f9fb1023b | 347 | addedbubbles = true; |
jcrane32 | 19:d65f9fb1023b | 348 | } |
jcrane32 | 19:d65f9fb1023b | 349 | |
jcrane32 | 20:7d56cdcbc9a5 | 350 | if (addedbubbles) ++bubbleNdx; |
jcrane32 | 20:7d56cdcbc9a5 | 351 | }*/ |
jcrane32 | 20:7d56cdcbc9a5 | 352 | |
jcrane32 | 20:7d56cdcbc9a5 | 353 | if (playing && ((rand() % 99) < 20)) { // 20% chance of inserting a bubble |
jcrane32 | 20:7d56cdcbc9a5 | 354 | bubbleLanes[rand() % 3]->add(); |
ShelbyC22 | 4:59b73f321c0e | 355 | } |
jcrane32 | 19:d65f9fb1023b | 356 | |
jcrane32 | 19:d65f9fb1023b | 357 | // draw all bubbles |
jcrane32 | 20:7d56cdcbc9a5 | 358 | lcd_mutex.lock(); |
jcrane32 | 19:d65f9fb1023b | 359 | bubbleLanes[0]->draw(); |
jcrane32 | 19:d65f9fb1023b | 360 | bubbleLanes[1]->draw(); |
jcrane32 | 19:d65f9fb1023b | 361 | bubbleLanes[2]->draw(); |
jcrane32 | 20:7d56cdcbc9a5 | 362 | lcd_mutex.unlock(); |
jcrane32 | 19:d65f9fb1023b | 363 | |
jcrane32 | 19:d65f9fb1023b | 364 | // TODO: check for hits with capacitive touchpad |
jcrane32 | 19:d65f9fb1023b | 365 | // if there is a hit, delete the bubble from the dynamic array |
jcrane32 | 20:7d56cdcbc9a5 | 366 | // replace "true" in the next 3 lines with your logic of when to check for a hit |
jcrane32 | 20:7d56cdcbc9a5 | 367 | // if (true) bubbleLanes[0]->checkHit(); |
jcrane32 | 20:7d56cdcbc9a5 | 368 | // if (true) bubbleLanes[1]->checkHit(); |
jcrane32 | 20:7d56cdcbc9a5 | 369 | // if (true) bubbleLanes[2]->checkHit(); |
jcrane32 | 19:d65f9fb1023b | 370 | |
jcrane32 | 19:d65f9fb1023b | 371 | // move down all the bubbles, deleting bubbles that are out of bounds if required |
jcrane32 | 19:d65f9fb1023b | 372 | bubbleLanes[0]->moveDown(); |
jcrane32 | 19:d65f9fb1023b | 373 | bubbleLanes[1]->moveDown(); |
jcrane32 | 19:d65f9fb1023b | 374 | bubbleLanes[2]->moveDown(); |
jcrane32 | 19:d65f9fb1023b | 375 | |
jcrane32 | 20:7d56cdcbc9a5 | 376 | if (!playing && bubbleLanes[0]->isEmpty() && bubbleLanes[1]->isEmpty() && bubbleLanes[2]->isEmpty()) { |
jcrane32 | 20:7d56cdcbc9a5 | 377 | runninggame = false; |
ShelbyC22 | 4:59b73f321c0e | 378 | } |
jcrane32 | 20:7d56cdcbc9a5 | 379 | |
jcrane32 | 19:d65f9fb1023b | 380 | //this wait delay may need to be tuned |
jcrane32 | 19:d65f9fb1023b | 381 | Thread::wait(100); |
ShelbyC22 | 4:59b73f321c0e | 382 | } |
jcrane32 | 19:d65f9fb1023b | 383 | |
jcrane32 | 19:d65f9fb1023b | 384 | // uncomment this when gameplay works |
jcrane32 | 19:d65f9fb1023b | 385 | //showScore(); |
jcrane32 | 19:d65f9fb1023b | 386 | |
jcrane32 | 19:d65f9fb1023b | 387 | // return to homescreen when |
jcrane32 | 19:d65f9fb1023b | 388 | songselect = false; |
jcrane32 | 19:d65f9fb1023b | 389 | homescreen = true; |
yqin70 | 0:4f77ae831ee7 | 390 | } |
jcrane32 | 19:d65f9fb1023b | 391 | Thread::wait(100); |
jcrane32 | 19:d65f9fb1023b | 392 | } |
yqin70 | 0:4f77ae831ee7 | 393 | } |