True leaf photo frame,gesture sensing APDS9960,motor fan,color LED

Dependencies:   SFE_APDS9960 mbed

main.cpp

Committer:
yzh344612058
Date:
2016-04-19
Revision:
1:d16891627cd3
Parent:
0:9b48e23879b3
Child:
2:6b5764a79ccf

File content as of revision 1:d16891627cd3:

#include <mbed.h>
#include "SparkFun_APDS9960.h"
#include "led.h"

Serial pc(P0_23,P0_25);   // TX Pin, RX Pin
I2C i2c(P0_8, P0_9); 
SparkFun_APDS9960 apds(i2c);
DigitalIn interrupt(P0_10);

 void handleGesture();

 int main()
 {
     pc.printf("Hello world!\n"); 
     
     if(apds.init(400000))
        pc.printf("APDS-9960 initialization complete\n");
     else
        pc.printf("Something went wrong during APDS-9960 init!\n");
        
     if (apds.enableGestureSensor(true) ) 
        printf("Gesture sensor is now running\n");
     else 
        printf("Something went wrong during gesture sensor init!\n");
        
        
     while(1)
     {
         Led_Blink();  
         if(!interrupt) 
         {
            wait_ms(10);
            if(!interrupt) 
                handleGesture();
         }  
    }
 }
 
 void handleGesture() {
    if ( apds.isGestureAvailable() ) {
    switch ( apds.readGesture() ) {
      case DIR_UP:
        pc.printf("UP\n");
        break;
      case DIR_DOWN:
        pc.printf("DOWN\n");
        break;
      case DIR_LEFT:
        pc.printf("LEFT\n");
        break;
      case DIR_RIGHT:
        pc.printf("RIGHT\n");
        break;
      case DIR_NEAR:
        pc.printf("NEAR\n");
        break;
      case DIR_FAR:
        pc.printf("FAR\n");
        break;
      default:
        pc.printf("NONE\n");
    }
  }
}