
| Sensor Pin | UNO Pin |
| VCC | 5V |
| GND | GND |
| SCL | SCL |
| SDA | SDA |
| INT | 2 |
라이브러리 다운로드: Click to download library files
Next, we need to open the ARDUINO IDE, and copy the following simple code to the IDE window. Then select the right serial port and board (Arduino UNO). Wave your hand in front of the sensor, see what happen on the serial port.
#include
#include
// Pins
#define APDS9960_INT 2 // Needs to be an interrupt pin
APDS9960 apds = APDS9960();
int isr_flag = 0;
void setup() {
// Initialize Serial port
Serial.begin(9600);
Serial.println();
Serial.println(F("--------------------------------"));
Serial.println(F("APDS-9960 - GestureTest"));
Serial.println(F("--------------------------------"));
// Initialize interrupt service routine
attachInterrupt(0, interruptRoutine, FALLING);
// Initialize APDS-9960 (configure I2C and initial values)
if ( apds.init() ) {
Serial.println(F("APDS-9960 initialization complete"));
} else {
Serial.println(F("Something went wrong during APDS-9960 init!"));
}
// Start running the APDS-9960 gesture sensor engine
if ( apds.enableGestureSensor(true) ) {
Serial.println(F("Gesture sensor is now running"));
} else {
Serial.println(F("Something went wrong during gesture sensor init!"));
}
}
void loop() {
if( isr_flag == 1 ) {
handleGesture();
if(digitalRead(APDS9960_INT) == 0){
apds.init();
apds.enableGestureSensor(true);
}
isr_flag = 0;
}
}
void interruptRoutine() {
isr_flag = 1;
}
void handleGesture() {
if ( apds.isGestureAvailable() ) {
switch ( apds.readGesture() ) {
case DIR_UP:
Serial.println("UP");
break;
case DIR_DOWN:
Serial.println("DOWN");
break;
case DIR_LEFT:
Serial.println("LEFT");
break;
case DIR_RIGHT:
Serial.println("RIGHT");
break;
case DIR_NEAR:
Serial.println("NEAR");
break;
case DIR_FAR:
Serial.println("FAR");
break;
default:
Serial.println("NONE");
}
}
}
상품이 장바구니에 담겼습니다.
바로 확인하시겠습니까?
상품이 찜 리스트에 담겼습니다.
바로 확인하시겠습니까?
Copyright © Mechasolution. All rights reserved.









