Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: LSM9DS1_Library_cal RPCInterface final mbed
Fork of final_mbed by
Diff: main.cpp
- Revision:
- 1:f54bee9d59de
- Parent:
- 0:bdbd3d6fc5d5
- Child:
- 2:55495227fcca
--- a/main.cpp Fri Dec 07 11:25:01 2012 +0000
+++ b/main.cpp Fri Apr 28 19:18:46 2017 +0000
@@ -1,19 +1,348 @@
-#include "mbed.h"
-#include "SDFileSystem.h"
-
-SDFileSystem sd(p5, p6, p7, p8, "sd"); // the pinout on the mbed Cool Components workshop board
+/* Author: Pramod Nataraja & Vishnu Venkat */
-int main() {
- printf("Hello World!\n");
-
- mkdir("/sd/mydir", 0777);
+ #include "mbed.h"
+ #include "VS1002.h"
+ //#include "TextLCD.h"
+ #include "mpr121.h"
+ #include "LSM9DS1.h"
+ #include "SerialRPCInterface.h"
+ using namespace mbed;
+ #define NEXT 7
+ #define PREVIOUS 8
+ #define PP 9
+ #define V_DOWN 10
+ #define V_UP 11
+ #define MUTE_UNMUTE 12
+//Ticker flipper;
+//LSM9DS1 IMU(p28, p27, 0xD6, 0x3C);
+//SerialRPCInterface RPC(p28, p27);
+//void foo(Arguments* input, Reply* output);
+//RPCFunction bluetooth_control(&foo, "bluetooth_control");
+/*float tempx=0;
+float tempy=0;
+float tempz=0;
+float delx=0;
+float dely=0;
+float delz=0;
+float del=0;*/
+
+VS1002 mp3(p5, p6, p7, p8,"sd",p11, p12 ,p13, p14, p23, p22, p21, p15); //Setup Audio decoder. Name is VS1002 even though VS1053 is used.
+//TextLCD lcd1(p30, p29, p17, p18, p19, p20); //setup lcd
+//InterruptIn interrupt(p26); // Create the interrupt receiver object on pin 26
+//I2C i2c(p9, p10); // Setup the i2c bus on pins 9 and 10
+//Mpr121 mpr121(&i2c, Mpr121::ADD_VSS); //Setup Mpr121
+Serial pc1(USBTX, USBRX);
+
+/* Global Variables to store Status*/
+int new_song_number=1; //Variable to store the Song Number
+int volume_set=0; //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
+char *song_name[6]={"Escape","Summer of 69","Monster", "Leave out all the rest","Kings","Interstellar Docking"}; //Array of song names entered manually
+
+
+/*void fallInterrupt()
+{
+ int key_code=0;
+ int i=0;
+ int value;
+ value=mpr121.read(0x00);
+ value +=mpr121.read(0x01)<<8;
+
+ i=0;
+ if(check)
+ check=0;
+ else
+ check=1;
+ if(check)
+ {
+ for (i=0; i<12; i++) {
+ if (((value>>i)&0x01)==1) key_code=i+1; //Convert value into decimal
+ }
+
+ switch(key_code) // Different cases depending on key press
+ {
+ case 0:break; // Invalid entry . Valid 1-12
+ case 1:
+ case 2:
+ case 3:
+ case 4:
+ case 5:
+ case 6: new_song_number=key_code; // Play the selected song
+ break;
+ case NEXT:new_song_number+=1; // Next song
+ if(new_song_number==7)
+ new_song_number=1;
+ break;
+ case PREVIOUS: new_song_number-=1; // Previous Song
+ if(new_song_number==0)
+ new_song_number=6;
+ break;
+ case PP: pause=!pause; // Pause/Play button
+ break;
+ case V_UP: volume_set+=3; // Volume Up
+ if(volume_set>=0)
+ volume_set=0;
+ break;
+ case V_DOWN: volume_set-=3; //Volume Down
+ if(volume_set<-55)
+ volume_set=-55;
+ break;
+ case MUTE_UNMUTE: mute=!mute; //Mute/Unmute
+ if(mute)
+ {
+ previous_volume=volume_set; // Attenuation of -55 db is small enough to not hear anything
+ volume_set=-55;
+ }
+ else
+ {
+ volume_set=previous_volume;
+ }
+ break;
+ default: ;//pc.cls();
+ pc1.printf("error"); // exit on error
+ exit(1);
+ }
+ }
+
+ if(pause)
+ pc1.printf("Paused ");
+ if(mute)
+ pc1.printf("Muted");
+ if(!mute && !pause)
+ pc1.printf("Playing");
+ pc1.printf("\r\n %d %s",new_song_number,song_name[new_song_number-1]);
+
+ }*/
+/*void IMUInterrupt()
+{
+ int key_code=0;
+
- FILE *fp = fopen("/sd/mydir/sdtest.txt", "w");
- if(fp == NULL) {
- error("Could not open file for write\n");
+ while(!IMU.accelAvailable());
+ tempx=IMU.calcAccel(IMU.ax);
+ tempy=IMU.calcAccel(IMU.ay);
+ tempz=IMU.calcAccel(IMU.az);
+ IMU.readAccel();
+ delx=tempx-IMU.calcAccel(IMU.ax);
+ dely=tempy-IMU.calcAccel(IMU.ay);
+ delz=tempz-IMU.calcAccel(IMU.az);
+ //del=delx*delx+dely*dely+delz*delz;
+ if(delx>0.15)
+ key_code=NEXT;
+ if(delx<-0.15)
+ key_code=PREVIOUS;
+ if(dely>0.15)
+ key_code=V_UP;
+ if(dely<-0.15)
+ key_code=V_DOWN;
+ if(delz>0.15)
+ key_code=PP;
+ if(delz<-0.15)
+ key_code=MUTE_UNMUTE;
+ //pc1.printf("delx:%f dely:%f delz:%f\r\n",delx,dely,delz);
+ //pc1.printf("key_code:%d\r\n",key_code);
+
+
+
+
+ switch(key_code) // Different cases depending on key press
+ {
+ case 0:break; // Invalid entry . Valid 1-12
+ case 1:
+ case 2:
+ case 3:
+ case 4:
+ case 5:
+ case 6: new_song_number=key_code; // Play the selected song
+ break;
+ case NEXT:
+ pc1.printf("next\r\n");
+ new_song_number+=1; // Next song
+ if(new_song_number==7)
+ new_song_number=1;
+ break;
+ case PREVIOUS:
+ pc1.printf("previous\r\n");
+ new_song_number-=1; // Previous Song
+ if(new_song_number==0)
+ new_song_number=6;
+ break;
+ case PP:
+ pc1.printf("pp\r\n");
+ pause=!pause; // Pause/Play button
+ break;
+ case V_UP:
+ pc1.printf("v_up\r\n");
+ volume_set+=3; // Volume Up
+ if(volume_set>=0)
+ volume_set=0;
+ break;
+ case V_DOWN:
+ pc1.printf("v_down\r\n");
+ volume_set-=3; //Volume Down
+ if(volume_set<-55)
+ volume_set=-55;
+ break;
+ case MUTE_UNMUTE:
+ pc1.printf("mute_unmute\r\n");
+ mute=!mute; //Mute/Unmute
+ if(mute)
+ {
+ previous_volume=volume_set; // Attenuation of -55 db is small enough to not hear anything
+ volume_set=-55;
+ }
+ else
+ {
+ volume_set=previous_volume;
+ }
+ break;
+ default: ;//pc.cls();
+ pc1.printf("error"); // exit on error
+ exit(1);
+ }
+
+
+ if(pause)
+ pc1.printf("Paused ");
+ if(mute)
+ pc1.printf("Muted");
+ if(!mute && !pause)
+ pc1.printf("Playing");
+ pc1.printf("\r\n %d %s",new_song_number,song_name[new_song_number-1]);
+
+ }*/
+ //void foo(Arguments * input, Reply * output){
+ void foo(){
+ //const char *arg0=input->getArg<const char*>();
+ pc1.printf("hi\n");
+ if(pc1.readable()){
+ const char arg0=pc1.getc();
+ //pc1.printf(arg0);
+ int key_code=0;
+ //switch(*arg0){
+ switch(arg0){
+ case '1': key_code=V_UP; break;
+ case '2': key_code=V_DOWN; break;
+ case '3': key_code=PP; break;
+ case '4': key_code=MUTE_UNMUTE; break;
+ case 'N': key_code=NEXT; break;
+ case 'B': key_code=PREVIOUS; break;
+ case 'a':
+ case 'b':
+ case 'c':
+ case 'd':
+ case 'e':
+ case 'f': key_code=arg0-'0'; // Play the selected song
+ break;
+ default : key_code=0; break;
}
- fprintf(fp, "Hello fun SD Card World!");
- fclose(fp);
+
+
+ switch(key_code) // Different cases depending on key press
+ {
+ case 0:break; // Invalid entry . Valid 1-12
+ case 1:
+ case 2:
+ case 3:
+ case 4:
+ case 5:
+ case 6: new_song_number=key_code; // Play the selected song
+ break;
+ case NEXT:
+ pc1.printf("next\r\n");
+ new_song_number+=1; // Next song
+ if(new_song_number==7)
+ new_song_number=1;
+ break;
+ case PREVIOUS:
+ pc1.printf("previous\r\n");
+ new_song_number-=1; // Previous Song
+ if(new_song_number==0)
+ new_song_number=6;
+ break;
+ case PP:
+ pc1.printf("pp\r\n");
+ pause=!pause; // Pause/Play button
+ break;
+ case V_UP:
+ pc1.printf("v_up\r\n");
+ volume_set+=3; // Volume Up
+ if(volume_set>=0)
+ volume_set=0;
+ break;
+ case V_DOWN:
+ pc1.printf("v_down\r\n");
+ volume_set-=3; //Volume Down
+ if(volume_set<-55)
+ volume_set=-55;
+ break;
+ case MUTE_UNMUTE:
+ pc1.printf("mute_unmute\r\n");
+ mute=!mute; //Mute/Unmute
+ if(mute)
+ {
+ previous_volume=volume_set; // Attenuation of -55 db is small enough to not hear anything
+ volume_set=-55;
+ }
+ else
+ {
+ volume_set=previous_volume;
+ }
+ break;
+ default: ;//pc.cls();
+ pc1.printf("error"); // exit on error
+ exit(1);
+ }
- printf("Goodbye World!\n");
+ /* Print to LCD the status of Song */
+ //pc.cls();
+ if(pause)
+ pc1.printf("Paused ");
+ if(mute)
+ pc1.printf("Muted");
+ if(!mute && !pause)
+ pc1.printf("Playing");
+ pc1.printf("\r\n %d %s",new_song_number,song_name[new_song_number-1]);
+ }
}
+ int main ()
+ {
+ pc1.printf("hello\r\n");
+ /*IMU.begin();
+ if (!IMU.begin()) {
+ pc1.printf("Failed to communicate with LSM9DS1.\r\n");
+ }
+ IMU.calibrate(1);*/
+ /*============================================================
+ * MP3 Initialising
+ *==========================================================*/
+
+
+ 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();
+
+
+ /* Touch Pad setup */
+ //interrupt.fall(&fallInterrupt);
+ //interrupt.mode(PullUp);
+ //interrupt.fall(&IMUInterrupt);
+ //interrupt.mode(PullUp);
+ // flipper.attach(&IMUInterrupt, 1);
+ pc1.attach(&foo, Serial::RxIrq);
+ while(1)
+ {
+ mp3.play_song(new_song_number);
+ }
+
+ }
+
+
