Uses the APDS_9960 Digital Proximity, Ambient Light, RGB and Gesture Sensor library to play detected gesture sounds on a speaker from the SDcard

Dependencies:   mbed SDFileSystem wave_player

Committer:
kbhagat6
Date:
Wed Mar 11 14:56:59 2015 +0000
Revision:
11:ea43b0b83222
Parent:
10:e8adab2fb829
Child:
12:63c81930b5d9
speaker stuff added

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kbhagat6 0:437ae08befe3 1 #include "mbed.h"
kbhagat6 0:437ae08befe3 2 #include "glibr.h"
kbhagat6 11:ea43b0b83222 3 #include "SDFileSystem.h"
kbhagat6 11:ea43b0b83222 4 #include "wave_player.h"
kbhagat6 10:e8adab2fb829 5
kbhagat6 10:e8adab2fb829 6 glibr test(p9,p10);
kbhagat6 11:ea43b0b83222 7 SDFileSystem sd(p5, p6, p7, p8, "sd"); //SD card
kbhagat6 11:ea43b0b83222 8 AnalogOut DACout(p18);
kbhagat6 11:ea43b0b83222 9 wave_player waver(&DACout);
kbhagat6 10:e8adab2fb829 10 //SparkFun_APDS9960 apds = SparkFun_APDS9960();
kbhagat6 10:e8adab2fb829 11 int isr_flag = 0;
kbhagat6 10:e8adab2fb829 12 DigitalOut myled(LED1);
kbhagat6 10:e8adab2fb829 13 //InterruptIn interrupt(p11);
kbhagat6 0:437ae08befe3 14 Serial pc(USBTX, USBRX);
kbhagat6 10:e8adab2fb829 15 bool ret;
kbhagat6 10:e8adab2fb829 16 int val;
kbhagat6 0:437ae08befe3 17
kbhagat6 10:e8adab2fb829 18 int main()
kbhagat6 10:e8adab2fb829 19 {
kbhagat6 10:e8adab2fb829 20 myled = 0;
kbhagat6 10:e8adab2fb829 21 ret = 0;
kbhagat6 10:e8adab2fb829 22 val = 0;
kbhagat6 10:e8adab2fb829 23 if ( test.ginit() ) {
kbhagat6 10:e8adab2fb829 24 pc.printf("APDS-9960 initialization complete\n\r");
kbhagat6 10:e8adab2fb829 25 } else {
kbhagat6 10:e8adab2fb829 26 pc.printf("Something went wrong during APDS-9960 init\n\r");
kbhagat6 10:e8adab2fb829 27 }
kbhagat6 0:437ae08befe3 28
kbhagat6 10:e8adab2fb829 29 // Start running the APDS-9960 gesture sensor engine
kbhagat6 10:e8adab2fb829 30 if ( test.enableGestureSensor(true) ) {
kbhagat6 10:e8adab2fb829 31 pc.printf("Gesture sensor is now running\n\r");
kbhagat6 10:e8adab2fb829 32 } else {
kbhagat6 10:e8adab2fb829 33 pc.printf("Something went wrong during gesture sensor init!\n\r");
kbhagat6 10:e8adab2fb829 34 }
kbhagat6 0:437ae08befe3 35
kbhagat6 11:ea43b0b83222 36 FILE *Up;
kbhagat6 11:ea43b0b83222 37 FILE *Down;
kbhagat6 11:ea43b0b83222 38 FILE *Left;
kbhagat6 11:ea43b0b83222 39 FILE *Right;
kbhagat6 11:ea43b0b83222 40 FILE *Far;
kbhagat6 11:ea43b0b83222 41 FILE *Near;
kbhagat6 11:ea43b0b83222 42
kbhagat6 11:ea43b0b83222 43 Up=fopen("/sd/myMusic/up.wav","r");
kbhagat6 11:ea43b0b83222 44 Down=fopen("/sd/myMusic/down.wav","r");
kbhagat6 11:ea43b0b83222 45 Left=fopen("/sd/myMusic/left.wav","r");
kbhagat6 11:ea43b0b83222 46 Right=fopen("/sd/myMusic/right.wav","r");
kbhagat6 11:ea43b0b83222 47 Far=fopen("/sd/myMusic/far.wav","r");
kbhagat6 11:ea43b0b83222 48 Near=fopen("/sd/myMusic/near.wav","r");
kbhagat6 11:ea43b0b83222 49 // waver.play(wave_file);
kbhagat6 10:e8adab2fb829 50 while(1) {
kbhagat6 10:e8adab2fb829 51 /* ret = test.isGestureAvailable();
kbhagat6 10:e8adab2fb829 52 pc.printf("Is Gesture Available?: %d\n", ret);
kbhagat6 10:e8adab2fb829 53 myled = ret;
kbhagat6 10:e8adab2fb829 54 val = test.readGesture();
kbhagat6 10:e8adab2fb829 55 */
kbhagat6 10:e8adab2fb829 56 if ( test.isGestureAvailable() ) {
kbhagat6 10:e8adab2fb829 57 switch ( test.readGesture() ) {
kbhagat6 10:e8adab2fb829 58 case DIR_UP:
kbhagat6 10:e8adab2fb829 59 pc.printf("UP\n");
kbhagat6 11:ea43b0b83222 60 waver.play(Up);
kbhagat6 10:e8adab2fb829 61 break;
kbhagat6 10:e8adab2fb829 62 case DIR_DOWN:
kbhagat6 10:e8adab2fb829 63 pc.printf("DOWN\n");
kbhagat6 11:ea43b0b83222 64 waver.play(Down);
kbhagat6 10:e8adab2fb829 65 break;
kbhagat6 10:e8adab2fb829 66 case DIR_LEFT:
kbhagat6 10:e8adab2fb829 67 pc.printf("LEFT\n");
kbhagat6 11:ea43b0b83222 68 waver.play(Left);
kbhagat6 10:e8adab2fb829 69 break;
kbhagat6 10:e8adab2fb829 70 case DIR_RIGHT:
kbhagat6 10:e8adab2fb829 71 pc.printf("RIGHT\n");
kbhagat6 11:ea43b0b83222 72 waver.play(Right);
kbhagat6 10:e8adab2fb829 73 break;
kbhagat6 10:e8adab2fb829 74 case DIR_NEAR:
kbhagat6 10:e8adab2fb829 75 pc.printf("NEAR\n");
kbhagat6 11:ea43b0b83222 76 waver.play(Near);
kbhagat6 10:e8adab2fb829 77 break;
kbhagat6 10:e8adab2fb829 78 case DIR_FAR:
kbhagat6 10:e8adab2fb829 79 pc.printf("FAR\n");
kbhagat6 11:ea43b0b83222 80 waver.play(Far);
kbhagat6 10:e8adab2fb829 81 break;
kbhagat6 10:e8adab2fb829 82 default:
kbhagat6 10:e8adab2fb829 83 pc.printf("NONE\n");
kbhagat6 10:e8adab2fb829 84 }
kbhagat6 10:e8adab2fb829 85 }
kbhagat6 0:437ae08befe3 86
kbhagat6 11:ea43b0b83222 87
kbhagat6 11:ea43b0b83222 88 // wait(1);
kbhagat6 10:e8adab2fb829 89
kbhagat6 10:e8adab2fb829 90 }
kbhagat6 11:ea43b0b83222 91 fclose(Up);
kbhagat6 11:ea43b0b83222 92 fclose(Down);
kbhagat6 11:ea43b0b83222 93 fclose(Left);
kbhagat6 11:ea43b0b83222 94 fclose(Right);
kbhagat6 11:ea43b0b83222 95 fclose(Near);
kbhagat6 11:ea43b0b83222 96 fclose(Far);
kbhagat6 11:ea43b0b83222 97 fclose(Left);
kbhagat6 11:ea43b0b83222 98
kbhagat6 11:ea43b0b83222 99
kbhagat6 10:e8adab2fb829 100 }