Arduino/Genuino 101制作计步器-Arduino中文社区 - Powered by Discuz!

Arduino中文社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 4443|回复: 6

Arduino/Genuino 101制作计步器

[复制链接]
发表于 2016-12-13 23:24 | 显示全部楼层 |阅读模式
待写


源码如下:
[mw_shl_code=cpp,true]/*
* Copyright (c) 2016 Intel Corporation.  All rights reserved.
* See the bottom of this file for the license terms.
*/

/*
   This sketch example demonstrates how the BMI160 accelerometer on the
   Intel(R) Curie(TM) module can be used as a Step Counter (pedometer)
*/

#include "CurieIMU.h"

/* To get an interrupt notification for every step detected,
    set stepEventsEnabeled to true. Otherwise, the main loop will
    poll for the current step count.

   By design, the step counter does not immediately update on every step detected.
   Please refer to Section 2.7 of the BMI160 IMU SensorData Sheet
   for more information on this feature.
*/
const int ledPin = 13;

boolean stepEventsEnabeled = true;   // whether you're polling or using events
long lastStepCount = 0;              // step count on previous polling check
boolean blinkState = false;          // state of the LED

void setup() {
  Serial.begin(9600); // initialize Serial communication
  while(!Serial) ;    // wait for serial port to connect.
  // pinMode(13, OUTPUT);
  // intialize the sensor:
  CurieIMU.begin();
  // turn on step detection mode:
  CurieIMU.setStepDetectionMode(CURIE_IMU_STEP_MODE_NORMAL);
  // enable step counting:
  CurieIMU.setStepCountEnabled(true);

  if (stepEventsEnabeled) {
    // attach the eventCallback function as the
    // step event handler:
    CurieIMU.attachInterrupt(eventCallback);
    CurieIMU.interrupts(CURIE_IMU_STEP);  // turn on step detection

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

void loop() {
  /* Instead of using step detection event notifications,
     we can check the step count periodically */
  if (!stepEventsEnabeled) {
    updateStepCount();
  }
  digitalWrite(13, blinkState);
  blinkState = !blinkState;
  delay(1000);
}

static void updateStepCount() {
  // get the step count:
  int stepCount = CurieIMU.getStepCount();

  // if the step count has changed, print it:
  if (stepCount != lastStepCount) {
    Serial.print("Step count: ");
    Serial.println(stepCount);
    // save the current count for comparison next check:
    lastStepCount = stepCount;
  }
}

static void eventCallback(void) {
  if (CurieIMU.stepsDetected())
    updateStepCount();
}

/*
   Copyright (c) 2016 Intel Corporation.  All rights reserved.

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2.1 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with this library; if not, write to the Free Software
   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

*/[/mw_shl_code]
发表于 2016-12-17 20:35 | 显示全部楼层
出现这样的错误该怎么改呢,大神们
发表于 2016-12-17 20:38 | 显示全部楼层
发表于 2016-12-17 20:43 | 显示全部楼层
arduino中的子函数 要写到程序靠前的位置,否则就需要进行函数声明,是这样的吗,那么在ardunio中如何进行函数声明呢,希望大神们指导一下,

点评

C语言是这样,但arduino的部分版本里,写在后面也可以  详情 回复 发表于 2016-12-17 23:26
 楼主| 发表于 2016-12-17 23:26 | 显示全部楼层
zjy 发表于 2016-12-17 20:43
arduino中的子函数 要写到程序靠前的位置,否则就需要进行函数声明,是这样的吗,那么在ardunio中如何进行 ...

C语言是这样,但arduino的部分版本里,写在后面也可以
发表于 2016-12-18 10:44 | 显示全部楼层
谢谢奈何col
发表于 2022-5-12 18:40 | 显示全部楼层
bmi160是用iic通信吗
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2024-9-21 16:35 , Processed in 0.097076 second(s), 23 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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