欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Arduino

程序员文章站 2024-03-23 18:07:58
...

Arduino Day1

2020_10_26

开发设备:Arduino Uno 副板
开发环境:Arduino IDE

基础:

void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:

}

Arduino的代码类似于C#和Java,有setup()loop()两部分。
其中:

  • setup() 是Arduino程序启动时调用的命令。
    • pinMode(13,INPUT);
  • loop()是Arduino程序运行时工作的命令。
    • digitalWrite(13,HIGH);

实验:

实验1:Blink点亮小灯

最开始,点亮 Uno 上的 LED 小灯。

/*
  Blink

  Turns an LED on for one second, then off for one second, repeatedly.

  Most Arduinos have an on-board LED you can control. On the UNO, MEGA and ZERO
  it is attached to digital pin 13, on MKR1000 on pin 6. LED_BUILTIN is set to
  the correct LED pin independent of which board is used.
  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:
  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.
  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
}

思路:
setup():声明13号接口作为输出,Uno 上的 LED 小灯设计时接在13号数字接口。
loop():数字接口分别输出高、低电平。

相关标签: arduino arduino

上一篇: 砍树

下一篇: 【dfs】买门票