0Pricing
Arduino & IoT Academy · บทเรียน

delay() และจังหวะการกะพริบ

หยุดการทำงานชั่วคราวเพื่อสร้างจังหวะกะพริบที่มองเห็นได้

delay() และจังหวะการกะพริบ เป็นบทเรียน Arduino & IoT Academy ฟรีบน CoddyKit นี่คือบทเรียนที่ 3 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Arduino & IoT Academy และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Arduino & IoT Academy มีบทเรียนทั้งหมด 4 บทเรียน

บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ

Add a Pause

Switching a pin on and off happens in microseconds, far too fast to see. To make a real blink, you tell the board to wait with delay. ⏱️

delay Speaks Milliseconds

The delay function pauses your sketch for a number of milliseconds. One second is 1000 of them, so delay(1000) waits one full second.

delay(1000);

Freeze the Light On

Turn the LED HIGH, then call delay. The board sits still and the LED stays lit for the whole pause before doing anything else.

digitalWrite(ledPin, HIGH);
delay(1000);

Then Hold It Off

Now drive the pin LOW and delay again. The LED stays dark for that pause, giving the off half of your blink its own visible moment.

digitalWrite(ledPin, LOW);
delay(1000);

The Full Blink Loop

Stack those four lines inside loop() and you get a steady blink: on, wait, off, wait, repeat. That is the classic Blink sketch.

void loop() {
  digitalWrite(ledPin, HIGH);
  delay(1000);
  digitalWrite(ledPin, LOW);
  delay(1000);
}

Faster or Slower

Change the number to change the rhythm. A smaller value like delay(200) makes a quick flash, while a larger one slows the blink right down.

delay(200);

On and Off Can Differ

The two delays do not have to match. A long on-time and short off-time gives a steady glow with a brief wink between pulses.

delay Stops Everything

Here is the catch: during a delay the board does nothing else. It cannot read a button or sensor, because delay blocks the whole sketch.

Fine for Now

For a simple blink, blocking is fine. Later you will meet millis, a way to time events without freezing the rest of your program.

Tiny vs Big Waits

delay handles milliseconds, but for very short pauses there is delayMicroseconds. You will need it later for precise sensor timing.

Loop Does the Repeating

You never write a repeat command. Because loop() runs again automatically, your on-off-wait pattern repeats forever on its own.

Quick Check

You want the LED to stay on for exactly two seconds.

Recap

You used delay to pace your blink, learned it counts milliseconds, and saw that it blocks everything else. Next you will wire a real LED. 🎉

คำถามที่พบบ่อย

บทเรียน “delay() และจังหวะการกะพริบ” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “delay() และจังหวะการกะพริบ” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Arduino & IoT Academy ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Arduino & IoT Academy มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “delay() และจังหวะการกะพริบ”

หยุดการทำงานชั่วคราวเพื่อสร้างจังหวะกะพริบที่มองเห็นได้ คุณปฏิบัติ Arduino & IoT Academy ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Arduino & IoT Academy หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน Arduino & IoT Academy บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 3 จากทั้งหมด 4 บทเรียน

บทเรียน “delay() และจังหวะการกะพริบ” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน Arduino & IoT Academy นี้ได้ไหม

ได้ บทเรียน Arduino & IoT Academy ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. pinMode และ OUTPUT
  2. digitalWrite HIGH และ LOW
  3. delay() และจังหวะการกะพริบ
  4. ต่อ LED ภายนอกอย่างปลอดภัย
← กลับไปที่ Arduino & IoT Academy