“手势传感器示例”的版本间的差异
(创建页面,内容为“{| style="width: 800px;" |- | <br> <p style="color: #4F4E4E;font-size:220%">'''手势传感器示例'''</p> <br> 别上、下、左、右、远、近的手势<br> <…”) |
|||
第6行: | 第6行: | ||
<p style="color: #4F4E4E;font-size:220%">'''手势传感器示例'''</p> | <p style="color: #4F4E4E;font-size:220%">'''手势传感器示例'''</p> | ||
<br> | <br> | ||
− | + | 识别检测上、下、左、右、远、近的手势 | |
+ | <br> | ||
<p style="color: #E87E05;font-size:155%">所需硬件</p> | <p style="color: #E87E05;font-size:155%">所需硬件</p> | ||
*[[mCookie-Core]] | *[[mCookie-Core]] |
2018年5月21日 (一) 02:43的最新版本
手势传感器示例
所需硬件
电路搭建 将Battery、Core、Hub堆叠在一起,使用4pin传感器线连接传感器与Hub扩展板的IIC接口,通过MicroUSB数据线接入电脑。
代码 #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");
}
}
}
|