Dance Dance Revolution program for main mbed
Dependencies: 4DGL-uLCD-SE SDFileSystem mbed-rtos mbed wave_player
Revision 0:8a02ac09eae0, committed 2016-04-29
- Comitter:
- wliu88
- Date:
- Fri Apr 29 02:04:07 2016 +0000
- Commit message:
- new
Changed in this revision
diff -r 000000000000 -r 8a02ac09eae0 4DGL-uLCD-SE.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/4DGL-uLCD-SE.lib Fri Apr 29 02:04:07 2016 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/4180_1/code/4DGL-uLCD-SE/#e39a44de229a
diff -r 000000000000 -r 8a02ac09eae0 SDFileSystem.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SDFileSystem.lib Fri Apr 29 02:04:07 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/SDFileSystem/#c8f66dc765d4
diff -r 000000000000 -r 8a02ac09eae0 arrows.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/arrows.h Fri Apr 29 02:04:07 2016 +0000 @@ -0,0 +1,256 @@ +#ifndef ARROWS_H +#define ARROWS_H + + +#include "mbed.h" +#include "globals.h" +//arrow.h: file responsible for generating arrow +//LEFT = 0 +//UP = 1 +//DOWN = 2 +//RIGHT = 3 +//INVALID = -1 + +class Arrow { + public: + int active; + int type; + int locx1; + int locx2; + int locx3; + int locy1; + int locy2; + int locy3; + int currx; + int curry; + double delay; + Arrow(){} + Arrow(int dir) { + type = dir; + if(dir != -1){ active = 0; } + else {active = 1;} + } + Arrow(int dir, double arg_delay){ + type = dir; + if(dir != -1){active =0;} + else {active = 1;} + delay = arg_delay; + } + double getDelay(){ + return delay; + } + void setType(int dir) { + type = dir; + } + int getType(){ + return type; + } + int getActive(){ + return active; + } + void setActive(int activepassive){ + active = activepassive; + } + void init(int screenNum){ + if(active){ + switch(type){ + case 0: + locx1 = 10; + locy1 = 123; + locx2 = 20; + locy2 = 119; + locx3 = 20; + locy3 = 127; + currx = 15; + curry = 123; + break; + case 3: + locx1 = 106; + locy1 = 119; + locx2 = 106; + locy2 = 127; + locx3 = 116; + locy3 = 123; + currx = 111; + curry = 123; + break; + case 1: + locx1 = 42; + locy1 = 127; + locx2 = 47; + locy2 = 119; + locx3 = 52; + locy3 = 127; + currx = 47; + curry = 123; + break; + case 2: + locx1 = 74; + locy1 = 119; + locx2 = 79; + locy2 = 127; + locx3 = 84; + locy3 = 119; + currx = 79; + curry = 123; + break; + default: + //arrow has not been released/dead + } + if(type != -1){ + if(screenNum==0){ + uLCD.triangle(locx1, locy1, locx2, locy2, locx3, locy3, 0x0000FF); + } + else if (screenNum == 1) { + uLCD2.triangle(locx1, locy1, locx2, locy2, locx3, locy3, 0x0000FF); + } + else { + uLCD.triangle(locx1, locy1, locx2, locy2, locx3, locy3, 0x0000FF); + uLCD2.triangle(locx1, locy1, locx2, locy2, locx3, locy3, 0x0000FF); + } + } + } + } + + void init2(){ + if(active){ + switch(type){ + case 0: + locx1 = 10; + locy1 = 123; + locx2 = 20; + locy2 = 119; + locx3 = 20; + locy3 = 127; + currx = 15; + curry = 123; + break; + case 3: + locx1 = 106; + locy1 = 119; + locx2 = 106; + locy2 = 127; + locx3 = 116; + locy3 = 123; + currx = 111; + curry = 123; + break; + case 1: + locx1 = 42; + locy1 = 127; + locx2 = 47; + locy2 = 119; + locx3 = 52; + locy3 = 127; + currx = 47; + curry = 123; + break; + case 2: + locx1 = 74; + locy1 = 119; + locx2 = 79; + locy2 = 127; + locx3 = 84; + locy3 = 119; + currx = 79; + curry = 123; + break; + default: + //arrow has not been released/dead + } + if(type != -1){ + uLCD2.triangle(locx1, locy1, locx2, locy2, locx3, locy3, 0x0000FF); + } + } + } + + int update(int screenNum){ + switch(screenNum){ + case 0: + if(type != -1){ + uLCD.triangle(locx1,locy1,locx2,locy2,locx3,locy3,0x000000); + locy1 -= 9; + locy2 -= 9; + locy3 -= 9; + //currx -= 8; + curry -= 9; + uLCD.triangle(locx1,locy1,locx2,locy2,locx3,locy3,0x0000FF); + if(curry <= 5){ + uLCD.triangle(locx1,locy1,locx2,locy2,locx3,locy3,0x000000); + active = 0; + return 1; + } + else{ + return 0; + } + } + else{return 1;} + break; + case 1: + if(type != -1){ + uLCD2.triangle(locx1,locy1,locx2,locy2,locx3,locy3,0x000000); + locy1 -= 9; + locy2 -= 9; + locy3 -= 9; + //currx -= 8; + curry -= 9; + uLCD2.triangle(locx1,locy1,locx2,locy2,locx3,locy3,0x0000FF); + if(curry <= 5){ + uLCD2.triangle(locx1,locy1,locx2,locy2,locx3,locy3,0x000000); + active = 0; + return 1; + } + else{ + return 0; + } + } + else{return 1;} + break; + default: + if(type != -1){ + uLCD.triangle(locx1,locy1,locx2,locy2,locx3,locy3,0x000000); + uLCD2.triangle(locx1,locy1,locx2,locy2,locx3,locy3,0x000000); + locy1 -= 9; + locy2 -= 9; + locy3 -= 9; + //currx -= 8; + curry -= 9; + uLCD.triangle(locx1,locy1,locx2,locy2,locx3,locy3,0x0000FF); + uLCD2.triangle(locx1,locy1,locx2,locy2,locx3,locy3,0x0000FF); + if(curry <= 5){ + uLCD.triangle(locx1,locy1,locx2,locy2,locx3,locy3,0x000000); + uLCD2.triangle(locx1,locy1,locx2,locy2,locx3,locy3,0x000000); + active = 0; + return 1; + } + else{ + return 0; + } + } + else{return 1;} + } + } + + int update2(){ + if(type != -1){ + uLCD2.triangle(locx1,locy1,locx2,locy2,locx3,locy3,0x000000); + locy1 -= 9; + locy2 -= 9; + locy3 -= 9; + //currx -= 8; + curry -= 9; + uLCD2.triangle(locx1,locy1,locx2,locy2,locx3,locy3,0x0000FF); + if(curry <= 5){ + uLCD2.triangle(locx1,locy1,locx2,locy2,locx3,locy3,0x000000); + active = 0; + return 1; + } + else{ + return 0; + } + } + else{return 1;} + } +}; + +#endif \ No newline at end of file
diff -r 000000000000 -r 8a02ac09eae0 background.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/background.h Fri Apr 29 02:04:07 2016 +0000 @@ -0,0 +1,80 @@ +#include "mbed.h" +#include "globals.h" + +//This file contains the code to setup the background for the game + +int refarrow_left_x = 15; +int refarrow_left_y = 12; +int refarrow_up_x = 47; +int refarrow_up_y = 12; +int refarrow_down_x = 79; +int refarrow_down_y = 12; +int refarrow_right_x = 111; +int refarrow_right_y = 12; + + +void setup_lining(){ + uLCD.filled_rectangle(0,0,127,1,0xFF0000); + uLCD.filled_rectangle(0,0,1,127,0xFF0000); + uLCD.filled_rectangle(0,127,127,126,0xFF0000); + uLCD.filled_rectangle(126,127,127,0,0xFF0000); + uLCD.filled_rectangle(31,0,34,127,0xFF0000); + uLCD.filled_rectangle(63,0,66,127,0xFF0000); + uLCD.filled_rectangle(95,0,98,127,0xFF0000); +} + +void setup_goal_arrows(){ + //simple setup for reference arrows for Dance Dance Revolution + uLCD.triangle(10,12,20,8,20,16,0xBEBEBE); //left + uLCD.triangle(42,16,47,8,52,16,0xBEBEBEB);//up + uLCD.triangle(74,8,79,16,84,8,0xBEBEBE); //down + uLCD.triangle(106,8,106,16,116,12,0xBEBEBEB);//right +} + +void setup_goal_arrows_complex() { + //left arrow + uLCD.filled_rectangle(8,10,23,13,0xBEBEBE); + uLCD.filled_rectangle(12,8,14,16,0xBEBEBE); +} + + +// +// +// +//Second Screen +void setup_lining2(){ + uLCD2.filled_rectangle(0,0,127,1,0xFF0000); + uLCD2.filled_rectangle(0,0,1,127,0xFF0000); + uLCD2.filled_rectangle(0,127,127,126,0xFF0000); + uLCD2.filled_rectangle(126,127,127,0,0xFF0000); + uLCD2.filled_rectangle(31,0,34,127,0xFF0000); + uLCD2.filled_rectangle(63,0,66,127,0xFF0000); + uLCD2.filled_rectangle(95,0,98,127,0xFF0000); +} + +void setup_goal_arrows2(){ + //simple setup for reference arrows for Dance Dance Revolution + uLCD2.triangle(10,12,20,8,20,16,0xBEBEBE); //left + uLCD2.triangle(42,16,47,8,52,16,0xBEBEBEB);//up + uLCD2.triangle(74,8,79,16,84,8,0xBEBEBE); //down + uLCD2.triangle(106,8,106,16,116,12,0xBEBEBEB);//right +} + +void setup_goal_arrows_complex2() { + //left arrow + uLCD2.filled_rectangle(8,10,23,13,0xBEBEBE); + uLCD2.filled_rectangle(12,8,14,16,0xBEBEBE); +} + + +void end_screen(){ + uLCD.filled_rectangle(0,0,127,1,0xFF0000); + uLCD.filled_rectangle(0,0,1,127,0xFF0000); + uLCD.filled_rectangle(0,127,127,126,0xFF0000); + uLCD.filled_rectangle(126,127,127,0,0xFF0000); + uLCD2.filled_rectangle(0,0,127,1,0x0000FF); + uLCD2.filled_rectangle(0,0,1,127,0x0000FF); + uLCD2.filled_rectangle(0,127,127,126,0x0000FF); + uLCD2.filled_rectangle(126,127,127,0,0x0000FF); + +} \ No newline at end of file
diff -r 000000000000 -r 8a02ac09eae0 globals.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/globals.h Fri Apr 29 02:04:07 2016 +0000 @@ -0,0 +1,9 @@ +#ifndef GLOBAL_H +#define GLOBAL_H + +// === [global object] === +extern uLCD_4DGL uLCD; +extern uLCD_4DGL uLCD2; + + +#endif \ No newline at end of file
diff -r 000000000000 -r 8a02ac09eae0 joystick.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/joystick.h Fri Apr 29 02:04:07 2016 +0000 @@ -0,0 +1,68 @@ +#include "mbed.h" + +class Nav_Switch +{ +public: + Nav_Switch(PinName up,PinName down,PinName left,PinName right,PinName fire, + volatile bool* u, volatile bool* d, volatile bool* l, volatile bool* r, volatile bool* f, volatile int* counter); +//boolean functions to test each switch + void up(); + void down(); + void left(); + void right(); + void fire(); +private: + InterruptIn _up; + InterruptIn _down; + InterruptIn _left; + InterruptIn _right; + InterruptIn _fire; + volatile bool* _u; + volatile bool* _d; + volatile bool* _l; + volatile bool* _r; + volatile bool* _f; + volatile int* _counter; + +}; +Nav_Switch::Nav_Switch (PinName up,PinName down,PinName left,PinName right,PinName fire, + volatile bool* u, volatile bool* d, volatile bool* l, volatile bool* r, volatile bool* f, + volatile int* counter): + _up(up), _down(down), _left(left), _right(right), _fire(fire), + _u(u), _d(d), _l(l), _r(r), _f(f), + _counter(counter) +{ + _up.mode(PullUp); //needed if pullups not on board or a bare nav switch is used - delete otherwise + _down.mode(PullUp); + _left.mode(PullUp); + _right.mode(PullUp); + _fire.mode(PullUp); + wait(0.001); //delays just a bit for pullups to pull inputs high + _up.fall(this, &Nav_Switch::up); + _down.fall(this, &Nav_Switch::down); + _left.fall(this, &Nav_Switch::left); + _right.fall(this, &Nav_Switch::right); + _fire.fall(this, &Nav_Switch::fire); +} +inline void Nav_Switch::up() +{ + (*_u) = true; + (*_counter) = ((*_counter) + 2 - 1) % 2; +} +inline void Nav_Switch::down() +{ + (*_d) = true; + (*_counter) = ((*_counter) + 1) % 2; +} +inline void Nav_Switch::left() +{ + (*_l) = true; +} +inline void Nav_Switch::right() +{ + (*_r) = true; +} +inline void Nav_Switch::fire() +{ + (*_f) = true; +}
diff -r 000000000000 -r 8a02ac09eae0 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri Apr 29 02:04:07 2016 +0000 @@ -0,0 +1,699 @@ + +//FULL GAME (MAIN MBED) + +#include "mbed.h" +#include "uLCD_4DGL.h" +#include "rtos.h" +#include "SDFileSystem.h" +#include <string> +#include <vector> +#include "joystick.h" +#include "background.h" +#include "arrows.h" +#include "releaser.h" +#include "songs.h" + + +Mutex mutex; +Mutex m; +Mutex arm; +uLCD_4DGL uLCD2(p9,p10,p16); // serial tx, serial rx, reset pin; +uLCD_4DGL uLCD(p28,p27,p29); +SDFileSystem sd(p5, p6, p7, p8, "sd"); +//InterruptIn pb1(p22); +//InterruptIn pb2(p21); +volatile bool up1 = false; +volatile bool down1 = false; +volatile bool left1 = false; +volatile bool right1 = false; +volatile bool fire1 = false; +volatile bool up2 = false; +volatile bool down2 = false; +volatile bool left2 = false; +volatile bool right2 = false; +volatile bool fire2 = false; +volatile int song1 = 0; +volatile int song2 = 0; +Nav_Switch js1( p12, p14, p13, p15, p11, &up1, &down1, &left1, &right1, &fire1,&song1); //Nav_Switch(PinName up,PinName down,PinName left,PinName right,PinName fire); +Nav_Switch js2( p23, p25, p24, p21, p22, &up2, &down2, &left2, &right2, &fire2,&song2); //Nav_Switch(PinName up,PinName down,PinName left,PinName right,PinName fire); +// variables used for controlling the process +volatile bool pushed1 = false; +volatile bool pushed2 = false; +volatile bool selected1 = false; +volatile bool selected2 = false; +volatile bool process1 = false; +volatile bool process2 = false; +volatile bool finished1 = false; +volatile bool finished2 = false; +ArrowReleaser ar = ArrowReleaser(); +ArrowReleaser ar2 = ArrowReleaser(); +double nextdelay = 1.0; +int indx = 0; +int chk; +int chk2; +volatile int counter = 0; +volatile int counter2 = 0; +volatile bool empty = false; +volatile bool scoreScreen = false; +DigitalOut songSelected(p19); +DigitalOut specificSong(p20); + + + + +vector<string> filenames; + +// helper function +// read files names in dir and put them in the variable "filenames" +void read_file_names(char *dir) +{ + DIR *dp; + struct dirent *dirp; + dp = opendir(dir); + //read all directory and file names in current directory into filename vector + while((dirp = readdir(dp)) != NULL) { + string filename = string(dirp->d_name); + if ((filename[0] >= 97 && filename[0] <=122) || (filename[0] >= 65 && filename[0] <=90)) { + filenames.push_back(filename); + } + } + closedir(dp); +} + +void uLCD_thread(void const *args) { + + // 1. title screen + mutex.lock(); + //uLCD.cls(); + //uLCD.reset(); + uLCD.textbackground_color(BLACK); + uLCD.color(RED); + uLCD.locate(4,0); + uLCD.printf("Dance Dance"); + uLCD.locate(4,1); + uLCD.printf("Revolution!"); + uLCD.locate(6,15); + uLCD.printf("Player 1"); + mutex.unlock(); + while(!pushed1) { + mutex.lock(); + uLCD.locate(4,7); + uLCD.printf("Press CENTER"); + mutex.unlock(); + Thread::wait(1000); + mutex.lock(); + uLCD.locate(4,7); + uLCD.printf(" "); + mutex.unlock(); + pushed1 = fire1; + } + + // 2. ready screen + mutex.lock(); + uLCD.cls(); + uLCD.locate(0,7); + uLCD.printf("Player 1 is ready!"); + mutex.unlock(); + Thread::wait(1000); + while(!pushed2) { + mutex.lock(); + uLCD.locate(0,9); + uLCD.printf("Wait player 2..."); + mutex.unlock(); + } + + // 3. song selection screen + while(!process1) { + Thread::yield(); + } + mutex.lock(); + uLCD.cls(); + uLCD.printf("Select a song"); + mutex.unlock(); + fire1 = false; + while(!selected1 || !selected2) { + for (int i = 0; i < filenames.size(); i++) { + mutex.lock(); + if (i == song1) { + uLCD.color(RED); + } else { + uLCD.color(GREEN); + } + uLCD.locate(0,i+2); + uLCD.printf("%s\n\r", filenames[i].c_str()); + uLCD.locate(16,i+2); + uLCD.printf(" "); + if (i == song2) { + uLCD.color(BLUE); + uLCD.locate(16,i+2); + uLCD.printf("<-"); + } + mutex.unlock(); + } + if (selected1) { + mutex.lock(); + uLCD.locate(0,8); + uLCD.color(RED); + uLCD.printf("Ready!"); + mutex.unlock(); + } + selected1 = fire1; + } + + + // 5. count down + mutex.lock(); + uLCD.cls(); + uLCD.color(RED); + uLCD.printf("%s\n\r", filenames[song1].c_str()); + uLCD.locate(0,1); + uLCD.printf("is picked"); + mutex.unlock(); + while(!process2) { + Thread::yield(); + } + mutex.lock(); + uLCD.cls(); + uLCD.text_width(4); //4X size text + uLCD.text_height(4); + mutex.unlock(); + uLCD.color(RED); + for (int i=5; i>=0; --i) { + mutex.lock(); + uLCD.locate(1,2); + uLCD.printf("%2D",i); + mutex.unlock(); + Thread::wait(1000); + } + finished1 = true; +} + +void uLCD2_thread(void const *args) { + + // 1. title screen + mutex.lock(); + //uuLCD2.cls(); + //uuLCD2.reset(); + uLCD2.textbackground_color(BLACK); + uLCD2.color(BLUE); + uLCD2.locate(4,0); + uLCD2.printf("Dance Dance"); + uLCD2.locate(4,1); + uLCD2.printf("Revolution!"); + uLCD2.locate(6,15); + uLCD2.printf("Player 2"); + mutex.unlock(); + while(!pushed2) { + mutex.lock(); + uLCD2.locate(4,7); + uLCD2.printf("Press CENTER"); + mutex.unlock(); + wait(1); + mutex.lock(); + uLCD2.locate(4,7); + uLCD2.printf(" "); + mutex.unlock(); + pushed2 = fire2; + } + + // 2. ready screen + mutex.lock(); + uLCD2.cls(); + uLCD2.locate(0,7); + uLCD2.printf("Player 2 is ready!"); + mutex.unlock(); + Thread::wait(1000); + while(!pushed1){ + mutex.lock(); + uLCD2.locate(0,9); + uLCD2.printf("Wait player 1..."); + mutex.unlock(); + } + + // 3. song selection screen + Thread::wait(1000); + process1 = true; + mutex.lock(); + uLCD2.cls(); + uLCD2.printf("Select a song"); + mutex.unlock(); + fire2 = false; + while(!selected2 || !selected1) { + for (int i = 0; i < filenames.size(); i++) { + mutex.lock(); + if (i == song2) { + uLCD2.color(BLUE); + } else { + uLCD2.color(GREEN); + } + uLCD2.locate(0,i+2); + uLCD2.printf("%s\n\r", filenames[i].c_str()); + uLCD2.locate(16,i+2); + uLCD2.printf(" "); + // add a marker to notify player 2 about player 1's selection + if (i == song1) { + uLCD2.color(RED); + uLCD2.locate(16,i+2); + uLCD2.printf("<-"); + } + mutex.unlock(); + } + if (selected2) { + mutex.lock(); + uLCD2.locate(0,8); + uLCD2.color(BLUE); + uLCD2.printf("Ready!"); + mutex.unlock(); + } + selected2 = fire2; + } + + // 5. count down + mutex.lock(); + uLCD2.cls(); + uLCD2.color(BLUE); + uLCD2.printf("%s\n\r", filenames[song1].c_str()); + uLCD2.locate(0,1); + uLCD2.printf("is picked"); + mutex.unlock(); + Thread::wait(3000); + process2 = true; + mutex.lock(); + uLCD2.cls(); + uLCD2.text_width(4); //4X size text + uLCD2.text_height(4); + mutex.unlock(); + uLCD2.color(BLUE); + for (int i=5; i>=0; --i) { + mutex.lock(); + uLCD2.locate(1,2); + uLCD2.printf("%2D",i); + mutex.unlock(); + Thread::wait(1000); + } + finished2 = true; +} + +//GAME + +void arrowreleasing_thread1(void const *args) { + Thread::wait(100); + if(!song1){ + while(1){ + chk = 0; chk2 =0; + while(!chk && !chk2){ + arm.lock(); + m.lock(); + chk = ar.ReleaseArrow(DemoArray2,indx,2); + m.unlock(); + arm.unlock(); + Thread::wait(100); + } + indx++; + if(indx == 53){ + arm.lock(); + ar.setTermStatus(1); + arm.unlock(); + break; + } + nextdelay = DemoArray2[indx-1].getDelay(); + Thread::wait(nextdelay*1000); + } + } + else{ + while(1){ + chk = 0; chk2 =0; + while(!chk && !chk2){ + arm.lock(); + m.lock(); + chk = ar.ReleaseArrow(DemoArray,indx,2); + m.unlock(); + arm.unlock(); + Thread::wait(100); + } + indx++; + if(indx == 53){ + arm.lock(); + ar.setTermStatus(1); + arm.unlock(); + break; + } + nextdelay = DemoArray[indx-1].getDelay(); + Thread::wait(nextdelay*1000); + } + } +} + +void arrowdrawing_thread1(void const *args){ + int term; + while(!scoreScreen){ + for(int i=0; i< 5; i++){ + arm.lock(); + if(ar.ActiveArrows[i].getActive()){ + m.lock(); + term = ar.ActiveArrows[i].update(2); + m.unlock(); + if(term){ + ar.ActiveArrows[i].setActive(0); + m.lock(); + setup_goal_arrows(); + uLCD.locate(0,0); + uLCD.printf("%d",counter); + setup_goal_arrows2(); + uLCD2.locate(0,0); + uLCD2.printf("%d",counter2); + m.unlock(); + term = 0; + } + } + arm.unlock(); + } + /*arm.lock(); + if(empty && ar.getTermStatus()){ + arm.unlock(); + //Song has ended and all arrows have ended + scoreScreen = true; + break; + }*/ + } + +} + + +void joystick2_thread(void const *args) { + while(!scoreScreen){ + if(left2){ + left2 = false; + for(int i=0; i < 5; i++){ + arm.lock(); + if(ar.ActiveArrows[i].getActive() && ar.ActiveArrows[i].getType() == 0 && abs(ar.ActiveArrows[i].curry - refarrow_left_y) <= 10){ + arm.unlock(); + counter2++; + m.lock(); + uLCD2.locate(0,0); + uLCD2.printf("%d",counter2); + m.unlock(); + break; + } + arm.unlock(); + } + m.lock(); + uLCD2.circle(refarrow_left_x,refarrow_left_y,10,0x00FF00); + m.unlock(); + wait(0.04); + m.lock(); + uLCD2.circle(refarrow_left_x,refarrow_left_y,10,0x000000); + uLCD2.locate(0,0); + uLCD2.printf("%d",counter2); + m.unlock(); + } + if(right2){ + right2 = false; + for(int i=0; i < 5; i++){ + arm.lock(); + if(ar.ActiveArrows[i].getActive() && ar.ActiveArrows[i].getType() == 3 && abs(ar.ActiveArrows[i].curry - refarrow_right_y) <= 10){ + arm.unlock(); + counter2++; + m.lock(); + uLCD2.locate(0,0); + uLCD2.printf("%d",counter2); + m.unlock(); + break; + } + arm.unlock(); + } + m.lock(); + uLCD2.circle(refarrow_right_x,refarrow_right_y,10,0x00FF00); + m.unlock(); + wait(0.04); + m.lock(); + uLCD2.circle(refarrow_right_x,refarrow_right_y,10,0x000000); + uLCD2.locate(0,0); + uLCD2.printf("%d",counter2); + m.unlock(); + } + if(up2){ + up2 = false; + for(int i=0; i < 5; i++){ + arm.lock(); + if(ar.ActiveArrows[i].getActive() && ar.ActiveArrows[i].getType() == 1 && abs(ar.ActiveArrows[i].curry - refarrow_up_y) <= 10){ + arm.unlock(); + counter2++; + m.lock(); + uLCD2.locate(0,0); + uLCD2.printf("%d",counter2); + m.unlock(); + break; + } + arm.unlock(); + } + m.lock(); + uLCD2.circle(refarrow_up_x,refarrow_up_y,10,0x00FF00); + m.unlock(); + wait(0.04); + m.lock(); + uLCD2.circle(refarrow_up_x,refarrow_up_y,10,0x000000); + uLCD2.locate(0,0); + uLCD2.printf("%d",counter2); + m.unlock(); + } + if(down2){ + down2 = false; + for(int i=0; i < 5; i++){ + arm.lock(); + if(ar.ActiveArrows[i].getActive() && ar.ActiveArrows[i].getType() == 2 && abs(ar.ActiveArrows[i].curry - refarrow_down_y) <= 10){ + arm.unlock(); + counter2++; + m.lock(); + uLCD2.locate(0,0); + uLCD2.printf("%d",counter2); + m.unlock(); + break; + } + arm.unlock(); + } + m.lock(); + uLCD2.circle(refarrow_down_x,refarrow_down_y,10,0x00FF00); + m.unlock(); + wait(0.04); + m.lock(); + uLCD2.circle(refarrow_down_x,refarrow_down_y,10,0x000000); + uLCD2.locate(0,0); + uLCD2.printf("%d",counter2); + m.unlock(); + } + Thread::wait(10); + + } +} + + +int main() +{ + + uLCD.baudrate(3000000); + uLCD2.baudrate(3000000); + read_file_names("/sd/wavfiles"); + Thread thread1(uLCD_thread); + Thread thread2(uLCD2_thread); + while(true) + { + if(finished1 && finished2){ + thread1.terminate(); + thread2.terminate(); + uLCD.cls(); + uLCD2.cls(); + break; + } + } + + songSelected = 1; + specificSong = song1; + + //GAME + uLCD.baudrate(8000); + uLCD2.baudrate(8000); + uLCD.color(GREEN); + uLCD2.color(GREEN); + uLCD.locate(0,0); + uLCD.printf("%d",counter); + setup_lining(); + setup_goal_arrows(); + uLCD2.locate(0,0); + uLCD2.printf("%d",counter); + setup_lining2(); + setup_goal_arrows2(); + wait(1); + Thread t1(arrowreleasing_thread1); + t1.set_priority(osPriorityRealtime); + Thread t2(arrowdrawing_thread1); + Thread t3(joystick2_thread); + t3.set_priority(osPriorityHigh); + while(1){ + + if(left1){ + left1 = false; + for(int i=0; i < 5; i++){ + arm.lock(); + if(ar.ActiveArrows[i].getActive() && ar.ActiveArrows[i].getType() == 0 && abs(ar.ActiveArrows[i].curry - refarrow_left_y) <= 10){ + arm.unlock(); + counter++; + m.lock(); + uLCD.locate(0,0); + uLCD.printf("%d",counter); + m.unlock(); + break; + } + arm.unlock(); + } + m.lock(); + uLCD.circle(refarrow_left_x,refarrow_left_y,10,0x00FF00); + m.unlock(); + wait(0.04); + m.lock(); + uLCD.circle(refarrow_left_x,refarrow_left_y,10,0x000000);uLCD.locate(0,0); + uLCD.locate(0,0); + uLCD.printf("%d",counter); + m.unlock(); + } + if(right1){ + right1 = false; + for(int i=0; i < 5; i++){ + arm.lock(); + if(ar.ActiveArrows[i].getActive() && ar.ActiveArrows[i].getType() == 3 && abs(ar.ActiveArrows[i].curry - refarrow_right_y) <= 10){ + arm.unlock(); + counter++; + m.lock(); + uLCD.locate(0,0); + uLCD.printf("%d",counter); + m.unlock(); + break; + } + arm.unlock(); + } + m.lock(); + uLCD.circle(refarrow_right_x,refarrow_right_y,10,0x00FF00); + m.unlock(); + wait(0.04); + m.lock(); + uLCD.circle(refarrow_right_x,refarrow_right_y,10,0x000000); + uLCD.locate(0,0); + uLCD.printf("%d",counter); + m.unlock(); + } + if(up1){ + up1 = false; + for(int i=0; i < 5; i++){ + arm.lock(); + if(ar.ActiveArrows[i].getActive() && ar.ActiveArrows[i].getType() == 1 && abs(ar.ActiveArrows[i].curry - refarrow_up_y) <= 10){ + arm.unlock(); + counter++; + m.lock(); + uLCD.locate(0,0); + uLCD.printf("%d",counter); + m.unlock(); + break; + } + arm.unlock(); + } + m.lock(); + uLCD.circle(refarrow_up_x,refarrow_up_y,10,0x00FF00); + m.unlock(); + wait(0.04); + m.lock(); + uLCD.circle(refarrow_up_x,refarrow_up_y,10,0x000000); + uLCD.locate(0,0); + uLCD.printf("%d",counter); + m.unlock(); + } + if(down1){ + down1 = false; + for(int i=0; i < 5; i++){ + arm.lock(); + if(ar.ActiveArrows[i].getActive() && ar.ActiveArrows[i].getType() == 2 && abs(ar.ActiveArrows[i].curry - refarrow_down_y) <= 10){ + arm.unlock(); + counter++; + m.lock(); + uLCD.locate(0,0); + uLCD.printf("%d",counter); + m.unlock(); + break; + } + arm.unlock(); + } + m.lock(); + uLCD.circle(refarrow_down_x,refarrow_down_y,10,0x00FF00); + m.unlock(); + wait(0.04); + m.lock(); + uLCD.circle(refarrow_down_x,refarrow_down_y,10,0x000000); + uLCD.locate(0,0); + uLCD.printf("%d",counter); + m.unlock(); + } + if(fire1){ + //nothing + } + arm.lock(); + if(ar.getTermStatus()){ + empty = true; + for(int i=0; i < 5; i++){ + if(ar.ActiveArrows[i].getActive()) { + empty = false; + break; + } + } + if(empty) { + scoreScreen = true; + uLCD.cls(); + uLCD2.cls(); + break; + } + } + arm.unlock(); + wait(0.01); + } + + //End of game + uLCD.cls(); + uLCD2.cls(); + if(counter > counter2){ + end_screen(); + uLCD.locate(6,6); + uLCD.color(GREEN); + uLCD.printf("YOU WIN!\n PLAYER 1 WINS!"); + uLCD2.locate(5,6); + uLCD2.color(RED); + uLCD2.printf("YOU LOSE!\n PLAYER 1 WINS!"); + end_screen(); + } + else if (counter2 > counter) { + end_screen(); + uLCD.locate(5,6); + uLCD.color(RED); + uLCD.printf("YOU LOSE!\n PLAYER 2 WINS!"); + uLCD2.locate(6,6); + uLCD.color(GREEN); + uLCD2.printf("YOU WIN!\n PLAYER 2 WINS!"); + end_screen(); + } + else { + end_screen(); + uLCD.locate(7,7); + uLCD.printf("DRAW"); + uLCD2.locate(7,7); + uLCD2.printf("DRAW"); + end_screen(); + } + wait(5); + uLCD.cls(); + uLCD2.cls(); + end_screen(); + uLCD.locate(6,6); + uLCD.color(GREEN); + uLCD.printf("Thanks\n for playing!"); + uLCD2.locate(6,6); + uLCD2.color(GREEN); + uLCD2.printf("Thanks\n for playing!"); + end_screen(); +}
diff -r 000000000000 -r 8a02ac09eae0 mbed-rtos.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-rtos.lib Fri Apr 29 02:04:07 2016 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/users/wliu88/code/mbed-rtos/#94371fac911d
diff -r 000000000000 -r 8a02ac09eae0 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Fri Apr 29 02:04:07 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/aae6fcc7d9bb \ No newline at end of file
diff -r 000000000000 -r 8a02ac09eae0 releaser.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/releaser.h Fri Apr 29 02:04:07 2016 +0000 @@ -0,0 +1,64 @@ +#ifndef RELEASER_H +#define RELEASER_H + + +#include "mbed.h" +#include "arrows.h" + +//releaser.h: responsible for keeping track of arrows that are active on the screen + +class ArrowReleaser { + private: + int terminate; + public: + Arrow ActiveArrows [10]; + ArrowReleaser(){ + for(int i=0; i< 10; i++){ + ActiveArrows[i] = Arrow(-1); + } + terminate = 0; + } + int ReleaseArrow(Arrow songArrows[], int indexSongArray, int screens){ + for(int i=0; i< 10; i++){ + if(!ActiveArrows[i].getActive()){ + //Empty space + ActiveArrows[i] = songArrows[indexSongArray]; + if(ActiveArrows[i].getType() == -1){ + ActiveArrows[i].setActive(0); + } + else { + ActiveArrows[i].setActive(1); + } + ActiveArrows[i].init(screens); + return 1; + } + } + return 0; + } + int ReleaseArrow2(Arrow songArrows[], int indexSongArray){ + for(int i=0; i< 7; i++){ + if(!ActiveArrows[i].getActive()){ + //Empty space + ActiveArrows[i] = songArrows[indexSongArray]; + if(ActiveArrows[i].getType() == -1){ + ActiveArrows[i].setActive(0); + } + else { + ActiveArrows[i].setActive(1); + } + ActiveArrows[i].init2(); + return 1; + } + } + return 0; + } + int getTermStatus(){ + return terminate; + } + void setTermStatus(int status){ + terminate = status; + } + +}; + +#endif \ No newline at end of file
diff -r 000000000000 -r 8a02ac09eae0 songs.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/songs.h Fri Apr 29 02:04:07 2016 +0000 @@ -0,0 +1,447 @@ +#ifndef SONGS_H +#define SONGS_H + +#include "arrows.h" + +Arrow DemoArray[60] = { + Arrow(1,0.50), + Arrow(1,0.50), + Arrow(1,0.50), + Arrow(3,0.70), + Arrow(1,0.80), + Arrow(0,1.20), + Arrow(1,1.20), + Arrow(3,1.10), + Arrow(3,0.50), + Arrow(1,0.90), + Arrow(0,1.10), + Arrow(0,0.80), + Arrow(3,0.60), + Arrow(3,1.20), + Arrow(2,0.70), + Arrow(3,0.80), + Arrow(0,1.20), + Arrow(2,0.80), + Arrow(2,0.50), + Arrow(0,0.70), + Arrow(2,0.90), + Arrow(2,0.60), + Arrow(1,0.50), + Arrow(3,0.70), + Arrow(2,1.10), + Arrow(2,1.00), + Arrow(0,1.10), + Arrow(0,0.90), + Arrow(1,1.20), + Arrow(2,0.70), + Arrow(0,0.60), + Arrow(1,1.10), + Arrow(3,0.90), + Arrow(2,1.10), + Arrow(3,1.20), + Arrow(1,0.50), + Arrow(1,1.00), + Arrow(2,1.10), + Arrow(1,0.50), + Arrow(0,0.50), + Arrow(0,0.70), + Arrow(2,1.10), + Arrow(2,0.80), + Arrow(0,1.00), + Arrow(3,0.50), + Arrow(2,0.50), + Arrow(3,0.80), + Arrow(0,1.10), + Arrow(2,0.60), + Arrow(3,0.90), + Arrow(3,1.00), + Arrow(2,0.60), + Arrow(0,0.80), + Arrow(0,0.80), + Arrow(2,1.10), + Arrow(3,0.90), + Arrow(3,1.00), + Arrow(2,0.60), + Arrow(0,0.80), + Arrow(0,0.80)}; +Arrow DemoArray2[60] = { + Arrow(3,0.70), + Arrow(1,0.90), + Arrow(1,1.10), + Arrow(2,0.70), + Arrow(0,1.30), + Arrow(3,1.10), + Arrow(2,1.20), + Arrow(0,0.80), + Arrow(0,1.10), + Arrow(3,0.90), + Arrow(1,1.10), + Arrow(3,1.00), + Arrow(1,1.30), + Arrow(0,0.80), + Arrow(3,1.00), + Arrow(3,1.00), + Arrow(3,0.70), + Arrow(2,1.00), + Arrow(1,1.00), + Arrow(0,0.70), + Arrow(0,0.90), + Arrow(3,1.00), + Arrow(1,1.00), + Arrow(3,0.90), + Arrow(2,1.20), + Arrow(0,0.80), + Arrow(0,1.20), + Arrow(2,0.90), + Arrow(0,1.20), + Arrow(2,1.00), + Arrow(3,0.90), + Arrow(2,0.80), + Arrow(1,1.10), + Arrow(2,1.00), + Arrow(3,1.20), + Arrow(2,1.20), + Arrow(1,0.80), + Arrow(2,1.20), + Arrow(0,1.30), + Arrow(1,0.80), + Arrow(0,1.20), + Arrow(3,0.90), + Arrow(2,0.90), + Arrow(3,1.00), + Arrow(2,1.10), + Arrow(3,0.70), + Arrow(2,1.10), + Arrow(0,0.80), + Arrow(2,1.30), + Arrow(2,1.10), + Arrow(3,1.30), + Arrow(0,1.00), + Arrow(0,1.00), + Arrow(2,1.10), + Arrow(3,1.10), + Arrow(2,1.20), + Arrow(1,0.80), + Arrow(0,0.80), + Arrow(1,0.90), + Arrow(2,1.00)}; + + + +//Arrow sequence for Animals.wav +/*Arrow AnimalArray[312] = { + Arrow(3,1.00), + Arrow(3,0.80), + Arrow(0,0.50), + Arrow(2,0.50), + Arrow(3,1.00), + Arrow(1,0.50), + Arrow(2,0.50), + Arrow(1,0.70), + Arrow(1,0.60), + Arrow(0,0.70), + Arrow(1,0.80), + Arrow(0,0.90), + Arrow(1,0.80), + Arrow(0,0.90), + Arrow(1,0.70), + Arrow(0,0.70), + Arrow(1,0.70), + Arrow(1,0.70), + Arrow(2,0.80), + Arrow(1,0.90), + Arrow(0,0.90), + Arrow(1,1.00), + Arrow(3,0.80), + Arrow(1,0.80), + Arrow(0,0.80), + Arrow(0,0.50), + Arrow(1,0.90), + Arrow(3,1.00), + Arrow(2,0.70), + Arrow(2,0.90), + Arrow(3,0.50), + Arrow(0,0.70), + Arrow(0,0.50), + Arrow(1,0.60), + Arrow(0,0.90), + Arrow(1,0.70), + Arrow(1,0.60), + Arrow(1,0.90), + Arrow(0,1.00), + Arrow(3,0.50), + Arrow(3,0.50), + Arrow(1,0.60), + Arrow(0,0.70), + Arrow(3,1.00), + Arrow(3,1.00), + Arrow(1,0.80), + Arrow(0,0.50), + Arrow(1,0.50), + Arrow(3,0.70), + Arrow(0,0.50), + Arrow(2,0.70), + Arrow(1,0.70), + Arrow(0,0.80), + Arrow(2,0.60), + Arrow(1,0.50), + Arrow(3,0.90), + Arrow(2,0.50), + Arrow(0,0.60), + Arrow(0,0.50), + Arrow(2,0.70), + Arrow(3,0.80), + Arrow(0,0.90), + Arrow(0,0.90), + Arrow(0,0.80), + Arrow(3,0.60), + Arrow(2,0.70), + Arrow(2,0.60), + Arrow(2,0.60), + Arrow(0,0.60), + Arrow(2,0.50), + Arrow(2,0.70), + Arrow(2,0.50), + Arrow(0,0.70), + Arrow(2,0.70), + Arrow(0,0.60), + Arrow(1,0.50), + Arrow(3,0.90), + Arrow(1,1.00), + Arrow(0,0.70), + Arrow(2,0.60), + Arrow(1,0.90), + Arrow(3,0.60), + Arrow(1,0.70), + Arrow(2,0.60), + Arrow(3,1.00), + Arrow(2,0.90), + Arrow(1,0.90), + Arrow(1,0.60), + Arrow(3,1.00), + Arrow(2,0.60), + Arrow(1,0.50), + Arrow(2,0.70), + Arrow(0,1.00), + Arrow(3,0.50), + Arrow(3,0.50), + Arrow(2,0.90), + Arrow(1,1.00), + Arrow(1,0.80), + Arrow(1,1.00), + Arrow(3,0.80), + Arrow(0,0.90), + Arrow(1,0.90), + Arrow(0,0.80), + Arrow(1,0.80), + Arrow(2,0.80), + Arrow(0,0.70), + Arrow(0,0.80), + Arrow(2,0.50), + Arrow(3,1.00), + Arrow(2,1.00), + Arrow(3,0.50), + Arrow(1,0.70), + Arrow(3,0.70), + Arrow(0,0.50), + Arrow(0,0.90), + Arrow(1,1.00), + Arrow(1,0.80), + Arrow(1,0.60), + Arrow(0,0.90), + Arrow(3,0.70), + Arrow(1,0.80), + Arrow(2,0.50), + Arrow(3,0.60), + Arrow(3,0.90), + Arrow(0,0.90), + Arrow(2,0.90), + Arrow(0,0.90), + Arrow(2,0.60), + Arrow(3,0.60), + Arrow(1,0.70), + Arrow(1,0.70), + Arrow(3,0.50), + Arrow(3,0.70), + Arrow(1,1.00), + Arrow(0,0.50), + Arrow(3,0.90), + Arrow(1,0.90), + Arrow(1,0.80), + Arrow(0,0.80), + Arrow(2,1.00), + Arrow(3,0.60), + Arrow(2,0.50), + Arrow(3,1.00), + Arrow(1,0.60), + Arrow(0,0.90), + Arrow(2,1.00), + Arrow(1,0.50), + Arrow(3,0.60), + Arrow(1,0.80), + Arrow(2,0.50), + Arrow(1,0.70), + Arrow(2,0.50), + Arrow(1,0.90), + Arrow(2,0.60), + Arrow(1,0.80), + Arrow(0,0.80), + Arrow(0,0.60), + Arrow(2,0.60), + Arrow(0,0.60), + Arrow(3,1.00), + Arrow(1,0.90), + Arrow(0,1.00), + Arrow(2,1.00), + Arrow(3,0.80), + Arrow(0,0.70), + Arrow(1,0.50), + Arrow(1,0.90), + Arrow(1,0.90), + Arrow(2,0.90), + Arrow(2,0.70), + Arrow(0,0.70), + Arrow(0,0.60), + Arrow(1,0.80), + Arrow(0,0.70), + Arrow(0,0.50), + Arrow(1,0.50), + Arrow(3,0.70), + Arrow(1,0.70), + Arrow(2,0.60), + Arrow(0,0.70), + Arrow(3,0.50), + Arrow(1,0.90), + Arrow(2,0.50), + Arrow(1,0.80), + Arrow(1,0.50), + Arrow(2,0.90), + Arrow(1,0.50), + Arrow(3,0.60), + Arrow(1,1.00), + Arrow(1,1.00), + Arrow(1,1.00), + Arrow(3,0.80), + Arrow(3,0.80), + Arrow(3,0.90), + Arrow(0,0.50), + Arrow(3,0.70), + Arrow(3,0.60), + Arrow(0,0.60), + Arrow(0,0.60), + Arrow(2,0.90), + Arrow(3,1.00), + Arrow(0,0.60), + Arrow(3,0.50), + Arrow(1,1.00), + Arrow(2,0.60), + Arrow(2,0.50), + Arrow(3,0.50), + Arrow(0,0.50), + Arrow(2,0.90), + Arrow(0,0.60), + Arrow(3,0.90), + Arrow(3,0.50), + Arrow(3,0.90), + Arrow(3,0.80), + Arrow(3,0.50), + Arrow(1,0.90), + Arrow(1,0.80), + Arrow(0,0.70), + Arrow(2,0.60), + Arrow(3,0.90), + Arrow(1,1.00), + Arrow(0,0.60), + Arrow(0,0.90), + Arrow(0,1.00), + Arrow(3,0.50), + Arrow(2,0.50), + Arrow(3,1.00), + Arrow(0,0.70), + Arrow(0,0.70), + Arrow(2,0.60), + Arrow(1,0.50), + Arrow(0,0.70), + Arrow(2,0.60), + Arrow(0,0.50), + Arrow(0,0.70), + Arrow(1,0.70), + Arrow(1,0.70), + Arrow(1,1.00), + Arrow(3,0.80), + Arrow(1,1.00), + Arrow(3,1.00), + Arrow(0,0.80), + Arrow(0,0.50), + Arrow(2,0.70), + Arrow(0,0.60), + Arrow(1,0.70), + Arrow(3,0.90), + Arrow(2,1.00), + Arrow(2,1.00), + Arrow(0,1.00), + Arrow(3,0.90), + Arrow(2,0.80), + Arrow(3,0.70), + Arrow(1,1.00), + Arrow(0,0.60), + Arrow(0,0.80), + Arrow(2,0.60), + Arrow(2,0.90), + Arrow(1,0.90), + Arrow(3,0.50), + Arrow(2,0.90), + Arrow(2,0.90), + Arrow(2,0.90), + Arrow(2,0.50), + Arrow(3,0.60), + Arrow(1,0.90), + Arrow(2,0.70), + Arrow(0,1.00), + Arrow(3,0.60), + Arrow(1,0.90), + Arrow(0,0.70), + Arrow(2,0.90), + Arrow(3,0.60), + Arrow(0,0.70), + Arrow(3,0.80), + Arrow(2,0.80), + Arrow(1,0.90), + Arrow(3,0.70), + Arrow(2,1.00), + Arrow(3,0.80), + Arrow(0,1.00), + Arrow(3,0.50), + Arrow(1,0.90), + Arrow(2,0.80), + Arrow(0,0.80), + Arrow(3,0.90), + Arrow(0,1.00), + Arrow(3,1.00), + Arrow(0,0.80), + Arrow(0,0.60), + Arrow(2,0.60), + Arrow(2,0.70), + Arrow(2,0.90), + Arrow(2,0.90), + Arrow(0,0.50), + Arrow(2,0.90), + Arrow(2,0.90), + Arrow(3,0.60), + Arrow(3,0.50), + Arrow(0,0.70), + Arrow(2,0.50), + Arrow(3,0.60), + Arrow(0,0.90), + Arrow(0,0.60), + Arrow(1,1.00), + Arrow(3,0.60), + Arrow(2,0.80), + Arrow(3,0.60), + Arrow(2,0.80), + Arrow(3,0.90), + Arrow(2,0.90), + Arrow(2,1.00) +};*/ + +#endif \ No newline at end of file
diff -r 000000000000 -r 8a02ac09eae0 wave_player.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/wave_player.lib Fri Apr 29 02:04:07 2016 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/sravet/code/wave_player/#acc3e18e77ad