【Follow me第二季第2期】入门任务
# 开箱十分感谢得捷电子对本次活动的赞助,开发板的开箱照片
!(/data/attachment/forum/202410/16/002539evbyz8ytwy33fu5b.jpg.thumb.jpg?rand=2690.8417481488577)
!(/data/attachment/forum/202410/16/002539rxj8uijjuuj3j5uq.jpg.thumb.jpg?rand=4449.028228183285)
!(/data/attachment/forum/202410/16/002539v92z99y9z9n2an0n.jpg.thumb.jpg?rand=3121.0106373025305)
!(/data/attachment/forum/202410/16/002540qa0aa0a37xonm1m9.jpg.thumb.jpg?rand=5048.682388149384)
去官网下载Arduino IDE
!(/data/attachment/forum/202410/16/002540kbjmixatktgxuj4x.png.thumb.jpg?rand=1247.041007558023)
下载以后打开软件,需要下载Arduino UNO R4 WiFi对应的库文件,在设置和左边的菜单都中都可以选择
!(/data/attachment/forum/202410/16/002540ie3a3jpvhf384a3a.png.thumb.jpg?rand=1389.716552812017)
插上Arduino UNO R4 WiFi开发板,就直接识别到了
!(/data/attachment/forum/202410/16/002541bdtb6tt8bp8q8cg8.png.thumb.jpg?rand=2236.2089401594344)
# 任务一:搭建环境并开启第一步Blink / 串口打印Hello EEWorld!
## 1)Blink
!(/data/attachment/forum/202410/16/002541wcq1xvmc950qx1vz.png.thumb.jpg?rand=5944.079768515789)
这个是让开发板上LED自动闪烁的例程,直接在示例->basic->Blink中可以找到
官方写了详细的注释,甚至上放还提供了网址可以访问学习
```C++
/*
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.
https://www.arduino.cc/en/Tutorial/BuiltInExamples/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
}
```
编译代码,烧录到开发板,LED灯可以闪烁
!(/data/attachment/forum/202410/16/002542gu2pmlg7yskssppw.png.thumb.jpg?rand=755.107040765548)
## 2)串口打印Hello EEWorld!
!(/data/attachment/forum/202410/16/002542uvg1r9y9vmi91jgy.png.thumb.jpg?rand=4416.733954248013)
官方提供了例程,直接在示例->Communication->SerialCallResponseASCII中可以找到
官方的例程是打印0,0,0,修改了Hello EEWorld!烧录,可以在串口助手中看到输出
```C++
/*
Serial Call and Response in ASCII
Language: Wiring/Arduino
This program sends an ASCII A (byte of value 65) on startup and repeats that
until it gets some data in. Then it waits for a byte in the serial port, and
sends three ASCII-encoded, comma-separated sensor values, truncated by a
linefeed and carriage return, whenever it gets a byte in.
The circuit:
- potentiometers attached to analog inputs 0 and 1
- pushbutton attached to digital I/O 2
created 26 Sep 2005
by Tom Igoe
modified 24 Apr 2012
by Tom Igoe and Scott Fitzgerald
Thanks to Greg Shakar and Scott Fitzgerald for the improvements
This example code is in the public domain.
https://www.arduino.cc/en/Tutorial/BuiltInExamples/SerialCallResponseASCII
*/
int firstSensor = 0; // first analog sensor
int secondSensor = 0;// second analog sensor
int thirdSensor = 0; // digital sensor
int inByte = 0; // incoming serial byte
void setup() {
// start serial port at 9600 bps and wait for port to open:
Serial.begin(9600);
while (!Serial) {
;// wait for serial port to connect. Needed for native USB port only
}
pinMode(2, INPUT); // digital sensor is on digital pin 2
establishContact();// send a byte to establish contact until receiver responds
}
void loop() {
// if we get a valid byte, read analog ins:
if (Serial.available() > 0) {
// get incoming byte:
inByte = Serial.read();
// read first analog input:
firstSensor = analogRead(A0);
// read second analog input:
secondSensor = analogRead(A1);
// read switch, map it to 0 or 255
thirdSensor = map(digitalRead(2), 0, 1, 0, 255);
// send sensor values:
Serial.print(firstSensor);
Serial.print(",");
Serial.print(secondSensor);
Serial.print(",");
Serial.println(thirdSensor);
}
}
void establishContact() {
while (Serial.available() <= 0) {
Serial.println("Hello EEWorld!");// send an initial string
delay(500);
}
}
```
!()
!(/data/attachment/forum/202410/16/002542tjjcdl6kw8n9h0n0.png.thumb.jpg?rand=488.19354841664887)
# 参考资料
(https://www.arduino.cc/)
(https://docs.arduino.cc/)
页:
[1]