0Pricing
Arduino & IoT Academy · レッスン

setup() は 1 回だけ実行される

ピンとシリアルを準備する起動時のブロックです

「setup() は 1 回だけ実行される」はCoddyKit上の無料Arduino & IoT Academyレッスンです。 これはレッスン1/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはArduino & IoT Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Arduino & IoT Academyコースには全4レッスンが含まれています。

このレッスンの一部はまだ翻訳されておらず、英語で表示されています。

Two Blocks, Every Sketch

Every Arduino program is built from two functions. The first one is setup(), and getting it right makes everything else click. 🙂

Runs Exactly Once

The big idea: setup() runs a single time, right after your board powers on or resets. It never repeats on its own.

What setup() Looks Like

It is a function with empty parentheses and curly braces. Everything you write between those braces is your startup code.

void setup() {
  // startup code goes here
}

Why void?

The word void means setup returns no value. You are just running commands, not handing a result back to anyone.

Prepare Your Pins

setup is where you announce how each pin behaves. Use pinMode() once here so the board knows a pin sends or receives signals.

void setup() {
  pinMode(13, OUTPUT);
}

Open the Serial Channel

Talking to your computer also starts here. Serial.begin() opens the USB link once, ready for messages later.

void setup() {
  Serial.begin(9600);
}

One-Time Jobs Only

Put things here that should happen a single time: setting pin modes, starting Serial, or initializing a sensor. Setup is your launch checklist.

It Runs First, Always

No matter what else is in your sketch, setup() always runs before any repeating logic. It is the very first thing the board does.

Reset Triggers It Again

Press the board's reset button or cut and restore power, and setup() fires once more. A fresh start means a fresh setup.

Combine Several Lines

You can stack many one-time tasks inside setup. The board runs them top to bottom, then moves on for good.

void setup() {
  pinMode(13, OUTPUT);
  Serial.begin(9600);
}

Empty Is Still Valid

A sketch can have an empty setup() if nothing needs preparing. The braces must still be there, even with nothing inside.

void setup() {
}

Quick Check

Let's test how setup() behaves.

Recap: setup()

You learned that setup() runs once at startup, returns void, and is where you prepare pins and Serial. It is your board's launch checklist. 🎉

よくある質問

「setup() は 1 回だけ実行される」レッスンは無料ですか?

はい。「setup() は 1 回だけ実行される」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Arduino & IoT Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Arduino & IoT Academyコースには全4レッスンが含まれています。

「setup() は 1 回だけ実行される」で何を学びますか?

ピンとシリアルを準備する起動時のブロックです ブラウザで直接実行するハンズオンコードでArduino & IoT Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

Arduino & IoT Academyを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのArduino & IoT Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン1/4です。

「setup() は 1 回だけ実行される」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このArduino & IoT Academyレッスンでコードを書いて実行できますか?

はい。すべてのArduino & IoT Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. setup() は 1 回だけ実行される
  2. loop() は繰り返し実行される
  3. コメントと読みやすいスケッチ
  4. コンパイルエラーと読み方
← Arduino & IoT Academyに戻る