Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: SFE_APDS9960 mbed
main.cpp
00001 #include <mbed.h> 00002 #include "SparkFun_APDS9960.h" 00003 #include "led.h" 00004 00005 //Serial pc(P0_23,P0_25); // TX Pin, RX Pin 00006 Serial pc(P0_23,P0_8); 00007 I2C i2c(P0_14, P0_13); 00008 SparkFun_APDS9960 apds(i2c); 00009 InterruptIn SparkFun_Int(P0_16); 00010 PwmOut Fan1(P0_9); 00011 PwmOut Fan2(P0_25); 00012 00013 //Red_Left: P0.8 Blue_Right:P0.11 Green_Down:P0.15 00014 00015 DigitalOut LED_Down(P0_15); 00016 00017 int isr_flag = 0; 00018 00019 void handleGesture(); 00020 00021 00022 void SparkFun_Interrupt(){ 00023 isr_flag = 1; 00024 } 00025 00026 int main() 00027 { 00028 pc.baud(9600); 00029 pc.printf("Hello world!\n"); 00030 Fan1 = 0;Fan2 = 0; 00031 LED_Down = 1; 00032 wait_ms(500); wait_ms(500); wait_ms(500); wait_ms(500); 00033 LED_Down = 0; 00034 SparkFun_Int.fall(&SparkFun_Interrupt); 00035 00036 00037 if(apds.init(100000)) 00038 pc.printf("APDS-9960 initialization complete\n"); 00039 else 00040 pc.printf("Something went wrong during APDS-9960 init!\n"); 00041 00042 if (apds.enableGestureSensor(true) ) 00043 printf("Gesture sensor is now running\n"); 00044 else 00045 printf("Something went wrong during gesture sensor init!\n"); 00046 00047 Fan1.period(1/40); 00048 Fan2.period(1/40); 00049 Fan1 = 1; Fan2 = 1; 00050 00051 while(1) 00052 { 00053 if(isr_flag == 1) 00054 { 00055 handleGesture(); 00056 isr_flag = 0; 00057 } 00058 } 00059 } 00060 00061 void handleGesture() { 00062 if ( apds.isGestureAvailable() ) { 00063 switch ( apds.readGesture() ) { 00064 case DIR_UP: 00065 00066 pc.printf("Left\n"); 00067 if(Fan1.read() != 0.95) 00068 Fan1 = 0.95; 00069 if(Fan2.read() != 1) 00070 Fan2 = 1; 00071 break; 00072 00073 case DIR_DOWN: 00074 00075 pc.printf("Right\n"); 00076 if(Fan1.read()!= 1) 00077 Fan1 = 1; 00078 if(Fan2.read()!= 0.95) 00079 Fan2 = 0.95; 00080 00081 break; 00082 case DIR_LEFT: 00083 LED_Down = 0; 00084 pc.printf("Down\n"); 00085 break; 00086 case DIR_RIGHT: 00087 pc.printf("Up\n"); 00088 LED_Down = 1; 00089 break; 00090 case DIR_NEAR: 00091 pc.printf("NEAR\n"); 00092 break; 00093 case DIR_FAR: 00094 pc.printf("FAR\n"); 00095 break; 00096 default: 00097 pc.printf("NONE\n"); 00098 } 00099 } 00100 }
Generated on Fri Jul 15 2022 15:25:13 by
1.7.2