当前位置: 首页 > 工具软件 > Netduino > 使用案例 >

Netduino PLUS2学习

闾丘成礼
2023-12-01



真正弄懂一个事务的标准是你是否可以教会别人。


官网上的get starting 英文水平有限,以便谷歌翻译,一边学习。

Now, we’ll write our Netduino App’s code. For a first project, we’ll blink the Netduino’s  programmable (blue) LED.On the right side of the screen, the Solution Explorer shows your project files.Program.cs holds the startup code for your project. We’re going to open it and write a  half dozen or so lines of code. Double-click on Program.cs (or right-click and selectOpen).In the main section of the window, we are now editing Program.cs. Click on the lineunderneath the text “// write your code here”. This is where we’ll write our code. Now, type the following:

OutputPort led = new OutputPort(Pins.ONBOARD_LED, false);

翻译:

我们开始写自己的Netduino应用的代码。在第一个程序里,我们将让Netduino的可编程的(蓝)LED灯闪烁。在屏幕的右边,在解决方案浏览器中显示你的程序的项目文件。启动文件包含在“Program.cs”中,我们将打开它并在其中写一些代码。双击“Programe.cs”或邮件点击选择选择打开。我们开始在窗口的"main"部分,编辑"Prpgrame.cs",单机"“// write your code here”."下面,输入如下文本:

OutputPort led = new OutputPort(Pins.ONBOARD_LED, false);


This first line of code creates an OutputPort. An OutputPort lets us control the voltage level of the pins on the Netduino (or in this case the voltage to the blue LED).Pins.ONBOARD_LED is shorthand which tells the Netduino which “pin” of the microcontroller we want to control and the second parameter (false) puts the LED in aninitial state of OFF (false).

翻译:

第一行代码创建了一个输出接口,一个可以让我们控制Netduino管脚的电压等级(在此处为蓝LED等的电压),“Pins.ONBOARD_LED”是一个简写,告诉Netduino我们想控制微处理器的哪个管脚,第二个参数(false)是设置LED的初始化状态为false。



Now, we’re going to blink the LED on and off repeatedly. A straight forward way to create an action which repeats forever is to put it inside a loop which never ends. Add the following code to your project.

while (true)

{

}

The keyword while tells the micro controller to do something in a loop while a certain condition is met. This condition is placed in parenthesis. In our case, we use a condition of true. Since conditions are met when they are “true”, passing it “true” means that the loop will repeat forever.

翻译:

现在我们要让LED指示灯反复闪烁。创建一个可以一直重复的动作的简单方法是将它放在一个一直不会停止的循环里。在你的项目中添加如下代码:

while(true)

{

}

关键词whie告诉微处理器,当满足一定条件是,循环做一些事情。条件放在括号里。此处我用们用了true作为条件。当为true的条件满足后,通过设置"true",意为这循环将一直重复。


Now, we’ll create the blinking LED code. Between the two sets of curly braces, insert the following four lines of code: led.Write(true); // turn on the LED Thread.Sleep(250); // sleep for 250ms led.Write(false); // turn off the LED Thread.Sleep(250); // sleep for 250ms

现在我们将创建让LED闪烁的代码。在两组花括号之间,插入下列四行代码。


我们就可以让led灯反复闪烁。


 类似资料: