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

main.cpp

Committer:
kbhagat6
Date:
2015-03-11
Revision:
12:63c81930b5d9
Parent:
11:ea43b0b83222
Child:
14:5e5994418e97

File content as of revision 12:63c81930b5d9:

#include "mbed.h"
#include "glibr.h"
#include "SDFileSystem.h"
#include "wave_player.h"

glibr GSensor(p9,p10);
SDFileSystem sd(p5, p6, p7, p8, "sd"); //SD card
AnalogOut DACout(p18);
wave_player waver(&DACout);
int isr_flag = 0;
DigitalOut myled(LED1);
//InterruptIn interrupt(p11);
Serial pc(USBTX, USBRX);
bool ret;
int val;

int main()
{
    myled = 0;
    ret = 0;
    val = 0;
    if ( GSensor.ginit() ) {
        pc.printf("APDS-9960 initialization complete\n\r");
    } else {
        pc.printf("Something went wrong during APDS-9960 init\n\r");
    }

    // Start running the APDS-9960 gesture sensor engine
    if ( GSensor.enableGestureSensor(true) ) {
        pc.printf("Gesture sensor is now running\n\r");
    } else {
        pc.printf("Something went wrong during gesture sensor init!\n\r");
    }

    FILE *Up;
    FILE *Down;
    FILE *Left;
    FILE *Right;
    FILE *Far;
    FILE *Near;

    Up=fopen("/sd/up.wav","r");
    Down=fopen("/sd/down.wav","r");
    Left=fopen("/sd/left.wav","r");
    Right=fopen("/sd/right.wav","r");
    Far=fopen("/sd/far.wav","r");
    Near=fopen("/sd/near.wav","r");
    //   waver.play(wave_file);
    while(1) {
        /* ret = GSensor.isGestureAvailable();
         pc.printf("Is Gesture Available?: %d\n", ret);
         myled = ret;
         val = GSensor.readGesture();
         */
        if ( GSensor.isGestureAvailable() ) {
            switch ( GSensor.readGesture() ) {
                case DIR_UP:
                    pc.printf("UP\n");
                    waver.play(Up);
                    break;
                case DIR_DOWN:
                    pc.printf("DOWN\n");
                    waver.play(Down);
                    break;
                case DIR_LEFT:
                    pc.printf("LEFT\n");
                    waver.play(Left);
                    break;
                case DIR_RIGHT:
                    pc.printf("RIGHT\n");
                    waver.play(Right);
                    break;
                case DIR_NEAR:
                    pc.printf("NEAR\n");
                    waver.play(Near);
                    break;
                case DIR_FAR:
                    pc.printf("FAR\n");
                    waver.play(Far);
                    break;
                default:
                    pc.printf("NONE\n");
            }
        }


        //   wait(1);

    }
    fclose(Up);
    fclose(Down);
    fclose(Left);
    fclose(Right);
    fclose(Near);
    fclose(Far);
    fclose(Left);


}