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

Dependencies:   SFE_APDS9960 mbed

main.cpp

Committer:
yzh344612058
Date:
2016-04-20
Revision:
3:d046bb79dbbe
Parent:
2:6b5764a79ccf
Child:
4:6dfbdf48fd16

File content as of revision 3:d046bb79dbbe:

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

Serial pc(P0_23,P0_25);   // TX Pin, RX Pin
I2C i2c(P0_14, P0_13); 
SparkFun_APDS9960 apds(i2c);
InterruptIn SparkFun_Int(P0_16);

int isr_flag = 0;

void handleGesture();
 

void SparkFun_Interrupt(){
  isr_flag = 1;   
}

 int main()
 {
     pc.printf("Hello world!\n"); 
     
     SparkFun_Int.fall(&SparkFun_Interrupt);
        
     
     if(apds.init(100000))
        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)
     {
        if(isr_flag == 1)
        {
            handleGesture();
            isr_flag = 0;
        } 
    }
 }
 
 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");
    }
  }
}