# 三軸加速度模組

![](/files/-MITX1p2poemG5h05xDl)

## **指令**

![](/files/-MITVsBoP-dkZ0r1_JCL)

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

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

### 範例 BlocklyDuino 積木畫布

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

![](/files/-MITW20W78MEAtjOY9wC)

![](/files/-MITWd-t50LCsYniBkQK)

## 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>" %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://cavedu.gitbook.io/cavedu/hangeekduino/samplecode/input_module/accelerometer.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
