0Pricing
Arduino & IoT Academy · 课时

digitalWrite、HIGH 与 LOW

打开或关闭引脚以点亮 LED

digitalWrite、HIGH 与 LOW 是 CoddyKit 上的免费 Arduino & IoT Academy 课时。 这是第 2 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 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 导师)并解锁 Arduino & IoT Academy 课程的其余内容,请升级到 CoddyKit PRO。 Arduino & IoT Academy 课程共包含 4 节课。

「digitalWrite、HIGH 与 LOW」这节课中我会学到什么?

打开或关闭引脚以点亮 LED 你通过在浏览器中直接运行的动手代码来练习 Arduino & IoT Academy,全天候 AI 导师会在你学习这节课的过程中回答你的问题。

学习 Arduino & IoT Academy 需要有经验吗?

无需任何先前经验。CoddyKit 上的 Arduino & IoT Academy 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 2 节课,共 4 节。

「digitalWrite、HIGH 与 LOW」课时需要多长时间?

大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。

我能在这节 Arduino & IoT Academy 课中编写并运行代码吗?

能。每节 Arduino & IoT Academy 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。

此课程中的所有课时

  1. pinMode 与 OUTPUT
  2. digitalWrite、HIGH 与 LOW
  3. delay() 与闪烁时序
  4. 安全连接外部 LED
← 返回 Arduino & IoT Academy