SKU:RB-02S102 Gesture Sensor
来自ALSROBOT WiKi
目录 |
产品概述
Gesture Sensor模块是基于APDS-9960传感器的一款能够识别手势移动方向(上下左右)的传感器模块。APDS-9960芯片集成了RGB、环境光、接近和手势检测功能。模块使用I2C接口,使用相应arduino库函数即可对编程控制,传感器返回的信号可用于作为机器人接收的控制信号,从而实现对机器人的控制。内置的识别算法相当智能,能够把双手从生硬的按键中解放出来。
产品参数
- 输入电压:3.3V - 5V
- 引脚接口:IIC接口* 1、中断引脚 * 1
- 接口类型:直插、KF2510
- 输出信号:数字
- 产品尺寸:30 mm * 25 mm
- 定位孔:4 * M3,间距 23mm x 18mm
- 检测距离:10 cm
- 重量大小:3g
使用方法
1、测试环境
- 硬件环境:Starduino UNO R3 、传感器V5.0扩展板、红外手势传感器、8*8点阵
- 软件环境:Arduino IDE 1.7.7
2、引脚定义
- -:电源地
- +:电源正极
- SDA:数据引脚
- SCL:时引脚
3、硬件连接
4、例子程序
#include <Wire.h> #include <ALSROBOT_APDS9960.h> // Pins #define APDS9960_INT 2 // Needs to be an interrupt pin const int DINPin = 4; //数据引脚 连接到数字P4口 const int CLKPin = 5; //时钟引脚 连接到数字P5口 const int LTHPin = 6; //锁存引脚 连接到数字P6口 byte LieScan[16] = { //列扫描,点阵只点亮一列 0xFE,0xFD,0xFB,0xF7,0xEF,0xDF,0xBF,0x7F }; byte HanZi_1[] = { 0x1c,0x7c,0x7e,0x3f,0x3f,0x7e,0x7c,0x1c //显示心形图案 }; char Left[]={0x00,0x18,0x3c,0x7e,0x18,0x18,0x18,0x00}; char Down[]={0x00,0x10,0x30,0x7e,0x7e,0x30,0x10,0x00}; char Up[]={0x00,0x08,0x0c,0x7e,0x7e,0x0c,0x08,0x00}; char Right[]={0x00,0x18,0x18,0x18,0x7e,0x3c,0x18,0x00}; char Far[]={0xff,0xff,0xc3,0xc3,0xc3,0xc3,0xff,0xff}; char Near[]={0x00,0x00,0x3c,0x3c,0x3c,0x3c,0x00,0x00}; char Moren[]={0x18,0x3c,0x5a,0xff,0xff,0x5a,0x3c,0x18}; ALSROBOT_APDS9960 apds = ALSROBOT_APDS9960(); int isr_flag = 0; int temp=0; void setup() { // Set interrupt pin as input pinMode(APDS9960_INT, INPUT); pinMode(DINPin,OUTPUT); //设置数据引脚为输出 pinMode(CLKPin,OUTPUT); //设置锁存引脚为输出 pinMode(LTHPin,OUTPUT); //设置时钟引脚为输出 // Initialize Serial port Serial.begin(9600); Serial.println(); Serial.println(F("--------------------------------")); Serial.println(F("ALSROBOT 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 left(){ for(unsigned char times_1 = 0;times_1 <250;times_1++) { //持续刷新250次 for(char x = 0;x <8;x++) { shiftOut(DINPin, CLKPin, MSBFIRST, LieScan[x]); //先选择列 shiftOut(DINPin, CLKPin, MSBFIRST, Left[x]); //再送行数据 digitalWrite(LTHPin, LOW); //刷新显示 digitalWrite(LTHPin, HIGH); } } } void down() { for(unsigned char times_1 = 0;times_1 <250;times_1++) { //持续刷新250次 for(char x = 0;x <8;x++) { shiftOut(DINPin, CLKPin, MSBFIRST, LieScan[x]); //先选择列 shiftOut(DINPin, CLKPin, MSBFIRST, Down[x]); //再送行数据 digitalWrite(LTHPin, LOW); //刷新显示 digitalWrite(LTHPin, HIGH); } } } void up() { for(unsigned char times_1 = 0;times_1 <250;times_1++) { //持续刷新250次 for(char x = 0;x <8;x++) { shiftOut(DINPin, CLKPin, MSBFIRST, LieScan[x]); //先选择列 shiftOut(DINPin, CLKPin, MSBFIRST, Up[x]); //再送行数据 digitalWrite(LTHPin, LOW); //刷新显示 digitalWrite(LTHPin, HIGH); } } } void right() { for(unsigned char times_1 = 0;times_1 <250;times_1++) { //持续刷新250次 for(char x = 0;x <8;x++) { shiftOut(DINPin, CLKPin, MSBFIRST, LieScan[x]); //先选择列 shiftOut(DINPin, CLKPin, MSBFIRST, Right[x]); //再送行数据 digitalWrite(LTHPin, LOW); //刷新显示 digitalWrite(LTHPin, HIGH); } } } void far() { for(unsigned char times_1 = 0;times_1 <250;times_1++) { //持续刷新250次 for(char x = 0;x <8;x++) { shiftOut(DINPin, CLKPin, MSBFIRST, LieScan[x]); //先选择列 shiftOut(DINPin, CLKPin, MSBFIRST, Far[x]); //再送行数据 digitalWrite(LTHPin, LOW); //刷新显示 digitalWrite(LTHPin, HIGH); } } } void near() { for(unsigned char times_1 = 0;times_1 <250;times_1++) { //持续刷新250次 for(char x = 0;x <8;x++) { shiftOut(DINPin, CLKPin, MSBFIRST, LieScan[x]); //先选择列 shiftOut(DINPin, CLKPin, MSBFIRST, Near[x]); //再送行数据 digitalWrite(LTHPin, LOW); //刷新显示 digitalWrite(LTHPin, HIGH); } } } void moren() { for(unsigned char times_1 = 0;times_1 <250;times_1++) { //持续刷新250次 for(char x = 0;x <8;x++) { shiftOut(DINPin, CLKPin, MSBFIRST, LieScan[x]); //先选择列 shiftOut(DINPin, CLKPin, MSBFIRST, 0x00); //再送行数据 digitalWrite(LTHPin, LOW); //刷新显示 digitalWrite(LTHPin, HIGH); } } } void loop() { switch(temp) { case 1:up();break; case 2:down();break; case 3:left();break; case 4:right();break; case 5:near();break; case 6:far();break; default :moren();break; } handleGesture(); } void interruptRoutine() { isr_flag = 1; } void handleGesture() { if ( apds.isGestureAvailable() ) { switch ( apds.readGesture() ) { case DIR_UP: temp=1; Serial.println("UP"); break; case DIR_DOWN: temp=2; Serial.println("DOWN"); break; case DIR_LEFT: temp=3; Serial.println("LEFT"); break; case DIR_RIGHT: temp=4; Serial.println("RIGHT"); break; case DIR_NEAR: temp=5; Serial.println("NEAR"); break; case DIR_FAR: temp=6; Serial.println("FAR"); break; default:temp=7; Serial.println("NONE"); } } }
5、程序效果 如图所示,当手滑动时,点阵显示相应的滑动方向