# setup()

コード実行の初期に呼び出され、初期化コードを記述します。

{% hint style="warning" %}
TWENETの初期化は `setup()` 関数が終了した後にも実行されます。多くの処理はTWENETが終了した後に実行するようになっているため、ここでは初期化以外の処理を行わないようにしてください。

注意すべき事項を以下に列挙します。

* スリープ`the_twenet.sleep()`の実行はできません。初期化後速やかにスリープしたいときは`begin()`関数内に最初のスリープ処理を記述してください。
* `delay()`関数は後述の処理\*に置き換えられます。この場合、パラメータの`ms`はミリ秒を指定するものではありませんが、`setup()`の32Mhzクロックに併せてミリ秒指定に近くなるように調整されています。<br>

\* `delay()`の代替処理

```cpp
static inline void delay(uint32_t ms) {
		volatile uint32_t ct = ms * CT_MAGIC;
		while (ct > 0) {
			--ct;
		}
}
```

{% endhint %}


---

# 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://mwx.twelite.info/v0.1.3/api-reference/functions/setup.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.
