digitalWrite HIGH และ LOW
เปิดและปิดพินเพื่อให้ LED สว่าง
digitalWrite HIGH และ LOW เป็นบทเรียน Arduino & IoT Academy ฟรีบน CoddyKit นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Arduino & IoT Academy และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Arduino & IoT Academy มีบทเรียนทั้งหมด 4 บทเรียน
บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ
Now Make It Glow
Your pin is set to OUTPUT, but it is still silent. To actually switch it on or off, you use one new command: digitalWrite. ✨
Two States Only
A digital pin lives in just two states. It is either fully on, called HIGH, or fully off, called LOW. There is nothing in between.
HIGH Means On
Writing HIGH pushes the pin up to roughly 5 volts. That voltage flows through your LED and lights it. HIGH is the on signal.
digitalWrite(ledPin, HIGH);LOW Means Off
Writing LOW drops the pin back to 0 volts. With no voltage to push current, the LED goes dark. LOW is the off signal.
digitalWrite(ledPin, LOW);The Two Arguments
digitalWrite needs two things: which pin to change, and the state to set. So you pass a pin and then either HIGH or LOW.
digitalWrite(pin, HIGH);It Belongs in loop
You set a pin's mode once, but you can change its state any time. Put digitalWrite in loop() to switch the LED on demand.
On Then Off
To blink, you simply alternate. Drive the pin HIGH, then drive it LOW, and the LED toggles between glowing and dark.
digitalWrite(ledPin, HIGH);
digitalWrite(ledPin, LOW);Too Fast to See
Run HIGH then LOW with nothing between and the LED flickers far too fast for your eyes. You need a pause, which comes next lesson.
1 and 0 Also Work
HIGH and LOW are just friendly names. Under the hood they equal 1 and 0, so digitalWrite(pin, 1) does the same as HIGH.
Read Back the State
digitalWrite changes a pin but never reports it. To check what an output pin is doing, you track the state yourself in a variable.
Mind the Wiring
The onboard LED needs no parts, but an external one can pull too much current. Always protect it with a resistor, covered soon.
Quick Check
Your LED is connected and the pin is OUTPUT. How do you turn it off?
Recap
You now control a pin with digitalWrite, using HIGH for on and LOW for off. Next you will add timing so the blink is actually visible. 🎉
คำถามที่พบบ่อย
บทเรียน “digitalWrite HIGH และ LOW” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “digitalWrite HIGH และ LOW” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Arduino & IoT Academy ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Arduino & IoT Academy มีบทเรียนทั้งหมด 4 บทเรียน
คุณจะเรียนรู้อะไรในบทเรียน “digitalWrite HIGH และ LOW”
เปิดและปิดพินเพื่อให้ LED สว่าง คุณปฏิบัติ Arduino & IoT Academy ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน
คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Arduino & IoT Academy หรือไม่
ไม่จำเป็นต้องมีประสบการณ์มาก่อน Arduino & IoT Academy บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน
บทเรียน “digitalWrite HIGH และ LOW” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน Arduino & IoT Academy นี้ได้ไหม
ได้ บทเรียน Arduino & IoT Academy ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- pinMode และ OUTPUT
- digitalWrite HIGH และ LOW
- delay() และจังหวะการกะพริบ
- ต่อ LED ภายนอกอย่างปลอดภัย