Jubeat (ユビート Yubīto?), stylized as jubeat, is a series of arcade music video games developed by Konami Computer Entertainment Japan, and is a part of Konami's Bemani line of music video games. The series uses an arrangement of 16 buttons in a 4x4 grid for gameplay, a grid also used for the displaying of cues and part of the user interface.
Dependencies: 4DGL-uLCD-SE SDFileSystem TextLCD mbed-rtos mbed wave_player
Fork of ECE4180_Lab4 by
main.cpp@0:c3c8793d0091, 2016-03-16 (annotated)
- Committer:
- ToHellWithGeorgi
- Date:
- Wed Mar 16 13:38:50 2016 +0000
- Revision:
- 0:c3c8793d0091
ECE 4180 jubeat;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ToHellWithGeorgi | 0:c3c8793d0091 | 1 | #include "mbed.h" |
ToHellWithGeorgi | 0:c3c8793d0091 | 2 | #include "rtos.h" |
ToHellWithGeorgi | 0:c3c8793d0091 | 3 | #include "uLCD_4DGL.h" |
ToHellWithGeorgi | 0:c3c8793d0091 | 4 | #include "SDFileSystem.h" |
ToHellWithGeorgi | 0:c3c8793d0091 | 5 | #include "wave_player.h" |
ToHellWithGeorgi | 0:c3c8793d0091 | 6 | #include "VS1002.h" |
ToHellWithGeorgi | 0:c3c8793d0091 | 7 | #include <mpr121.h> |
ToHellWithGeorgi | 0:c3c8793d0091 | 8 | |
ToHellWithGeorgi | 0:c3c8793d0091 | 9 | //SDFileSystem sd(p5, p6, p7, p8, "sd"); |
ToHellWithGeorgi | 0:c3c8793d0091 | 10 | uLCD_4DGL uLCD(p28,p27,p30); |
ToHellWithGeorgi | 0:c3c8793d0091 | 11 | Serial pc(USBTX, USBRX); |
ToHellWithGeorgi | 0:c3c8793d0091 | 12 | VS1002 mp3(p5, p6, p7, p8,"sd",p11, p12 ,p13, p14, p23, p22, p21, p20); |
ToHellWithGeorgi | 0:c3c8793d0091 | 13 | LocalFileSystem local("local"); |
ToHellWithGeorgi | 0:c3c8793d0091 | 14 | //AnalogOut DACout(p18); // used to play sound on speaker |
ToHellWithGeorgi | 0:c3c8793d0091 | 15 | //wave_player waver(&DACout); |
ToHellWithGeorgi | 0:c3c8793d0091 | 16 | //This is for the touchpad |
ToHellWithGeorgi | 0:c3c8793d0091 | 17 | I2C i2c(p9, p10); |
ToHellWithGeorgi | 0:c3c8793d0091 | 18 | InterruptIn interrupt(p26); |
ToHellWithGeorgi | 0:c3c8793d0091 | 19 | Mpr121 mpr121(&i2c, Mpr121::ADD_VSS); |
ToHellWithGeorgi | 0:c3c8793d0091 | 20 | |
ToHellWithGeorgi | 0:c3c8793d0091 | 21 | int start = 0; |
ToHellWithGeorgi | 0:c3c8793d0091 | 22 | |
ToHellWithGeorgi | 0:c3c8793d0091 | 23 | int new_song_number=1; //Variable to store the Song Number |
ToHellWithGeorgi | 0:c3c8793d0091 | 24 | int volume_set=-1; //Variable to store the Volume |
ToHellWithGeorgi | 0:c3c8793d0091 | 25 | int previous_volume; //Variable to store the volume when muted |
ToHellWithGeorgi | 0:c3c8793d0091 | 26 | bool pause=false; //Variable to store the status of Pause button |
ToHellWithGeorgi | 0:c3c8793d0091 | 27 | bool mute=false; //Variable to store the status of mute button |
ToHellWithGeorgi | 0:c3c8793d0091 | 28 | |
ToHellWithGeorgi | 0:c3c8793d0091 | 29 | int check=0; //Capacitative touch generates interrupt on both press and release. This variable tracks this and updates only on press. |
ToHellWithGeorgi | 0:c3c8793d0091 | 30 | char *song_name[6]={"18 till I Die","Summer of 69","Boulevard", "Serenity","Crawling","In the end"}; //Array of song names entered manually |
ToHellWithGeorgi | 0:c3c8793d0091 | 31 | int chosennum=-1; |
ToHellWithGeorgi | 0:c3c8793d0091 | 32 | int playing=0; |
ToHellWithGeorgi | 0:c3c8793d0091 | 33 | int score=0; |
ToHellWithGeorgi | 0:c3c8793d0091 | 34 | int fullscore; |
ToHellWithGeorgi | 0:c3c8793d0091 | 35 | |
ToHellWithGeorgi | 0:c3c8793d0091 | 36 | Mutex ulcd_mutex; |
ToHellWithGeorgi | 0:c3c8793d0091 | 37 | Mutex sd_mutex; |
ToHellWithGeorgi | 0:c3c8793d0091 | 38 | |
ToHellWithGeorgi | 0:c3c8793d0091 | 39 | void fallInterrupt() { |
ToHellWithGeorgi | 0:c3c8793d0091 | 40 | int key_code=0; |
ToHellWithGeorgi | 0:c3c8793d0091 | 41 | int i=0; |
ToHellWithGeorgi | 0:c3c8793d0091 | 42 | int value=mpr121.read(0x00); |
ToHellWithGeorgi | 0:c3c8793d0091 | 43 | value +=mpr121.read(0x01)<<8; |
ToHellWithGeorgi | 0:c3c8793d0091 | 44 | // LED demo mod by J. Hamblen |
ToHellWithGeorgi | 0:c3c8793d0091 | 45 | //pc.printf("MPR value: %x \r\n", value); |
ToHellWithGeorgi | 0:c3c8793d0091 | 46 | i=0; |
ToHellWithGeorgi | 0:c3c8793d0091 | 47 | // puts key number out to LEDs for demo |
ToHellWithGeorgi | 0:c3c8793d0091 | 48 | for (i=0; i<12; i++) { |
ToHellWithGeorgi | 0:c3c8793d0091 | 49 | if (((value>>i)&0x01)==1) key_code=i+1; |
ToHellWithGeorgi | 0:c3c8793d0091 | 50 | } |
ToHellWithGeorgi | 0:c3c8793d0091 | 51 | check=1; |
ToHellWithGeorgi | 0:c3c8793d0091 | 52 | //pc.printf("%d ",playing); |
ToHellWithGeorgi | 0:c3c8793d0091 | 53 | //if(!playing){ |
ToHellWithGeorgi | 0:c3c8793d0091 | 54 | chosennum=key_code; |
ToHellWithGeorgi | 0:c3c8793d0091 | 55 | //} |
ToHellWithGeorgi | 0:c3c8793d0091 | 56 | } |
ToHellWithGeorgi | 0:c3c8793d0091 | 57 | |
ToHellWithGeorgi | 0:c3c8793d0091 | 58 | class square { |
ToHellWithGeorgi | 0:c3c8793d0091 | 59 | public: |
ToHellWithGeorgi | 0:c3c8793d0091 | 60 | int startx,starty,side,pos; |
ToHellWithGeorgi | 0:c3c8793d0091 | 61 | |
ToHellWithGeorgi | 0:c3c8793d0091 | 62 | |
ToHellWithGeorgi | 0:c3c8793d0091 | 63 | /*function*/ |
ToHellWithGeorgi | 0:c3c8793d0091 | 64 | square(){}; |
ToHellWithGeorgi | 0:c3c8793d0091 | 65 | square(int sx,int sy,int s,int p):startx(sx),starty(sy),side(s),pos(p){}; |
ToHellWithGeorgi | 0:c3c8793d0091 | 66 | void set(int sx, int sy, int s,int p){startx = sx;starty = sy;side = s;pos = p;}; |
ToHellWithGeorgi | 0:c3c8793d0091 | 67 | // draw the block on the LCD |
ToHellWithGeorgi | 0:c3c8793d0091 | 68 | void draw() {//draw a empty block on the LCD |
ToHellWithGeorgi | 0:c3c8793d0091 | 69 | uLCD.rectangle(startx,starty,startx+side,starty+side,0x00FF00); |
ToHellWithGeorgi | 0:c3c8793d0091 | 70 | } |
ToHellWithGeorgi | 0:c3c8793d0091 | 71 | void show() {//emerge the color inside the block |
ToHellWithGeorgi | 0:c3c8793d0091 | 72 | uLCD.filled_rectangle(startx+4, starty+4, startx+side-4, starty+side-4, 0x333300); |
ToHellWithGeorgi | 0:c3c8793d0091 | 73 | wait(0.1); |
ToHellWithGeorgi | 0:c3c8793d0091 | 74 | uLCD.filled_rectangle(startx+4, starty+4, startx+side-4, starty+side-4, 0x666600); |
ToHellWithGeorgi | 0:c3c8793d0091 | 75 | wait(0.1); |
ToHellWithGeorgi | 0:c3c8793d0091 | 76 | uLCD.filled_rectangle(startx+4, starty+4, startx+side-4, starty+side-4, 0x999900); |
ToHellWithGeorgi | 0:c3c8793d0091 | 77 | wait(0.1); |
ToHellWithGeorgi | 0:c3c8793d0091 | 78 | uLCD.filled_rectangle(startx+4, starty+4, startx+side-4, starty+side-4, 0xCCCC00); |
ToHellWithGeorgi | 0:c3c8793d0091 | 79 | wait(0.1); |
ToHellWithGeorgi | 0:c3c8793d0091 | 80 | uLCD.filled_rectangle(startx+4, starty+4, startx+side-4, starty+side-4, 0xFFFF00); |
ToHellWithGeorgi | 0:c3c8793d0091 | 81 | wait(0.1); |
ToHellWithGeorgi | 0:c3c8793d0091 | 82 | if(pos==chosennum){hit();score++;} |
ToHellWithGeorgi | 0:c3c8793d0091 | 83 | else{miss();} |
ToHellWithGeorgi | 0:c3c8793d0091 | 84 | |
ToHellWithGeorgi | 0:c3c8793d0091 | 85 | } |
ToHellWithGeorgi | 0:c3c8793d0091 | 86 | void hit() { |
ToHellWithGeorgi | 0:c3c8793d0091 | 87 | uLCD.filled_rectangle(startx+4, starty+4, startx+side-4, starty+side-4, 0x00FF00); |
ToHellWithGeorgi | 0:c3c8793d0091 | 88 | wait(0.1); |
ToHellWithGeorgi | 0:c3c8793d0091 | 89 | uLCD.filled_rectangle(startx+4, starty+4, startx+side-4, starty+side-4, 0x000000); |
ToHellWithGeorgi | 0:c3c8793d0091 | 90 | } |
ToHellWithGeorgi | 0:c3c8793d0091 | 91 | void miss() { |
ToHellWithGeorgi | 0:c3c8793d0091 | 92 | uLCD.filled_rectangle(startx+4, starty+4, startx+side-4, starty+side-4, 0xFF0000); |
ToHellWithGeorgi | 0:c3c8793d0091 | 93 | wait(0.1); |
ToHellWithGeorgi | 0:c3c8793d0091 | 94 | uLCD.filled_rectangle(startx+4, starty+4, startx+side-4, starty+side-4, 0x000000); |
ToHellWithGeorgi | 0:c3c8793d0091 | 95 | } |
ToHellWithGeorgi | 0:c3c8793d0091 | 96 | }; |
ToHellWithGeorgi | 0:c3c8793d0091 | 97 | |
ToHellWithGeorgi | 0:c3c8793d0091 | 98 | void graph(void const *args) |
ToHellWithGeorgi | 0:c3c8793d0091 | 99 | { |
ToHellWithGeorgi | 0:c3c8793d0091 | 100 | while(!start){wait(0.5);} |
ToHellWithGeorgi | 0:c3c8793d0091 | 101 | pc.printf("i can start from now"); |
ToHellWithGeorgi | 0:c3c8793d0091 | 102 | ulcd_mutex.lock(); |
ToHellWithGeorgi | 0:c3c8793d0091 | 103 | square a[9]; |
ToHellWithGeorgi | 0:c3c8793d0091 | 104 | a[0].set(1,1,40,1); |
ToHellWithGeorgi | 0:c3c8793d0091 | 105 | a[1].set(44,1,40,2); |
ToHellWithGeorgi | 0:c3c8793d0091 | 106 | a[2].set(87,1,40,3); |
ToHellWithGeorgi | 0:c3c8793d0091 | 107 | a[3].set(1,44,40,5); |
ToHellWithGeorgi | 0:c3c8793d0091 | 108 | a[4].set(44,44,40,6); |
ToHellWithGeorgi | 0:c3c8793d0091 | 109 | a[5].set(87,44,40,7); |
ToHellWithGeorgi | 0:c3c8793d0091 | 110 | a[6].set(1,87,40,9); |
ToHellWithGeorgi | 0:c3c8793d0091 | 111 | a[7].set(44,87,40,10); |
ToHellWithGeorgi | 0:c3c8793d0091 | 112 | a[8].set(87,87,40,11); |
ToHellWithGeorgi | 0:c3c8793d0091 | 113 | a[0].draw();a[1].draw();a[2].draw(); |
ToHellWithGeorgi | 0:c3c8793d0091 | 114 | a[3].draw();a[4].draw();a[5].draw(); |
ToHellWithGeorgi | 0:c3c8793d0091 | 115 | a[6].draw();a[7].draw();a[8].draw(); |
ToHellWithGeorgi | 0:c3c8793d0091 | 116 | |
ToHellWithGeorgi | 0:c3c8793d0091 | 117 | FILE *fp = fopen("/local/2.txt", "r"); |
ToHellWithGeorgi | 0:c3c8793d0091 | 118 | int screen=-1; |
ToHellWithGeorgi | 0:c3c8793d0091 | 119 | int waitmm=0; |
ToHellWithGeorgi | 0:c3c8793d0091 | 120 | int numnode=-1; |
ToHellWithGeorgi | 0:c3c8793d0091 | 121 | int counter = 0; |
ToHellWithGeorgi | 0:c3c8793d0091 | 122 | fscanf(fp,"%d",&numnode); |
ToHellWithGeorgi | 0:c3c8793d0091 | 123 | fullscore=numnode; |
ToHellWithGeorgi | 0:c3c8793d0091 | 124 | while(counter < numnode) { |
ToHellWithGeorgi | 0:c3c8793d0091 | 125 | fscanf(fp,"%d %d",&screen, &waitmm); |
ToHellWithGeorgi | 0:c3c8793d0091 | 126 | //uLCD.printf("%d %d\n", screen, waitmm); |
ToHellWithGeorgi | 0:c3c8793d0091 | 127 | a[screen].show(); |
ToHellWithGeorgi | 0:c3c8793d0091 | 128 | wait(float(waitmm)/1000); |
ToHellWithGeorgi | 0:c3c8793d0091 | 129 | counter++; |
ToHellWithGeorgi | 0:c3c8793d0091 | 130 | } |
ToHellWithGeorgi | 0:c3c8793d0091 | 131 | ulcd_mutex.unlock(); |
ToHellWithGeorgi | 0:c3c8793d0091 | 132 | |
ToHellWithGeorgi | 0:c3c8793d0091 | 133 | } |
ToHellWithGeorgi | 0:c3c8793d0091 | 134 | |
ToHellWithGeorgi | 0:c3c8793d0091 | 135 | int main() { |
ToHellWithGeorgi | 0:c3c8793d0091 | 136 | //Thread thread2(speaker); |
ToHellWithGeorgi | 0:c3c8793d0091 | 137 | interrupt.fall(&fallInterrupt); |
ToHellWithGeorgi | 0:c3c8793d0091 | 138 | interrupt.mode(PullUp); |
ToHellWithGeorgi | 0:c3c8793d0091 | 139 | |
ToHellWithGeorgi | 0:c3c8793d0091 | 140 | Thread thread2(graph); |
ToHellWithGeorgi | 0:c3c8793d0091 | 141 | |
ToHellWithGeorgi | 0:c3c8793d0091 | 142 | |
ToHellWithGeorgi | 0:c3c8793d0091 | 143 | uLCD.cls(); |
ToHellWithGeorgi | 0:c3c8793d0091 | 144 | uLCD.media_init(); |
ToHellWithGeorgi | 0:c3c8793d0091 | 145 | uLCD.set_sector_address(0x0000, 0x0099); |
ToHellWithGeorgi | 0:c3c8793d0091 | 146 | uLCD.display_video(0,0); |
ToHellWithGeorgi | 0:c3c8793d0091 | 147 | uLCD.cls(); |
ToHellWithGeorgi | 0:c3c8793d0091 | 148 | |
ToHellWithGeorgi | 0:c3c8793d0091 | 149 | ulcd_mutex.lock(); |
ToHellWithGeorgi | 0:c3c8793d0091 | 150 | uLCD.printf("This is game of Jubeat\n\npick a song you want to play\n\n1. Lovers on the Sun\n2.Man At Arms\n"); |
ToHellWithGeorgi | 0:c3c8793d0091 | 151 | while(!check){wait(0.1);} |
ToHellWithGeorgi | 0:c3c8793d0091 | 152 | uLCD.printf("You chosen song: %d",chosennum); |
ToHellWithGeorgi | 0:c3c8793d0091 | 153 | wait(1); |
ToHellWithGeorgi | 0:c3c8793d0091 | 154 | uLCD.cls(); |
ToHellWithGeorgi | 0:c3c8793d0091 | 155 | ulcd_mutex.unlock(); |
ToHellWithGeorgi | 0:c3c8793d0091 | 156 | pc.printf("mutex unlocked!\n"); |
ToHellWithGeorgi | 0:c3c8793d0091 | 157 | /* |
ToHellWithGeorgi | 0:c3c8793d0091 | 158 | square a[9]; |
ToHellWithGeorgi | 0:c3c8793d0091 | 159 | a[0].set(1,1,40); |
ToHellWithGeorgi | 0:c3c8793d0091 | 160 | a[1].set(44,1,40); |
ToHellWithGeorgi | 0:c3c8793d0091 | 161 | a[2].set(87,1,40); |
ToHellWithGeorgi | 0:c3c8793d0091 | 162 | a[3].set(1,44,40); |
ToHellWithGeorgi | 0:c3c8793d0091 | 163 | a[4].set(44,44,40); |
ToHellWithGeorgi | 0:c3c8793d0091 | 164 | a[5].set(87,44,40); |
ToHellWithGeorgi | 0:c3c8793d0091 | 165 | a[6].set(1,87,40); |
ToHellWithGeorgi | 0:c3c8793d0091 | 166 | a[7].set(44,87,40); |
ToHellWithGeorgi | 0:c3c8793d0091 | 167 | a[8].set(87,87,40); |
ToHellWithGeorgi | 0:c3c8793d0091 | 168 | a[0].draw();a[1].draw();a[2].draw(); |
ToHellWithGeorgi | 0:c3c8793d0091 | 169 | a[3].draw();a[4].draw();a[5].draw(); |
ToHellWithGeorgi | 0:c3c8793d0091 | 170 | a[6].draw();a[7].draw();a[8].draw(); |
ToHellWithGeorgi | 0:c3c8793d0091 | 171 | */ |
ToHellWithGeorgi | 0:c3c8793d0091 | 172 | |
ToHellWithGeorgi | 0:c3c8793d0091 | 173 | mp3._RST = 1; |
ToHellWithGeorgi | 0:c3c8793d0091 | 174 | mp3.cs_high(); //chip disabled |
ToHellWithGeorgi | 0:c3c8793d0091 | 175 | mp3.sci_initialise(); //initialise MBED |
ToHellWithGeorgi | 0:c3c8793d0091 | 176 | mp3.sci_write(0x00,(SM_SDINEW+SM_STREAM+SM_DIFF)); |
ToHellWithGeorgi | 0:c3c8793d0091 | 177 | mp3.sci_write(0x03, 0x9800); |
ToHellWithGeorgi | 0:c3c8793d0091 | 178 | mp3.sdi_initialise(); |
ToHellWithGeorgi | 0:c3c8793d0091 | 179 | |
ToHellWithGeorgi | 0:c3c8793d0091 | 180 | start=1; |
ToHellWithGeorgi | 0:c3c8793d0091 | 181 | //while(1) |
ToHellWithGeorgi | 0:c3c8793d0091 | 182 | //{ |
ToHellWithGeorgi | 0:c3c8793d0091 | 183 | //playing=1; |
ToHellWithGeorgi | 0:c3c8793d0091 | 184 | mp3.play_song(1); |
ToHellWithGeorgi | 0:c3c8793d0091 | 185 | //playing=0; |
ToHellWithGeorgi | 0:c3c8793d0091 | 186 | //} |
ToHellWithGeorgi | 0:c3c8793d0091 | 187 | |
ToHellWithGeorgi | 0:c3c8793d0091 | 188 | ulcd_mutex.lock(); |
ToHellWithGeorgi | 0:c3c8793d0091 | 189 | uLCD.cls(); |
ToHellWithGeorgi | 0:c3c8793d0091 | 190 | |
ToHellWithGeorgi | 0:c3c8793d0091 | 191 | uLCD.printf("congratulation!\n\nYour score is:\n\n%d \nout of %d",score,fullscore); |
ToHellWithGeorgi | 0:c3c8793d0091 | 192 | wait(3); |
ToHellWithGeorgi | 0:c3c8793d0091 | 193 | ulcd_mutex.unlock(); |
ToHellWithGeorgi | 0:c3c8793d0091 | 194 | while(1){} |
ToHellWithGeorgi | 0:c3c8793d0091 | 195 | |
ToHellWithGeorgi | 0:c3c8793d0091 | 196 | |
ToHellWithGeorgi | 0:c3c8793d0091 | 197 | } |