# 三軸加速度模組

![](https://1275793585-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LaZQFBYOS3O0ksiEmR1%2F-MITWj3se1m73e-is7Nz%2F-MITX1p2poemG5h05xDl%2FGyro.jpg?alt=media\&token=679711e3-94e5-4d75-b247-7b029ca55be4)

## **指令**

![](https://1275793585-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LaZQFBYOS3O0ksiEmR1%2F-MITVYgrkCPtVq7kS3DW%2F-MITVsBoP-dkZ0r1_JCL%2FLesson_10_AccelerometerSensor2.png?alt=media\&token=799e71c0-654f-43f7-a295-15f10d385bf8)

## **對應的**Arduino 語法

```
     LIS.getAccelerationX();
     LIS.getAccelerationY();
     LIS.getAccelerationZ();
```

### 範例 BlocklyDuino 積木畫布

在序列埠印出三軸加速度模組X軸、Y軸、Z軸的數值。

![](https://1275793585-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LaZQFBYOS3O0ksiEmR1%2F-MITVYgrkCPtVq7kS3DW%2F-MITW20W78MEAtjOY9wC%2FLesson_10_AccelerometerSensor.png?alt=media\&token=e46784c3-d8c2-47d5-a2ee-db04b2dabd62)

![](https://1275793585-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LaZQFBYOS3O0ksiEmR1%2F-MITVYgrkCPtVq7kS3DW%2F-MITWd-t50LCsYniBkQK%2FLesson_10_AccelerometerSensor3.png?alt=media\&token=fb42ea93-ca1b-4efc-aacc-e2b7788bddd3)

## Arduino 程式

```
#include "LIS3DHTR.h"
#include <Wire.h>
LIS3DHTR<TwoWire> LIS;
#define WIRE Wire

void setup()
{
  LIS.begin(WIRE, 0x19);
  delay(100);
  LIS.setOutputDataRate(LIS3DHTR_DATARATE_50HZ);

  Serial.begin(9600);

}


void loop()
{
  Serial.print("X:");
  Serial.print((LIS.getAccelerationX()));
  Serial.print(" ");
  Serial.print("Y:");
  Serial.print((LIS.getAccelerationY()));
  Serial.print(" ");
  Serial.print("Z:");
  Serial.println((LIS.getAccelerationZ()));
  delay(1000);
}
```

## 影片教學:

{% embed url="https://www.youtube.com/watch?v=XUhoKEate5Q" %}
