“Sensor-Gesture/zh”的版本间的差异
502748957@qq.com(讨论 | 贡献) (→开发) |
|||
第40行: | 第40行: | ||
==开发== | ==开发== | ||
===程序下载=== | ===程序下载=== | ||
− | + | 复制如下程序至Microduino IDE中,可以测试手势检测功能是否正常。 | |
+ | <source lang="cpp"> | ||
+ | #include <Microduino_Gesture.h> | ||
+ | |||
+ | // Global Variables | ||
+ | Gesture gestureSensor; | ||
+ | |||
+ | void setup() { | ||
+ | // Initialize Serial port | ||
+ | Serial.begin(9600); | ||
+ | |||
+ | // Initialize Gesture (configure I2C and initial values) | ||
+ | if ( gestureSensor.begin() ) { | ||
+ | Serial.println(F("Gesture initialization complete")); | ||
+ | } else { | ||
+ | Serial.println(F("Something went wrong during Gesture init!")); | ||
+ | } | ||
+ | |||
+ | if (gestureSensor.setGestureGain(GGAIN_2X)) { //GGAIN_1X GGAIN_2X GGAIN_4X GGAIN_8X | ||
+ | Serial.println(F("Gesture setGestureGain complete")); | ||
+ | } else { | ||
+ | Serial.println(F("Something went wrong during APDS-9960 setGestureGain!")); | ||
+ | } | ||
+ | |||
+ | // Start running the Gesture gesture sensor engine | ||
+ | if ( gestureSensor.enableGestureSensor(true) ) { | ||
+ | Serial.println(F("Gesture sensor is now running")); | ||
+ | } else { | ||
+ | Serial.println(F("Something went wrong during gesture sensor init!")); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | void loop() { | ||
+ | if ( gestureSensor.isGestureAvailable() ) { | ||
+ | switch ( gestureSensor.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"); | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | </source> | ||
===程序烧写=== | ===程序烧写=== | ||
第59行: | 第117行: | ||
*下载完毕后,打开串口监视器 | *下载完毕后,打开串口监视器 | ||
*手对着传感器上下左右运动,串口监视器会打印出对应的方向,例如UP,DOWN,FAR | *手对着传感器上下左右运动,串口监视器会打印出对应的方向,例如UP,DOWN,FAR | ||
+ | |||
==应用== | ==应用== | ||
*适用于手势控制系统 | *适用于手势控制系统 |
2018年11月15日 (四) 10:09的版本
Language | English |
---|
Sensor-Gesture产品编号:MSDI81 Sensor-Gesture是手势传感器,可以检测手的运动方向和远近程度 传感器引脚说明
特色
规格
开发程序下载复制如下程序至Microduino IDE中,可以测试手势检测功能是否正常。 #include <Microduino_Gesture.h>
// Global Variables
Gesture gestureSensor;
void setup() {
// Initialize Serial port
Serial.begin(9600);
// Initialize Gesture (configure I2C and initial values)
if ( gestureSensor.begin() ) {
Serial.println(F("Gesture initialization complete"));
} else {
Serial.println(F("Something went wrong during Gesture init!"));
}
if (gestureSensor.setGestureGain(GGAIN_2X)) { //GGAIN_1X GGAIN_2X GGAIN_4X GGAIN_8X
Serial.println(F("Gesture setGestureGain complete"));
} else {
Serial.println(F("Something went wrong during APDS-9960 setGestureGain!"));
}
// Start running the Gesture gesture sensor engine
if ( gestureSensor.enableGestureSensor(true) ) {
Serial.println(F("Gesture sensor is now running"));
} else {
Serial.println(F("Something went wrong during gesture sensor init!"));
}
}
void loop() {
if ( gestureSensor.isGestureAvailable() ) {
switch ( gestureSensor.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");
}
}
}
程序烧写
硬件搭建
效果观察
应用
项目购买图库 |