![](/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
Diff: main.cpp
- Revision:
- 20:7d56cdcbc9a5
- Parent:
- 19:d65f9fb1023b
- Parent:
- 17:13e45fdcf0b0
- Child:
- 21:cbcbb3480cad
diff -r d65f9fb1023b -r 7d56cdcbc9a5 main.cpp --- a/main.cpp Fri Dec 06 15:46:16 2019 +0000 +++ b/main.cpp Fri Dec 06 18:00:11 2019 +0000 @@ -1,8 +1,11 @@ #include "mbed.h" #include "rtos.h" #include "stdio.h" +#include <stdlib.h> +#include <time.h> #include "SDFileSystem.h" #include "wave_player.h" +#include "mpr121.h" #include "uLCD_4DGL.h" #include "Small_6.h" @@ -12,7 +15,7 @@ #include "globals.h" -#include "bubbles.h" +//#include "bubbles.h" #include "stacys_mom.h" //#include "the_middle.h" #include "fireflies.h" @@ -40,6 +43,27 @@ DigitalIn pb1(p20); DigitalIn pb2(p19); AnalogOut DACout(p18); +// Create the interrupt receiver object on pin 26 for touch pad IRQ +InterruptIn interrupt(p26); +// Setup the i2c bus on pins 9 and 10 +I2C i2c(p9, p10); +// Setup the Mpr121: +// constructor(i2c object, i2c address of the mpr121) +Mpr121 mpr121(&i2c, Mpr121::ADD_VSS); + +// Key hit/release interrupt routine +//void fallInterrupt() { +// int key_code=0; +// int i=0; +// int value=mpr121.read(0x00); +// value +=mpr121.read(0x01)<<8; +// for (i=0; i<12; i++) { +// if (((value>>i)&0x01)==1) { +// key_code=i+1; +// } +// } +//} + wave_player waver(&DACout); Thread thread1, thread2, thread3, thread4; @@ -53,8 +77,8 @@ unsigned short **currentBubbles = NULL; int bubbleNdx = 0; -int bubblesDrawn = 0; -int bubblesMissed = 0; +volatile int bubblesDrawn = 0; +volatile int bubblesMissed = 0; @@ -95,7 +119,7 @@ } lcd_mutex.unlock(); - Thread::wait(200); + Thread::wait(500); } } @@ -153,15 +177,16 @@ myRGBled = green; Thread::wait(200); } else if (playing) { - - if (bubblesMissed <= 3) { + //lcd_mutex.lock(); +// uLCD.printf("%d", bubblesMissed); +// lcd_mutex.unlock(); + if (bubblesMissed <= 1) { myRGBled = green; - } else if (bubblesMissed <= 5) { - myRGBled = yellow; + } else if (bubblesMissed <= 3) { + myRGBled = blue; } else { myRGBled = red; } - Thread::wait(300); } @@ -239,27 +264,26 @@ Thread::wait(2000); } - -void play() { - Lane *bubbleLanes[3]; - // these positions may need to be adjusted as I assume they're positioned incorrectly... - bubbleLanes[0] = new Lane(3,3); - bubbleLanes[1] = new Lane(3,6); - bubbleLanes[2] = new Lane(3,9); +int main() { +//<<<<<<< working copy +// +// uLCD.baudrate(3000000); // set baud rate to max +// +//======= +// interrupt.fall(&fallInterrupt); +// interrupt.mode(PullUp); //for touch keypad +// lcd_mutex.lock(); +// uLCD.baudrate(3000000); +// uLCD.cls(); +// uLCD.media_init(); +// uLCD.set_sector_address(0x0077, 0x4002); +// uLCD.display_video(0,0); +// wait(4); +// lcd_mutex.unlock(); +//>>>>>>> merge rev - while (playing && !bubbleLanes[0]->isEmpty() && !bubbleLanes[1]->isEmpty() && !bubbleLanes[2]->isEmpty()) { - - } - - // return to homescreen when - homescreen = true; -} - - - -int main() { - - uLCD.baudrate(3000000); // set baud rate to max + // seed random + srand (time(NULL)); thread1.start(homescreen_thread); thread2.start(joystick_thread); @@ -269,9 +293,9 @@ Lane *bubbleLanes[3]; // these positions may need to be adjusted as I assume they're positioned incorrectly... - bubbleLanes[0] = new Lane(15,15); - bubbleLanes[1] = new Lane(40,15); - bubbleLanes[2] = new Lane(80,15); + bubbleLanes[0] = new Lane(20,15); + bubbleLanes[1] = new Lane(60,15); + bubbleLanes[2] = new Lane(100,15); //startup sound? @@ -283,51 +307,76 @@ // uLCD.printf("You selected song %2d", songnum); // lcd_mutex.unlock(); pickSong(); + homescreen = false; // "playing" is updated by playsound() thread - while (playing && !bubbleLanes[0]->isEmpty() && !bubbleLanes[1]->isEmpty() && !bubbleLanes[2]->isEmpty()) { + bubbleLanes[0]->add(); +// bubbleLanes[1]->add(); +// bubbleLanes[2]->add(); + bubbleNdx = 0; + bool runninggame = true; + bubblesMissed = 0; + lcd_mutex.lock(); + uLCD.cls(); + lcd_mutex.unlock(); + while (runninggame) { + // draw unufilled circles at the bottom of the screen where the user should "tap" - uLCD.circle(15,110, 30, GREEN); - uLCD.circle(40,110, 30, GREEN); - uLCD.circle(80,110, 30, GREEN); + lcd_mutex.lock(); + uLCD.circle(20,110, 10, GREEN); + uLCD.circle(60,110, 10, GREEN); + uLCD.circle(100,110, 10, GREEN); + lcd_mutex.unlock(); // add bubbles to lanes - if (fireflies_bubbles[bubbleNdx][0] > songNdx) { // check if it's time to load a bubble +// uLCD.printf("%d", fireflies_bubbles[bubbleNdx][0]); + /*if (songNdx > fireflies_bubbles[bubbleNdx][0]) { // check if it's time to load a bubble bool addedbubbles = false; - if (fireflies_bubbles[bubbleNdx][2] > songNdx) { // check if add bubble at ndx + if (fireflies_bubbles[bubbleNdx][2]) { // check if add bubble at ndx bubbleLanes[0]->add(); addedbubbles = true; } - if (fireflies_bubbles[bubbleNdx][3] > songNdx) { // check if add bubble at ndx + if (fireflies_bubbles[bubbleNdx][3]) { // check if add bubble at ndx bubbleLanes[1]->add(); addedbubbles = true; } - if (fireflies_bubbles[bubbleNdx][4] > songNdx) { // check if add bubble at ndx + if (fireflies_bubbles[bubbleNdx][4]) { // check if add bubble at ndx bubbleLanes[2]->add(); addedbubbles = true; } - if (addedbubbles) ++songNdx; + if (addedbubbles) ++bubbleNdx; + }*/ + + if (playing && ((rand() % 99) < 20)) { // 20% chance of inserting a bubble + bubbleLanes[rand() % 3]->add(); } // draw all bubbles + lcd_mutex.lock(); bubbleLanes[0]->draw(); bubbleLanes[1]->draw(); bubbleLanes[2]->draw(); + lcd_mutex.unlock(); // TODO: check for hits with capacitive touchpad // if there is a hit, delete the bubble from the dynamic array - if (true) bubbleLanes[0]->checkHit(); - if (true) bubbleLanes[1]->checkHit(); - if (true) bubbleLanes[2]->checkHit(); + // replace "true" in the next 3 lines with your logic of when to check for a hit +// if (true) bubbleLanes[0]->checkHit(); +// if (true) bubbleLanes[1]->checkHit(); +// if (true) bubbleLanes[2]->checkHit(); // move down all the bubbles, deleting bubbles that are out of bounds if required bubbleLanes[0]->moveDown(); bubbleLanes[1]->moveDown(); bubbleLanes[2]->moveDown(); + if (!playing && bubbleLanes[0]->isEmpty() && bubbleLanes[1]->isEmpty() && bubbleLanes[2]->isEmpty()) { + runninggame = false; + } + //this wait delay may need to be tuned Thread::wait(100); }