Advertisement
ccarman602

Lesson-10-Gyro

Nov 25th, 2021
1,023
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Gravity Acceleration
  2. #include "LIS3DHTR.h"
  3. #ifdef SOFTWAREWIRE
  4.     #include <SoftwareWire.h>
  5.     SoftwareWire myWire(3, 2);
  6.     LIS3DHTR<SoftwareWire> LIS;   //Software I2C
  7.     #define WIRE myWire
  8. #else
  9.     #include <Wire.h>
  10.     LIS3DHTR<TwoWire> LIS;        //Hardware I2C
  11.     #define WIRE Wire
  12. #endif
  13.  
  14. void setup() {
  15.     Serial.begin(9600);
  16.     while (!Serial) {};
  17.     LIS.begin(WIRE, 0x19); //IIC init
  18.     delay(100);
  19.     LIS.setOutputDataRate(LIS3DHTR_DATARATE_50HZ);
  20. }
  21. void loop() {
  22.     if (!LIS) {
  23.         Serial.println("LIS3DHTR didn't connect.");
  24.         while (1);
  25.         return;
  26.     }
  27.     //3 axis
  28.     Serial.print("x:"); Serial.print(LIS.getAccelerationX()); Serial.print("  ");
  29.     Serial.print("y:"); Serial.print(LIS.getAccelerationY()); Serial.print("  ");
  30.     Serial.print("z:"); Serial.println(LIS.getAccelerationZ());
  31.  
  32.     delay(500);
  33. }
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement