[arduino]-1-Basics代码解读

Posted ryu-janeway

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[arduino]-1-Basics代码解读相关的知识,希望对你有一定的参考价值。

arduino IDE 自带示例中的Basics系列,

可以说是

向一个拥有C系家族编程语言基础的人

解释清楚了它自己的基本操作

BareMinimum(基本文件结构):

void setup() {
  // put your setup code here, to run once:
  // 这里放的setup代码只会运行一次
}

void loop() {
  // put your main code here, to run repeatedly:
  // 这里放的主要代码会在setup之后不停循环执行
}

 

Start(有修改):

// the setup routine runs once when you press reset:
//setup会在你按下reset之后首先执行
void setup() {                
  // initialize the digital pin as an output.
  // 将数字端口初始化为输出模式
  pinMode(0, OUTPUT); //LED on Model B
  pinMode(1, OUTPUT); //LED on Model A  or Pro
}

// the loop routine runs over and over again forever:
//loop会一遍又一遍的永远执行下去
void loop() {
  digitalWrite(0, HIGH);   // turn the LED on (HIGH is the voltage level)
                                    // 打开LED(HIGH代表电压高低)
  digitalWrite(1, HIGH);
  delay(1000);               // wait for a second
  digitalWrite(0, LOW);    // turn the LED off by making the voltage LOW
                                    // 将电压降低来关闭LED
  digitalWrite(1, LOW); 
  delay(1000);               // wait for a second
}

 

Blink:

/*
  Blink
  闪烁

  Turns an LED on for one second, then off for one second, repeatedly.
  点亮LED持续1秒钟,然后熄灭LED一秒钟,一次循环。

  Most Arduinos have an on-board LED you can control.
  许多arduino都有一个板载LED可供使用

  On the UNO, MEGA and ZERO it is attached to digital pin 13, on MKR1000 on pin 6.
  在UNO,MEGA和ZERO上它与数字端口13相连。//后略

  LED_BUILTIN is set to the correct LED pin independent of which board is used.
  LED_BUILTIN被设定为各种主板相对应的LED而与型号无关。
  
  If you want to know what pin the on-board LED is connected to on your Arduino  model, check the Technical Specs of your board at:
  如果你想知道你的这种arduino上到底哪个端口连接着板载LED,那么查看详细的说明可以到:
  https://www.arduino.cc/en/Main/Products

  modified 8 May 2014
  by Scott Fitzgerald
  modified 2 Sep 2016
  by Arturo Guadalupi
  modified 8 Sep 2016
  by Colby Newman

  This example code is in the public domain.

  http://www.arduino.cc/en/Tutorial/Blink
*/

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  // 将LED_BUILTIN端口初始化为输出模式。
  pinMode(LED_BUILTIN, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);                       // wait for a second
}

 

以上的代码皆可直接下载到UNO上运行

关于具体代码的理解,

请各位善用自己的英语知识

与互联网工具

 

本节关键代码词汇含义对照:

setup ≈ set up 意思非常之多,初始化,安排,安装,构建,都可以

loop 循环

pin 端口/针脚,1pin就是一根线,所以电脑里面的电源插口,4P,6P,24P就是这样来的

built in 内置/板载

digital 数字,关于模拟和数字的区别,你用着用着就明白了

delay 等待/延迟

以上是关于[arduino]-1-Basics代码解读的主要内容,如果未能解决你的问题,请参考以下文章

Arduino HX711模块(电子秤 )

图形化编程娱乐于教,Kittenblock arduino实例解读,按钮控灯

图形化编程娱乐于教,Kittenblock arduino实例解读,红外线发送

图形化编程娱乐于教,Kittenblock arduino实例解读,红外线接收

图形化编程娱乐于教,Kittenblock arduino实例解读,红外线发送

图形化编程娱乐于教,Kittenblock arduino实例解读,红外线发送