【Arduino/Genuino 101实验】利用IMU制作触控灯-Arduino中文社区 - Powered by Discuz!

Arduino中文社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 3035|回复: 3

【Arduino/Genuino 101实验】利用IMU制作触控灯

[复制链接]
发表于 2016-12-14 17:26 | 显示全部楼层 |阅读模式
LED插到13脚上,轻敲桌子就可以控制LED啦

源码:
[mw_shl_code=cpp,true]#include "CurieIMU.h"
bool state=false;
void setup() {
  pinMode(13,OUTPUT);
  Serial.begin(9600);
//  while(!Serial) ;

  CurieIMU.begin();
  CurieIMU.attachInterrupt(eventCallback);

  // Increase Accelerometer range to allow detection of stronger taps (< 16g)
  CurieIMU.setAccelerometerRange(32);
  CurieIMU.setAccelerometerRate(1600);

  // Reduce threshold to allow detection of weaker taps (>= 100mg)
  CurieIMU.setDetectionThreshold(CURIE_IMU_TAP, 100);

  // Enable Tap detection
  CurieIMU.interrupts(CURIE_IMU_TAP);

  Serial.println("IMU initialization complete, waiting for events...");
}

void loop() {
}

static void eventCallback()
{
  if (CurieIMU.getInterruptStatus(CURIE_IMU_TAP)) {
    if (CurieIMU.tapDetected(X_AXIS, NEGATIVE))
      Serial.println("Tap detected on negative X-axis");
    if (CurieIMU.tapDetected(X_AXIS, POSITIVE))
      Serial.println("Tap detected on positive X-axis");
    if (CurieIMU.tapDetected(Y_AXIS, NEGATIVE))
      Serial.println("Tap detected on negative Y-axis");
    if (CurieIMU.tapDetected(Y_AXIS, POSITIVE))
      Serial.println("Tap detected on positive Y-axis");
    if (CurieIMU.tapDetected(Z_AXIS, NEGATIVE))
      Serial.println("Tap detected on negative Z-axis");
    if (CurieIMU.tapDetected(Z_AXIS, POSITIVE))
      Serial.println("Tap detected on positive Z-axis");
    state =!state;
    digitalWrite(13,state);
  }
}

[/mw_shl_code]
发表于 2016-12-14 17:38 | 显示全部楼层
使用加速度计控制的吗               
发表于 2016-12-14 17:43 | 显示全部楼层
把演示视频上传一下

点评

刚在群上发过了,就是敲下桌子灯就亮,再敲下就关灯  详情 回复 发表于 2016-12-14 17:46
 楼主| 发表于 2016-12-14 17:46 | 显示全部楼层
大Angel101 发表于 2016-12-14 17:43
把演示视频上传一下

刚在群上发过了,就是敲下桌子灯就亮,再敲下就关灯
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|Archiver|手机版|Arduino中文社区

GMT+8, 2024-9-20 22:36 , Processed in 0.101698 second(s), 23 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表