# \[아두이노] 핀 출력 (데이터 쓰기)

### 코드

{% code title="아날로그 데이터를 쓸 때 (PWM 핀 (3, 5, 6, 9, 10, 11번 핀))" %}

```
@아두이노 {핀 번호}번 핀 아날로그 {데이터}쓰기
```

{% endcode %}

{% code title="디지털 데이터를 쓸 때 (디지털 핀(2\~13번 핀))" %}

```
@아두이노 {핀 번호}번 핀 디지털 {데이터}쓰기
```

{% endcode %}

***

### 설명

<mark style="color:purple;">`핀 쓰기`</mark>는 아두이노와 연결된 핀에 전기 데이터를 보내주는 출력 코드예요.

더 자세한 내용이 궁금하다면, [아두이노](/arduino/025.md)를 참고해 주세요.

***

### 주의사항

* 핀 모드 설정이 우선되어야 하고, 읽어올 핀의 핀 모드가 출력으로 설정되어 있어야 해요.
  * 아날로그 쓰기를 한다면, 핀 모드가 아날로그 출력으로 설정되어 있어야 하고, PWM 핀에 연결되어 있어야 해요.
  * 디지털 쓰기를 한다면, 핀 모드가 디지털 출력으로 설정되어 있어야 하고, 디지털 핀에 연결되어 있어야 해요.
* 아날로그 핀은 쓸 수 없어요. `@아두이노 {핀 번호}번 핀 아날로그 {데이터}쓰기`는 PWM을 위한 코드예요.
* {데이터}의 값에는 디지털 핀의 값은 0과 1로, 아날로그 출력 핀(PWM)의 값은 0\~255까지 쓸 수 있어요.

***

### 파이썬 대응 코드

아두이노 코드는 파이썬에 대응되는 코드가 없어 제공되지 않아요.

***

### 예시

{% code title="예시 코드" %}

```
@아두이노 6번 핀 아날로그 출력 설정
@아두이노 3번 핀 디지털 출력 설정
@아두이노 6번 핀 아날로그 11쓰기
@아두이노 3번 핀 디지털 1쓰기
```

{% endcode %}

{% code title="예시 코드의 결과" %}

```
(아두이노에서 6번 핀에 전기가 11만큼 흐름)
(아두이노에서 3번 핀에 전기가 흐름)
```

{% endcode %}

***

### 검색 키워드

digitalWrite, analogWrite


---

# 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://codebook.horang.it/arduino/028.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.
