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 Zhihan Jiang

Files at this revision

API Documentation at this revision

Comitter:
ToHellWithGeorgi
Date:
Wed Mar 16 13:38:50 2016 +0000
Commit message:
ECE 4180 jubeat;

Changed in this revision

4DGL-uLCD-SE.lib Show annotated file Show diff for this revision Revisions of this file
SDFileSystem.lib Show annotated file Show diff for this revision Revisions of this file
TextLCD.lib Show annotated file Show diff for this revision Revisions of this file
VS1002.cpp Show annotated file Show diff for this revision Revisions of this file
VS1002.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-rtos.lib Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
mpr121.cpp Show annotated file Show diff for this revision Revisions of this file
mpr121.h Show annotated file Show diff for this revision Revisions of this file
wave_player.lib Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/4DGL-uLCD-SE.lib	Wed Mar 16 13:38:50 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/4180_1/code/4DGL-uLCD-SE/#2cb1845d7681
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SDFileSystem.lib	Wed Mar 16 13:38:50 2016 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/neilt6/code/SDFileSystem/#c2c1f0b16380
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TextLCD.lib	Wed Mar 16 13:38:50 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/benyun/code/TextLCD/#7dd9751172e1
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/VS1002.cpp	Wed Mar 16 13:38:50 2016 +0000
@@ -0,0 +1,240 @@
+#include "VS1002.h"
+#include "mbed.h"
+#include "SDFileSystem.h"
+
+//Serial pc(USBTX, USBRX);
+//TextLCD lcd(p30, p29, p17, p18, p19, p20);
+
+/* ==================================================================
+ * Constructor
+ * =================================================================*/
+
+VS1002::VS1002(PinName mmosi, PinName mmiso, PinName ssck, PinName ccs, const char *name, PinName mosi, PinName miso, PinName sck, PinName cs, PinName rst, PinName dreq, PinName dcs, PinName vol)
+    : _sd(mmosi, mmiso, ssck, ccs, name), _spi(mosi, miso, sck), _CS(cs), _RST(rst), _DREQ(dreq), _DCS(dcs), _VOL(vol) {
+
+    }    
+
+/*===================================================================
+ * Functions
+ *==================================================================*/
+ 
+void VS1002::cs_low(void)
+{
+    _CS = 0;                                
+}
+void VS1002::cs_high(void)
+{
+    _CS = 1;                                
+}
+void VS1002::dcs_low(void)
+{
+    _DCS = 0;
+}
+void VS1002::dcs_high(void)
+{
+    _DCS = 1;
+}
+void VS1002::sci_en(void)                    //SCI enable
+{
+    cs_high();
+    dcs_high();
+    cs_low();
+}
+void VS1002::sci_dis(void)                    //SCI disable
+{
+    cs_high();
+}
+void VS1002::sdi_en(void)                    //SDI enable
+{
+    dcs_high();
+    cs_high();
+    dcs_low();
+}
+void VS1002::sdi_dis(void)                    //SDI disable
+{
+    dcs_high();
+}
+void VS1002::reset(void)                    //hardware reset
+{
+    wait(0.01);
+    _RST = 0;
+    wait(0.01);
+    _RST = 1;
+    wait(0.10);
+}
+void VS1002::power_down(void)                //hardware and software reset
+{
+    cs_low();
+    reset();
+    sci_write(0x00, SM_PDOWN);
+    wait(0.01);
+    reset();
+}
+void VS1002::sci_initialise(void)
+{
+    _RST = 1;                                //no reset
+    _spi.format(8,0);                        //spi 8bit interface, steady state low
+    _spi.frequency(1000000);                //rising edge data record, freq. 1Mhz
+    
+    cs_low();
+    for(int i=0; i<4; i++)
+    {
+    _spi.write(0xFF);                        //clock the chip a bit
+    }
+    cs_high();
+    dcs_high();
+    wait_us(5);
+}
+void VS1002::sdi_initialise(void)
+{
+    _spi.format(8,0);
+    _spi.frequency(7000000);                //set to 7MHz
+    
+    cs_high();
+    dcs_high();
+}
+void VS1002::sci_write(unsigned char address, unsigned short int data)
+{
+    sci_en();                                //enables SCI/disables SDI
+    
+    while(!_DREQ);                            //wait unitl data request is high
+    _spi.write(0x02);                        //SCI write
+    _spi.write(address);                    //register address
+    _spi.write((data >> 8) & 0xFF);            //write out first half of data word
+    _spi.write(data & 0xFF);                //write out second half of data word
+    
+    sci_dis();                                //enables SDI/disables SCI
+    wait_us(5);
+}
+void VS1002::sdi_write(unsigned char datum)
+{
+    sdi_en();
+    
+    while(!_DREQ);
+    _spi.write(datum);
+    
+    sci_dis();
+}
+unsigned short int VS1002::read(unsigned short int address)
+{
+    cs_low();                                //enables SCI/disables SDI
+    
+    while(!_DREQ);                            //wait unitl data request is high
+    _spi.write(0x03);                        //SCI write
+    _spi.write(address);                    //register address
+    unsigned short int received = _spi.write(0x00);    //write out dummy byte
+    received <<= 8;
+    received += _spi.write(0x00);            //write out dummy byte
+    
+    cs_high();                                //enables SDI/disables SCI
+    
+    return received;                        //return received word
+}
+void VS1002::sine_test_activate(unsigned char wave)
+{
+    cs_high();                                //enables SDI/disables SCI
+    
+    while(!_DREQ);                            //wait unitl data request is high
+    _spi.write(0x53);                        //SDI write
+    _spi.write(0xEF);                        //SDI write
+    _spi.write(0x6E);                        //SDI write
+    _spi.write(wave);                        //SDI write
+    _spi.write(0x00);                        //filler byte
+    _spi.write(0x00);                        //filler byte
+    _spi.write(0x00);                        //filler byte
+    _spi.write(0x00);                        //filler byte
+
+    cs_low();                                //enables SCI/disables SDI
+}
+void VS1002::sine_test_deactivate(void)
+{
+    cs_high();
+    
+    while(!_DREQ);
+    _spi.write(0x45);                        //SDI write
+    _spi.write(0x78);                        //SDI write
+    _spi.write(0x69);                        //SDI write
+    _spi.write(0x74);                        //SDI write
+    _spi.write(0x00);                        //filler byte
+    _spi.write(0x00);                        //filler byte
+    _spi.write(0x00);                        //filler byte
+    _spi.write(0x00);                        //filler byte
+}
+
+
+void VS1002::volume(signed int left, signed int right)
+{
+    while(_DREQ == 0);
+       
+    unsigned short int _left = -left;       //convert the decibel values into a format
+    unsigned short int _right = -right;     //readable by the chip cf. datasheet p.32 subsection 8.6.11
+    _left *= 2;
+    _right *= 2;
+    unsigned short int attenuation = ((256 * _left) + _right);
+    cs_low();
+    sci_write(0x0B, attenuation);               //writeout these values
+    cs_high();
+}
+
+void VS1002::play_song(int song_number)
+{
+    /*====== Song Select ======*/
+    
+    char str[16] = "/sd/music/";        //folder where the songs are located
+    sprintf(str+10,"%d",song_number);   //appending song number to path of the file
+    strcat(str,".mp3");                 //appending .mp3 to file name
+    FILE *song;
+    //pc.printf("%s",str);
+    unsigned char array[512];           //array for reading data from file
+    bool play_new=false;                // Variable to see if new_song has be assigned or not
+        
+    song = fopen(str, "r");    // Open the music file in read mode
+    //pc.printf("end reading music");
+    
+    /* Printing to LCD the present status */
+    // lcd.cls();
+  if(pause)
+   // lcd.printf("Paused ");
+  if(mute)
+  // lcd.printf("Muted");
+  if(!mute && !pause)
+  // lcd.printf("Playing"); 
+
+  //lcd.printf("\n %d %s",new_song_number,song_name[new_song_number-1]);
+   
+    if(!song) 
+    {
+     //   lcd.printf("\n \n Error!!");
+        exit(1);
+    }
+      while(!feof(song))
+    {
+            if(!pause)
+           {
+          
+           fread(&array, 1, 512, song);           
+           for(int i=0; i<512; i++)
+           {
+                sdi_write(array[i]);
+           }
+           volume(volume_set,volume_set);
+           }
+          if(new_song_number!=song_number)
+           {
+            play_new=true;
+             break;
+            }
+             
+             
+          }
+    
+           fclose(song);                              //close the file
+
+      if(!play_new)
+      {
+     new_song_number+=1;               // Goto Next song on completion of one song
+     if(new_song_number==7)
+      new_song_number=1; 
+     play_new=false;                   
+     }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/VS1002.h	Wed Mar 16 13:38:50 2016 +0000
@@ -0,0 +1,76 @@
+#ifndef VS1002_H
+#define VS1002_H
+
+#include "mbed.h"
+#include "SDFileSystem.h"
+#include "string"
+#include "string.h"
+#include "TextLCD.h"
+
+
+//SCI_MODE register bits as of p.26 of the datasheet
+#define SM_DIFF            0x0001
+#define SM_SETTOZERO    0x0002
+#define SM_RESET        0x0004
+#define SM_OUTOFWAV        0x0008
+#define SM_PDOWN        0x0010
+#define SM_TESTS        0x0020
+#define    SM_STREAM        0x0040
+#define SM_PLUSV        0x0080
+#define    SM_DACT            0x0100
+#define    SM_SDIORD        0x0200
+#define    SM_SDISHARE        0x0400
+#define    SM_SDINEW        0x0800
+#define    SM_ADPCM        0x1000
+#define    SM_ADPCM_HP        0x2000
+
+extern int new_song_number;
+extern int volume_set;
+extern bool pause;
+extern bool mute;
+extern char * song_name[6];
+
+
+class VS1002  {
+
+public:
+
+    VS1002(PinName mmosi, PinName mmiso, PinName ssck, PinName ccs, const char *name, PinName mosi, PinName miso, PinName sck, PinName cs, PinName rst, PinName dreq, PinName dcs, PinName vol);
+    
+    void cs_low(void); 
+    void cs_high(void);
+    void dcs_low(void);
+    void dcs_high(void);
+    void sci_en(void);
+    void sci_dis(void);
+    void sdi_en(void);
+    void sdi_dis(void);
+    
+    void sci_initialise(void);
+    void sdi_initialise(void);
+    void reset(void);
+    void power_down(void);
+ 
+    void sci_write(unsigned char, unsigned short int);
+    void sdi_write(unsigned char);
+    unsigned short int read(unsigned short int);
+    void sine_test_activate(unsigned char);
+    void volume(signed int,signed int);
+    void sine_test_deactivate(void);
+    void play_song(int);
+    
+    int num_of_files;
+    
+    DigitalIn _DREQ;
+    DigitalOut _RST;
+    AnalogIn _VOL;
+    
+protected:
+
+    SPI _spi;
+    DigitalOut _CS;
+    DigitalOut _DCS;
+    SDFileSystem _sd;
+
+};
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Mar 16 13:38:50 2016 +0000
@@ -0,0 +1,197 @@
+#include "mbed.h"
+#include "rtos.h"
+#include "uLCD_4DGL.h"
+#include "SDFileSystem.h"
+#include "wave_player.h"
+#include "VS1002.h" 
+#include <mpr121.h>
+
+//SDFileSystem sd(p5, p6, p7, p8, "sd");
+uLCD_4DGL uLCD(p28,p27,p30);
+Serial pc(USBTX, USBRX);
+VS1002 mp3(p5, p6, p7, p8,"sd",p11, p12 ,p13, p14, p23, p22, p21, p20); 
+LocalFileSystem local("local");
+//AnalogOut DACout(p18); // used to play sound on speaker
+//wave_player waver(&DACout);
+//This is for the touchpad
+I2C i2c(p9, p10);
+InterruptIn interrupt(p26);
+Mpr121 mpr121(&i2c, Mpr121::ADD_VSS);
+
+int start = 0;
+
+int new_song_number=1;  //Variable to store the Song Number
+int volume_set=-1;     //Variable to store the Volume
+int previous_volume;    //Variable to store the volume when muted
+bool pause=false;       //Variable to store the status of Pause button 
+bool mute=false;        //Variable to store the status of mute button
+
+int check=0;    //Capacitative touch generates interrupt on both press and release. This variable tracks this and updates only on press.
+char *song_name[6]={"18 till I Die","Summer of 69","Boulevard", "Serenity","Crawling","In the end"}; //Array of song names entered manually
+int chosennum=-1;
+int playing=0;
+int score=0;
+int fullscore;
+
+Mutex ulcd_mutex;
+Mutex sd_mutex;
+
+void fallInterrupt() {
+    int key_code=0;
+    int i=0;
+    int value=mpr121.read(0x00);
+    value +=mpr121.read(0x01)<<8;
+    // LED demo mod by J. Hamblen
+    //pc.printf("MPR value: %x \r\n", value);
+    i=0;
+    // puts key number out to LEDs for demo
+    for (i=0; i<12; i++) {
+        if (((value>>i)&0x01)==1) key_code=i+1;
+        }
+    check=1;
+    //pc.printf("%d  ",playing);
+    //if(!playing){
+    chosennum=key_code;
+    //}
+}
+
+class square {
+    public:
+    int startx,starty,side,pos;
+    
+
+    /*function*/
+    square(){};
+    square(int sx,int sy,int s,int p):startx(sx),starty(sy),side(s),pos(p){};
+    void set(int sx, int sy, int s,int p){startx = sx;starty = sy;side = s;pos = p;};
+    // draw the block on the LCD
+    void draw() {//draw a empty block on the LCD
+        uLCD.rectangle(startx,starty,startx+side,starty+side,0x00FF00);
+    }
+    void show() {//emerge the color inside the block
+        uLCD.filled_rectangle(startx+4, starty+4, startx+side-4, starty+side-4, 0x333300);
+        wait(0.1);
+        uLCD.filled_rectangle(startx+4, starty+4, startx+side-4, starty+side-4, 0x666600);
+        wait(0.1);
+        uLCD.filled_rectangle(startx+4, starty+4, startx+side-4, starty+side-4, 0x999900);
+        wait(0.1);
+        uLCD.filled_rectangle(startx+4, starty+4, startx+side-4, starty+side-4, 0xCCCC00);
+        wait(0.1);
+        uLCD.filled_rectangle(startx+4, starty+4, startx+side-4, starty+side-4, 0xFFFF00);
+        wait(0.1);
+        if(pos==chosennum){hit();score++;}
+        else{miss();}
+    
+    }
+    void hit()  {
+        uLCD.filled_rectangle(startx+4, starty+4, startx+side-4, starty+side-4, 0x00FF00);
+        wait(0.1);
+        uLCD.filled_rectangle(startx+4, starty+4, startx+side-4, starty+side-4, 0x000000);
+    }
+    void miss() {
+        uLCD.filled_rectangle(startx+4, starty+4, startx+side-4, starty+side-4, 0xFF0000);
+        wait(0.1);
+        uLCD.filled_rectangle(startx+4, starty+4, startx+side-4, starty+side-4, 0x000000);
+    }
+};
+
+void graph(void const *args)
+{   
+    while(!start){wait(0.5);}
+    pc.printf("i can start from now");
+    ulcd_mutex.lock();
+    square a[9];
+    a[0].set(1,1,40,1);
+    a[1].set(44,1,40,2);
+    a[2].set(87,1,40,3);
+    a[3].set(1,44,40,5);
+    a[4].set(44,44,40,6);
+    a[5].set(87,44,40,7);
+    a[6].set(1,87,40,9);
+    a[7].set(44,87,40,10);
+    a[8].set(87,87,40,11);
+    a[0].draw();a[1].draw();a[2].draw();
+    a[3].draw();a[4].draw();a[5].draw();
+    a[6].draw();a[7].draw();a[8].draw();
+    
+    FILE *fp = fopen("/local/2.txt", "r");
+        int screen=-1;
+        int waitmm=0;
+        int numnode=-1;
+        int counter = 0;
+        fscanf(fp,"%d",&numnode);
+        fullscore=numnode;
+        while(counter < numnode) {
+        fscanf(fp,"%d %d",&screen, &waitmm);
+        //uLCD.printf("%d %d\n", screen, waitmm);
+        a[screen].show();
+        wait(float(waitmm)/1000);
+        counter++;
+    }
+    ulcd_mutex.unlock();
+
+}
+
+int main() {
+    //Thread thread2(speaker);
+    interrupt.fall(&fallInterrupt);
+    interrupt.mode(PullUp);
+    
+    Thread thread2(graph);
+    
+    
+    uLCD.cls();
+    uLCD.media_init();
+    uLCD.set_sector_address(0x0000, 0x0099);
+    uLCD.display_video(0,0);
+    uLCD.cls();
+    
+    ulcd_mutex.lock();
+    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");
+    while(!check){wait(0.1);}
+    uLCD.printf("You chosen song: %d",chosennum);
+    wait(1);
+    uLCD.cls();
+    ulcd_mutex.unlock();
+    pc.printf("mutex unlocked!\n");
+    /*
+    square a[9];
+    a[0].set(1,1,40);
+    a[1].set(44,1,40);
+    a[2].set(87,1,40);
+    a[3].set(1,44,40);
+    a[4].set(44,44,40);
+    a[5].set(87,44,40);
+    a[6].set(1,87,40);
+    a[7].set(44,87,40);
+    a[8].set(87,87,40);
+    a[0].draw();a[1].draw();a[2].draw();
+    a[3].draw();a[4].draw();a[5].draw();
+    a[6].draw();a[7].draw();a[8].draw();
+    */
+    
+    mp3._RST = 1; 
+    mp3.cs_high();                                  //chip disabled 
+    mp3.sci_initialise();                           //initialise MBED 
+    mp3.sci_write(0x00,(SM_SDINEW+SM_STREAM+SM_DIFF)); 
+    mp3.sci_write(0x03, 0x9800); 
+    mp3.sdi_initialise();
+    
+    start=1; 
+    //while(1)
+    //{
+         //playing=1;
+         mp3.play_song(1);
+         //playing=0;
+    //}   
+    
+    ulcd_mutex.lock();
+    uLCD.cls();
+
+    uLCD.printf("congratulation!\n\nYour score is:\n\n%d \nout of %d",score,fullscore);
+    wait(3);
+    ulcd_mutex.unlock();
+    while(1){}
+    
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-rtos.lib	Wed Mar 16 13:38:50 2016 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/mbed_official/code/mbed-rtos/#02f5cf381388
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Mar 16 13:38:50 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/87f2f5183dfb
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mpr121.cpp	Wed Mar 16 13:38:50 2016 +0000
@@ -0,0 +1,221 @@
+/*
+Copyright (c) 2011 Anthony Buckton (abuckton [at] blackink [dot} net {dot} au)
+ 
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+ 
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+ 
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
+
+#include <mbed.h>
+#include <sstream>
+#include <string>
+#include <list>
+
+#include <mpr121.h>
+    
+Mpr121::Mpr121(I2C *i2c, Address i2cAddress)
+{
+    this->i2c = i2c;
+    
+    address = i2cAddress;
+           
+    // Configure the MPR121 settings to default
+    this->configureSettings();
+}
+
+   
+void Mpr121::configureSettings()
+{
+    // Put the MPR into setup mode
+    this->write(ELE_CFG,0x00);
+    
+    // Electrode filters for when data is > baseline
+    unsigned char gtBaseline[] = {
+         0x01,  //MHD_R
+         0x01,  //NHD_R 
+         0x00,  //NCL_R
+         0x00   //FDL_R
+         };
+         
+    writeMany(MHD_R,gtBaseline,4);   
+                 
+     // Electrode filters for when data is < baseline   
+     unsigned char ltBaseline[] = {
+        0x01,   //MHD_F
+        0x01,   //NHD_F
+        0xFF,   //NCL_F
+        0x02    //FDL_F
+        };
+        
+    writeMany(MHD_F,ltBaseline,4);
+        
+    // Electrode touch and release thresholds
+    unsigned char electrodeThresholds[] = {
+        E_THR_T, // Touch Threshhold
+        E_THR_R  // Release Threshold
+        };
+
+    for(int i=0; i<12; i++){
+        int result = writeMany((ELE0_T+(i*2)),electrodeThresholds,2);
+    }   
+
+    // Proximity Settings
+    unsigned char proximitySettings[] = {
+        0xff,   //MHD_Prox_R
+        0xff,   //NHD_Prox_R
+        0x00,   //NCL_Prox_R
+        0x00,   //FDL_Prox_R
+        0x01,   //MHD_Prox_F
+        0x01,   //NHD_Prox_F
+        0xFF,   //NCL_Prox_F
+        0xff,   //FDL_Prox_F
+        0x00,   //NHD_Prox_T
+        0x00,   //NCL_Prox_T
+        0x00    //NFD_Prox_T
+        };
+    writeMany(MHDPROXR,proximitySettings,11);
+
+    unsigned char proxThresh[] = {
+        PROX_THR_T, // Touch Threshold
+        PROX_THR_R  // Release Threshold
+        };
+    writeMany(EPROXTTH,proxThresh,2); 
+       
+    this->write(FIL_CFG,0x04);
+    
+    // Set the electrode config to transition to active mode
+    this->write(ELE_CFG,0x0c);
+}
+
+void Mpr121::setElectrodeThreshold(int electrode, unsigned char touch, unsigned char release){
+    
+    if(electrode > 11) return;
+    
+    // Get the current mode
+    unsigned char mode = this->read(ELE_CFG);
+    
+    // Put the MPR into setup mode
+    this->write(ELE_CFG,0x00);
+    
+    // Write the new threshold
+    this->write((ELE0_T+(electrode*2)), touch);
+    this->write((ELE0_T+(electrode*2)+1), release);
+    
+    //Restore the operating mode
+    this->write(ELE_CFG, mode);
+}
+    
+    
+unsigned char Mpr121::read(int key){
+
+    unsigned char data[2];
+    
+    //Start the command
+    i2c->start();
+
+    // Address the target (Write mode)
+    int ack1= i2c->write(address);
+
+    // Set the register key to read
+    int ack2 = i2c->write(key);
+
+    // Re-start for read of data
+    i2c->start();
+
+    // Re-send the target address in read mode
+    int ack3 = i2c->write(address+1);
+
+    // Read in the result
+    data[0] = i2c->read(0); 
+
+    // Reset the bus        
+    i2c->stop();
+
+    return data[0];
+}
+
+
+int Mpr121::write(int key, unsigned char value){
+    
+    //Start the command
+    i2c->start();
+
+    // Address the target (Write mode)
+    int ack1= i2c->write(address);
+
+    // Set the register key to write
+    int ack2 = i2c->write(key);
+
+    // Read in the result
+    int ack3 = i2c->write(value); 
+
+    // Reset the bus        
+    i2c->stop();
+    
+    return (ack1+ack2+ack3)-3;
+}
+
+
+int Mpr121::writeMany(int start, unsigned char* dataSet, int length){
+    //Start the command
+    i2c->start();
+
+    // Address the target (Write mode)
+    int ack= i2c->write(address);
+    if(ack!=1){
+        return -1;
+    }
+    
+    // Set the register key to write
+    ack = i2c->write(start);
+    if(ack!=1){
+        return -1;
+    }
+
+    // Write the date set
+    int count = 0;
+    while(ack==1 && (count < length)){
+        ack = i2c->write(dataSet[count]);
+        count++;
+    } 
+    // Stop the cmd
+    i2c->stop();
+    
+    return count;
+}
+      
+
+bool Mpr121::getProximityMode(){
+    if(this->read(ELE_CFG) > 0x0c)
+        return true;
+    else
+        return false;
+}
+
+void Mpr121::setProximityMode(bool mode){
+    this->write(ELE_CFG,0x00);
+    if(mode){
+        this->write(ELE_CFG,0x30); //Sense proximity from ALL pads
+    } else {
+        this->write(ELE_CFG,0x0c); //Sense touch, all 12 pads active.
+    }
+}
+
+
+int Mpr121::readTouchData(){
+    return this->read(0x00);
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mpr121.h	Wed Mar 16 13:38:50 2016 +0000
@@ -0,0 +1,157 @@
+/*
+Copyright (c) 2011 Anthony Buckton (abuckton [at] blackink [dot} net {dot} au)
+
+ 
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+ 
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+ 
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+
+   Parts written by Jim Lindblom of Sparkfun
+   Ported to mbed by A.Buckton, Feb 2011
+*/
+
+#ifndef MPR121_H
+#define MPR121_H
+
+//using namespace std;
+
+class Mpr121 
+{
+
+public:
+    // i2c Addresses, bit-shifted
+    enum Address { ADD_VSS = 0xb4,// ADD->VSS = 0x5a <-wiring on Sparkfun board
+                   ADD_VDD = 0xb6,// ADD->VDD = 0x5b
+                   ADD_SCL = 0xb8,// ADD->SDA = 0x5c
+                   ADD_SDA = 0xba // ADD->SCL = 0x5d
+                 };
+
+    // Real initialiser, takes the i2c address of the device.
+    Mpr121(I2C *i2c, Address i2cAddress);
+    
+    bool getProximityMode();
+    
+    void setProximityMode(bool mode);
+    
+    int readTouchData();
+               
+    unsigned char read(int key);
+    
+    int write(int address, unsigned char value);
+    int writeMany(int start, unsigned char* dataSet, int length);
+
+    void setElectrodeThreshold(int electrodeId, unsigned char touchThreshold, unsigned char releaseThreshold);
+        
+protected:
+    // Configures the MPR with standard settings. This is permitted to be overwritten by sub-classes.
+    void configureSettings();
+    
+private:
+    // The I2C bus instance.
+    I2C *i2c;
+
+    // i2c address of this mpr121
+    Address address;
+};
+
+
+// MPR121 Register Defines
+#define    MHD_R        0x2B
+#define    NHD_R        0x2C
+#define    NCL_R        0x2D
+#define    FDL_R        0x2E
+#define    MHD_F        0x2F
+#define    NHD_F        0x30
+#define    NCL_F        0x31
+#define    FDL_F        0x32
+#define    NHDT         0x33
+#define    NCLT         0x34
+#define    FDLT         0x35
+// Proximity sensing controls
+#define    MHDPROXR     0x36
+#define    NHDPROXR     0x37
+#define    NCLPROXR     0x38
+#define    FDLPROXR     0x39
+#define    MHDPROXF     0x3A
+#define    NHDPROXF     0x3B
+#define    NCLPROXF     0x3C
+#define    FDLPROXF     0x3D
+#define    NHDPROXT     0x3E
+#define    NCLPROXT     0x3F
+#define    FDLPROXT     0x40
+// Electrode Touch/Release thresholds
+#define    ELE0_T       0x41
+#define    ELE0_R       0x42
+#define    ELE1_T       0x43
+#define    ELE1_R       0x44
+#define    ELE2_T       0x45
+#define    ELE2_R       0x46
+#define    ELE3_T       0x47
+#define    ELE3_R       0x48
+#define    ELE4_T       0x49
+#define    ELE4_R       0x4A
+#define    ELE5_T       0x4B
+#define    ELE5_R       0x4C
+#define    ELE6_T       0x4D
+#define    ELE6_R       0x4E
+#define    ELE7_T       0x4F
+#define    ELE7_R       0x50
+#define    ELE8_T       0x51
+#define    ELE8_R       0x52
+#define    ELE9_T       0x53
+#define    ELE9_R       0x54
+#define    ELE10_T      0x55
+#define    ELE10_R      0x56
+#define    ELE11_T      0x57
+#define    ELE11_R      0x58
+// Proximity Touch/Release thresholds
+#define    EPROXTTH     0x59
+#define    EPROXRTH     0x5A
+// Debounce configuration
+#define    DEB_CFG      0x5B
+// AFE- Analogue Front End configuration
+#define    AFE_CFG      0x5C 
+// Filter configuration
+#define    FIL_CFG      0x5D
+// Electrode configuration - transistions to "active mode"
+#define    ELE_CFG      0x5E
+
+#define GPIO_CTRL0      0x73
+#define GPIO_CTRL1      0x74
+#define GPIO_DATA       0x75
+#define    GPIO_DIR     0x76
+#define    GPIO_EN      0x77
+#define    GPIO_SET     0x78
+#define GPIO_CLEAR      0x79
+#define GPIO_TOGGLE     0x7A
+// Auto configration registers
+#define    AUTO_CFG_0   0x7B
+#define    AUTO_CFG_U   0x7D
+#define    AUTO_CFG_L   0x7E
+#define    AUTO_CFG_T   0x7F
+
+// Threshold defaults
+// Electrode touch threshold
+#define    E_THR_T      0x0F   
+// Electrode release threshold 
+#define    E_THR_R      0x0A    
+// Prox touch threshold
+#define    PROX_THR_T   0x02
+// Prox release threshold
+#define    PROX_THR_R   0x02
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/wave_player.lib	Wed Mar 16 13:38:50 2016 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/sravet/code/wave_player/#acc3e18e77ad