arduino體感控制簡單版

 

https://learn.sparkfun.com/tutorials/apds-9960-rgb-and-gesture-sensor-hookup-guide/allgit

 

 硬件連線less

關鍵 VCC=  3.3v  不是 5v

 

 

 

下面這個庫實測不起做用,不知道爲何dom

 

 

 可用的庫ide

 

 

程序oop

/*
  APDS9960 - Gesture Sensor

  This example reads gesture data from the on-board APDS9960 sensor of the
  Nano 33 BLE Sense and prints any detected gestures to the Serial Monitor.

  Gesture directions are as follows:
  - UP:    from USB connector towards antenna
  - DOWN:  from antenna towards USB connector
  - LEFT:  from analog pins side towards digital pins side
  - RIGHT: from digital pins side towards analog pins side

  The circuit:
  - Arduino Nano 33 BLE Sense

  This example code is in the public domain.
*/

#include <Arduino_APDS9960.h>

void setup() {
  Serial.begin(9600);
  while (!Serial);

  if (!APDS.begin()) {
    Serial.println("Error initializing APDS9960 sensor!");
  }

  // for setGestureSensitivity(..) a value between 1 and 100 is required.
  // Higher values makes the gesture recognition more sensible but less accurate
  // (a wrong gesture may be detected). Lower values makes the gesture recognition
  // more accurate but less sensible (some gestures may be missed).
  // Default is 80
  //APDS.setGestureSensitivity(80);

  Serial.println("Detecting gestures ...");
}
void loop() {
  if (APDS.gestureAvailable()) {
    // a gesture was detected, read and print to serial monitor
    int gesture = APDS.readGesture();

    switch (gesture) {
      case GESTURE_UP:
        Serial.println("Detected UP gesture");
        break;

      case GESTURE_DOWN:
        Serial.println("Detected DOWN gesture");
        break;

      case GESTURE_LEFT:
        Serial.println("Detected LEFT gesture");
        break;

      case GESTURE_RIGHT:
        Serial.println("Detected RIGHT gesture");
        break;
        
      case GESTURE_DOWN:
        Serial.println("Detected DOWN gesture");
        break;
      default:
        // ignore
        break;
    }
  }
}

1測試的時候剛上電不要對着強光,不然觸發不了。

2實際測試,其餘物體也能夠觸發

應該是有一個光照強度值,跟初始上電瞬間採集到的光照有關係,基準值,發現觸發不了的狀況,斷電,不要對着強光重啓,復位不行。測試

還有2種其餘手勢可用:NEAR和FAR。ui

將手放在傳感器上方(大於10英寸(25釐米)),使其靠近傳感器(在傳感器上方約2英寸(5釐米)),將其保持在至少1秒鐘,而後移開您的手。spa

能夠經過如下方式實現FAR手勢:將手直接放在傳感器上方並靠近傳感器(大約2英寸(5釐米))至少1秒鐘,而後將手直接向上移至傳感器上方並超出傳感器範圍。3d

若是未正確解釋手勢,則「無」將出如今串行監視器中。code

 

 

 

相關文章
相關標籤/搜索