0Pricing
Arduino & IoT Academy · レッスン

コメントと読みやすいスケッチ

コードを読みやすく保つためにメモと構造を追加します

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

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

Notes for Humans

Code is read far more often than it is written. Comments are notes you leave so future-you understands the sketch. 📝

The Single-Line Comment

Type two slashes and the rest of that line is a comment. The board ignores it completely when running your code.

// this line is just a note
digitalWrite(13, HIGH);

Comments at Line End

You can drop a comment after real code on the same line. It explains that exact step without breaking anything. Handy for quick context.

delay(1000); // pause for one second

The Block Comment

For longer notes, wrap text between a slash-star and star-slash. This block can span several lines and is great for descriptions.

/* This sketch blinks
   the onboard LED. */

Comments Don't Run

Anything inside a comment is invisible to the board. It is purely for readers, so it never affects how your device behaves.

Explain Why, Not What

Good comments say why a line exists, not just what it does. Note the reason, since the code already shows the action.

delay(20); // debounce noisy button

Indentation Aids Reading

Lines inside braces should be pushed in a few spaces. This indentation shows what belongs together and keeps logic easy to scan.

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

Name Things Clearly

A clear name beats a comment. Calling a pin ledPin instead of just a number tells the reader exactly what it controls.

int ledPin = 13;

Comment Out to Test

Temporarily disable a line by adding slashes in front. Commenting out lets you test without deleting code you might want back.

// digitalWrite(13, LOW);

Avoid Obvious Clutter

Do not narrate every line. A comment like adding one to x adds clutter, not value. Save notes for the parts that truly need explaining.

Clean Sketches Last

Tidy spacing, clear names, and useful comments make a sketch easy to fix months later. Readable code is reliable code.

Quick Check

Let's check what a comment does.

Recap: Clean Sketches

You learned to use comments with // and slash-star, indent inside braces, and name things clearly. Readable sketches stay easy to maintain. 🎉

よくある質問

「コメントと読みやすいスケッチ」レッスンは無料ですか?

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

「コメントと読みやすいスケッチ」で何を学びますか?

コードを読みやすく保つためにメモと構造を追加します ブラウザで直接実行するハンズオンコードでArduino & IoT Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

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

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

「コメントと読みやすいスケッチ」レッスンにはどのくらい時間がかかりますか?

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

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

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

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

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