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 15:49:34 2015 +0000
Revision:
12:63c81930b5d9
Parent:
11:ea43b0b83222
Child:
14:5e5994418e97
updatedspeaker

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