led灯闪烁代码_如何设置LED灯并使其通过代码闪烁
led灯闪烁代码
Coding an LED Light is introductory project that shows you how software and hardware interact with each other. It's a simple project you can complete in a weekend that'll help you learn some basic aspects of hardware.
对LED灯进行编码是一个介绍性项目,向您展示软件和硬件之间如何交互。 这是一个简单的项目,您可以在周末完成,这将帮助您学习硬件的一些基本方面。
By the end of the project, you will code your own LED light, have the knowledge to manipulate the LED to on/off in intervals you choose, and learn basic principles of hardware.
在项目结束时,您将编写自己的LED灯,具有在选择的时间间隔内操作LED开/关的知识,并学习硬件的基本原理。
The Elegoo Uno starter kit has all the hardware as well as instructions you need to make a simple LED Light. The LED Light is the first project offered with their kit.
Elegoo Uno入门套件具有所有硬件以及制作简单LED灯所需的说明。 LED灯是其套件提供的第一个项目。
Elegoo Uno comes with many other projects and takes you through from beginner to advanced projects. Each project in the box advances your skills in a simple, easy to follow way.
Elegoo Uno附带了许多其他项目,并带您从初学者到高级项目。 框中的每个项目都以简单,易于遵循的方式提高了您的技能。
您需要的组件 (Components You'll Need)
Elegoo Uno R3 (Elegoo Uno R3)
The Elogoo Uno R3 is a microcontroller board. Microcontrollers are embedded inside devices to control the actions and features of a product. They are compact integrated circuits designed to control operations.
Elogoo Uno R3是微控制器板。 微控制器嵌入设备内部,以控制产品的动作和功能。 它们是设计用于控制操作的紧凑型集成电路。
The microcontroller that is included in the Elogoo Uno R3 has 14 digital input/output pins, 6 analog inputs, a USB connection, a power jack, and a reset button. This board has everything you need to support the microcontroller. Simply plug in the USB Cable to turn the microcontroller on.
Elogoo Uno R3中包含的微控制器具有14个数字输入/输出引脚,6个模拟输入,USB连接,电源插Kong和复位按钮。 该评估板提供了支持微控制器所需的一切。 只需插入USB电缆即可打开微控制器。
USB电缆 (USB Cable)
You need a USB Cable to connect the Elegoo Uno R3 to your computer and turn it on. USB stands for Universal Serial Bus. The USB is used to connect your computer to devices such as digital cameras, printers, scanners, and external hard drives.
您需要USB电缆将Elegoo Uno R3连接到计算机并打开它。 USB代表通用串行总线。 USB用于将您的计算机连接到设备,例如数码相机,打印机,扫描仪和外部硬盘驱动器。
In our project, we will use a USB cable to connect our microcontroller to our computer.
在我们的项目中,我们将使用USB电缆将微控制器连接到计算机。
发光二极管 (LEDs)
LED stands for light emitting diode. It has a positive and negative lead. The longer side is the positive lead.
LED代表发光二极管。 它有正面和负面的线索。 较长的一面是正极。
如何组装零件 (How to assemble the components)
In this project, we are only going to make the LED blink.
在这个项目中,我们只会使LED闪烁。
First, we need to plug in the USB Cable to the board and then the computer.
首先,我们需要将USB电缆插入板子,然后再插入计算机。
Then we need to plug in the LED to GND (GND is the reference point in an electrical circuit from which voltages are measured, and is a common return path for electric current) and the 13 input on the board.
然后,我们需要将LED插入GND(GND是电路中的基准点,从中可以测量电压,并且是电流的通用返回路径)和板上的13个输入。
使LED闪烁的代码: (Code to make the LED flash on/off:)
After the microcontroller board is plugged into the computer and the LED is on the board itself, we need to write some simple code to make the LED blink.
将微控制器板插入计算机并且LED本身就在板之后,我们需要编写一些简单的代码来使LED闪烁。
// the setup function runs once when you press reset or power the board void setup() { // initialize digital pin LED_BUILTIN as an output. pinMode(LED_BUILTIN, OUTPUT); } // the loop function runs over and over again forever void loop() { digitalWrite(LED_BUILTIN, HIGH); // turn the LED on delay(1000); // wait for a second digitalWrite(LED_BUILTIN, LOW); // turn the LED off delay(1000); // wait for a second }
The code above basically turns the LED on for 1 second and then turns it off for one second.
上面的代码基本上将LED点亮1秒钟,然后将其熄灭1秒钟。
This function is in a continuous loop. The
digitalWriteis a function that takes in 2 parameters,
LED_BUILTINand
HIGH || LOW. The loop basically takes in the LED, and then turns the volt to
HIGHwhich turns it on. Then after 1 second it turns the same LED off by turning the volt to
LOW.
此功能处于连续循环中。
digitalWrite是一个带有两个参数的函数,
LED_BUILTIN和
HIGH || LOW
HIGH || LOW。 环路基本上接收LED,然后将电压转到
HIGH,然后将其打开。 然后,在1秒钟后,通过将电压转到
LOW来关闭同一LED。
这是最终产品: (Here's the Final Product:)
The goal of this little LED Light Coding project was to introduce you to elementary principles of how hardware and software can be combined. I hope you enjoyed it!
这个小巧的LED Light Coding项目的目的是向您介绍如何组合硬件和软件的基本原理。 我希望你喜欢它!
翻译自: https://www.freecodecamp.org/news/code-behind-an-led-light/
led灯闪烁代码
- 如何通过代码设置TextView的Margin参数--TextView篇
- CEF 如何通过代码设置flash插件路径
- 如何通过代码实现进入到手机的设置页面(比如开启gps设置的页面)
- 如何在平台上实现LED灯的效果?如信号灯,来短信/来电时LED动画闪烁
- 程序中如何给自己设置硬件断点(通过程序代码设置数据断点而不使用JTAG)
- c++builder上使用TIDTCPServer和TIDTCPClient进行简单通信,如何通过代码动态设置TIDTCPServer的Bindings属性。
- WPF中如何通过代码设置DockPanel.Dock属性
- 【python-1】爬虫时如何通过Requests设置自己的ip地址,附检测方法(代码+注释)
- 如何通过代码获取以及设置android4.0系统的以太网配置中的静态IP,子网掩码,默认网关,DNS
- 当DataGridView控件通过代码在运行时设置了数据源,如何在运行时修改DataGridView控件的列
- 如何通过代码设置文件关联功能(Mac OSX 和Win)
- 一段简单的代码记录如何通过 js 给 HTML 设置自定义属性,并且通过点击事件获取到所设置的自定义属性值...
- CListCtrl虚拟列表如何通过代码设置选中某条记录
- 如何通过代码设置控件在 Grid 里的行和列?
- 如何通过代码设置WPF控件的字体,颜色
- 安卓开发如何通过代码设置组件背景
- C#编程生成的Word2007版本的文件如何兼容Word2003?(通过代码将docx文件转存为doc文件)
- 如何在JSP页面中设置断点,调试代码?
- 如何通过代码直接获得Spring容器中的Bean?
- Solidity如何通过代码减少gas消耗