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 语法(转)
-
My_arduino(2)小项目代码1
-
Arduino
-
Arduino IDE 开发ESP8266 上传DHT11温湿度数据至onenet
-
Arduino+ESP8266WIFI(2)——DHT11温湿度数据自动上传
-
Arduino在vscode中输出乱码解决方法——亲测有效
-
Arduino实验七——抢答器设计实验
-
使用AVR-GCC编程Arduino 博客分类: CRadioLinux+BSD Arduinogccavravrdudeavr-gcc
-
在Arduino上用Java编程 2.TotoroVM使用方法 博客分类: Arduino JavaArduino编译器JVM