您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

UserFunctions.cpp 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // User data functions. Modify these functions for your data items.
  2. #include "UserTypes.h"
  3. #include "Wire.h"
  4. #include "I2Cdev.h"
  5. #include "MPU6050.h"
  6. //------------------------------------------------------------------------------
  7. MPU6050 mpu;
  8. static uint32_t startMicros;
  9. // Acquire a data record.
  10. void acquireData(data_t* data) {
  11. data->time = micros();
  12. mpu.getMotion6(&data->ax, &data->ay, &data->az,
  13. &data->gx, &data->gy, &data->gz);
  14. }
  15. // setup AVR I2C
  16. void userSetup() {
  17. #if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
  18. Wire.begin();
  19. Wire.setClock(400000);
  20. #elif I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE
  21. Fastwire::setup(400, true);
  22. #endif
  23. mpu.initialize();
  24. }
  25. // Print a data record.
  26. void printData(Print* pr, data_t* data) {
  27. if (startMicros == 0) {
  28. startMicros = data->time;
  29. }
  30. pr->print(data->time- startMicros);
  31. pr->write(',');
  32. pr->print(data->ax);
  33. pr->write(',');
  34. pr->print(data->ay);
  35. pr->write(',');
  36. pr->print(data->az);
  37. pr->write(',');
  38. pr->print(data->gx);
  39. pr->write(',');
  40. pr->print(data->gy);
  41. pr->write(',');
  42. pr->println(data->gz);
  43. }
  44. // Print data header.
  45. void printHeader(Print* pr) {
  46. startMicros = 0;
  47. pr->println(F("micros,ax,ay,az,gx,gy,gz"));
  48. }