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@14:5e5994418e97, 2015-03-11 (annotated)
- Committer:
- kbhagat6
- Date:
- Wed Mar 11 16:17:28 2015 +0000
- Revision:
- 14:5e5994418e97
- Parent:
- 12:63c81930b5d9
- Child:
- 16:cd5666b8fa12
updated
Who changed what in which revision?
User | Revision | Line number | New 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 | 11:ea43b0b83222 | 42 | // waver.play(wave_file); |
kbhagat6 | 10:e8adab2fb829 | 43 | while(1) { |
kbhagat6 | 12:63c81930b5d9 | 44 | /* ret = GSensor.isGestureAvailable(); |
kbhagat6 | 10:e8adab2fb829 | 45 | pc.printf("Is Gesture Available?: %d\n", ret); |
kbhagat6 | 10:e8adab2fb829 | 46 | myled = ret; |
kbhagat6 | 12:63c81930b5d9 | 47 | val = GSensor.readGesture(); |
kbhagat6 | 10:e8adab2fb829 | 48 | */ |
kbhagat6 | 12:63c81930b5d9 | 49 | if ( GSensor.isGestureAvailable() ) { |
kbhagat6 | 12:63c81930b5d9 | 50 | switch ( GSensor.readGesture() ) { |
kbhagat6 | 10:e8adab2fb829 | 51 | case DIR_UP: |
kbhagat6 | 10:e8adab2fb829 | 52 | pc.printf("UP\n"); |
kbhagat6 | 14:5e5994418e97 | 53 | Up=fopen("/sd/up.wav","r"); |
kbhagat6 | 11:ea43b0b83222 | 54 | waver.play(Up); |
kbhagat6 | 10:e8adab2fb829 | 55 | break; |
kbhagat6 | 10:e8adab2fb829 | 56 | case DIR_DOWN: |
kbhagat6 | 10:e8adab2fb829 | 57 | pc.printf("DOWN\n"); |
kbhagat6 | 14:5e5994418e97 | 58 | Down=fopen("/sd/down.wav","r"); |
kbhagat6 | 11:ea43b0b83222 | 59 | waver.play(Down); |
kbhagat6 | 10:e8adab2fb829 | 60 | break; |
kbhagat6 | 10:e8adab2fb829 | 61 | case DIR_LEFT: |
kbhagat6 | 10:e8adab2fb829 | 62 | pc.printf("LEFT\n"); |
kbhagat6 | 14:5e5994418e97 | 63 | Left=fopen("/sd/left.wav","r"); |
kbhagat6 | 11:ea43b0b83222 | 64 | waver.play(Left); |
kbhagat6 | 10:e8adab2fb829 | 65 | break; |
kbhagat6 | 10:e8adab2fb829 | 66 | case DIR_RIGHT: |
kbhagat6 | 10:e8adab2fb829 | 67 | pc.printf("RIGHT\n"); |
kbhagat6 | 14:5e5994418e97 | 68 | Right=fopen("/sd/right.wav","r"); |
kbhagat6 | 11:ea43b0b83222 | 69 | waver.play(Right); |
kbhagat6 | 10:e8adab2fb829 | 70 | break; |
kbhagat6 | 10:e8adab2fb829 | 71 | case DIR_NEAR: |
kbhagat6 | 10:e8adab2fb829 | 72 | pc.printf("NEAR\n"); |
kbhagat6 | 14:5e5994418e97 | 73 | Far=fopen("/sd/far.wav","r"); |
kbhagat6 | 11:ea43b0b83222 | 74 | waver.play(Near); |
kbhagat6 | 10:e8adab2fb829 | 75 | break; |
kbhagat6 | 10:e8adab2fb829 | 76 | case DIR_FAR: |
kbhagat6 | 10:e8adab2fb829 | 77 | pc.printf("FAR\n"); |
kbhagat6 | 14:5e5994418e97 | 78 | Near=fopen("/sd/near.wav","r"); |
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 | } |