“SKU:RB-02S102 Gesture Sensor”的版本間的差異
來自ALSROBOT WiKi
(→?例子程序下載) |
|||
第11行: | 第11行: | ||
# 檢測距離:10 cm | # 檢測距離:10 cm | ||
# 重量大?。?g | # 重量大?。?g | ||
? | |||
* 產(chǎn)品尺寸圖: | * 產(chǎn)品尺寸圖: | ||
[[文件:size041.jpg|500px|縮略圖|居中]] | [[文件:size041.jpg|500px|縮略圖|居中]] |
2018年1月25日 (四) 17:31的版本
目錄 |
產(chǎn)品概述
Gesture Sensor模塊是基于APDS-9960傳感器的一款能夠識別手勢移動方向(上下左右)的傳感器模塊。APDS-9960芯片集成了RGB、環(huán)境光、接近和手勢檢測功能。模塊使用I2C接口,使用相應(yīng)arduino庫函數(shù)即可對編程控制,傳感器返回的信號可用于作為機器人接收的控制信號,從而實現(xiàn)對機器人的控制。內(nèi)置的識別算法相當智能,能夠把雙手從生硬的按鍵中解放出來。
產(chǎn)品參數(shù)
- 輸入電壓:3.3V - 5V
- 引腳接口:IIC接口* 1、中斷引腳 * 1
- 接口類型:直插、KF2510
- 輸出信號:數(shù)字
- 產(chǎn)品尺寸:30 mm * 25 mm
- 定位孔:4 * M3,間距 23mm x 18mm
- 檢測距離:10 cm
- 重量大?。?g
- 產(chǎn)品尺寸圖:
使用方法_1(Arduino 控制器)
使用硬件
- 1 * Arduino UNO 控制器
- 杜邦線若干
- USB 數(shù)據(jù)線
硬件連接
Arduino_code_1
#include <Wire.h> #include <ALS_APDS9960.h> ALS_APDS9960 apds = ALS_APDS9960(); int isr_flag = 0; void setup() { Serial.begin(9600); Serial.println(); Serial.println(F("--------------------------------")); Serial.println(F("SparkFun APDS-9960 - GestureTest")); Serial.println(F("--------------------------------")); 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() { handleGesture(); delay(50); } 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"); } } }
程序效果
手在上下左右遠近滑過經(jīng)過傳感器時,串口會打印如圖所示的數(shù)據(jù)
使用方法_2(Arduino 控制器)
使用硬件
- 1 * LED 發(fā)光模塊
- 1 * Arduino 控制器
- 1 * 傳感器擴展板 V5.0
- 1 * 手勢傳感器
- 1 * USB 數(shù)據(jù)線
- 1 * 4P 傳感器連接線
- 杜邦線若干
硬件連接
Arduino_code_2
#include <Wire.h> #include <ALS_APDS9960.h> #define led 4 #define APDS9960_INT 2 ALS_APDS9960 apds = ALS_APDS9960(); int temp = 0; int isr_flag = 0; void setup() { pinMode(led,OUTPUT); pinMode(APDS9960_INT, INPUT); Serial.begin(9600); Serial.println(); Serial.println(F("--------------------------------")); Serial.println(F("ALS_APDS-9960 - GestureTest")); Serial.println(F("--------------------------------")); attachInterrupt(0, interruptRoutine, FALLING); if ( apds.init() ) { Serial.println(F("APDS-9960 initialization complete")); } else { Serial.println(F("Something went wrong during APDS-9960 init!")); } 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 ) { detachInterrupt(0); handleGesture(); isr_flag = 0; attachInterrupt(0, interruptRoutine, FALLING); } } void interruptRoutine() { isr_flag = 1; switch(temp){ case 1: digitalWrite(led,HIGH); break; case 2: digitalWrite(led,LOW); break; } } void handleGesture() { if ( apds.isGestureAvailable() ) { switch ( apds.readGesture() ) { case DIR_UP: Serial.println("UP"); temp = 1; break; case DIR_DOWN: Serial.println("DOWN"); temp = 2; 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"); temp = 0; } } }
程序效果
- 向上滑動時,通過串口打印‘UP’,同時 LED 亮起
- 向下滑動時,通過串口打印‘DOWM’,同時 LED 熄滅
應(yīng)用案例
1、測試環(huán)境
- 硬件環(huán)境:Starduino UNO R3 、傳感器V5.0擴展板、紅外手勢傳感器、8*8點陣
- 軟件環(huán)境:Arduino IDE 1.7.7
2、引腳定義
- -:電源地
- +:電源正極
- SDA:數(shù)據(jù)引腳
- SCL:時引腳
3、硬件連接
4、例子程序
#include <Wire.h> #include <ALSROBOT_APDS9960.h> const int DINPin = 4; //數(shù)據(jù)引腳 連接到數(shù)字P4口 const int CLKPin = 5; //時鐘引腳 連接到數(shù)字P5口 const int LTHPin = 6; //鎖存引腳 連接到數(shù)字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() { pinMode(DINPin,OUTPUT); //設(shè)置數(shù)據(jù)引腳為輸出 pinMode(CLKPin,OUTPUT); //設(shè)置鎖存引腳為輸出 pinMode(LTHPin,OUTPUT); //設(shè)置時鐘引腳為輸出 // Initialize Serial port Serial.begin(9600); Serial.println(); Serial.println(F("--------------------------------")); Serial.println(F("ALSROBOT APDS-9960 - GestureTest")); Serial.println(F("--------------------------------")); 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++) { //持續(xù)刷新250次 for(char x = 0;x <8;x++) { shiftOut(DINPin, CLKPin, MSBFIRST, LieScan[x]); //先選擇列 shiftOut(DINPin, CLKPin, MSBFIRST, Left[x]); //再送行數(shù)據(jù) digitalWrite(LTHPin, LOW); //刷新顯示 digitalWrite(LTHPin, HIGH); } } } void down() { for(unsigned char times_1 = 0;times_1 <250;times_1++) { //持續(xù)刷新250次 for(char x = 0;x <8;x++) { shiftOut(DINPin, CLKPin, MSBFIRST, LieScan[x]); //先選擇列 shiftOut(DINPin, CLKPin, MSBFIRST, Down[x]); //再送行數(shù)據(jù) digitalWrite(LTHPin, LOW); //刷新顯示 digitalWrite(LTHPin, HIGH); } } } void up() { for(unsigned char times_1 = 0;times_1 <250;times_1++) { //持續(xù)刷新250次 for(char x = 0;x <8;x++) { shiftOut(DINPin, CLKPin, MSBFIRST, LieScan[x]); //先選擇列 shiftOut(DINPin, CLKPin, MSBFIRST, Up[x]); //再送行數(shù)據(jù) digitalWrite(LTHPin, LOW); //刷新顯示 digitalWrite(LTHPin, HIGH); } } } void right() { for(unsigned char times_1 = 0;times_1 <250;times_1++) { //持續(xù)刷新250次 for(char x = 0;x <8;x++) { shiftOut(DINPin, CLKPin, MSBFIRST, LieScan[x]); //先選擇列 shiftOut(DINPin, CLKPin, MSBFIRST, Right[x]); //再送行數(shù)據(jù) digitalWrite(LTHPin, LOW); //刷新顯示 digitalWrite(LTHPin, HIGH); } } } void far() { for(unsigned char times_1 = 0;times_1 <250;times_1++) { //持續(xù)刷新250次 for(char x = 0;x <8;x++) { shiftOut(DINPin, CLKPin, MSBFIRST, LieScan[x]); //先選擇列 shiftOut(DINPin, CLKPin, MSBFIRST, Far[x]); //再送行數(shù)據(jù) digitalWrite(LTHPin, LOW); //刷新顯示 digitalWrite(LTHPin, HIGH); } } } void near() { for(unsigned char times_1 = 0;times_1 <250;times_1++) { //持續(xù)刷新250次 for(char x = 0;x <8;x++) { shiftOut(DINPin, CLKPin, MSBFIRST, LieScan[x]); //先選擇列 shiftOut(DINPin, CLKPin, MSBFIRST, Near[x]); //再送行數(shù)據(jù) digitalWrite(LTHPin, LOW); //刷新顯示 digitalWrite(LTHPin, HIGH); } } } void moren() { for(unsigned char times_1 = 0;times_1 <250;times_1++) { //持續(xù)刷新250次 for(char x = 0;x <8;x++) { shiftOut(DINPin, CLKPin, MSBFIRST, LieScan[x]); //先選擇列 shiftOut(DINPin, CLKPin, MSBFIRST, 0x00); //再送行數(shù)據(jù) 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 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、程序效果 如圖所示,當手滑動時,點陣顯示相應(yīng)的滑動方向
產(chǎn)品相關(guān)推薦
例子程序下載
- Arduino 庫文件加載方法
- 產(chǎn)品例子程序及庫文件下載鏈接:https://pan.baidu.com/s/1pMwbo5X 密碼:d73v