Case 01 Light-emitting diode experiment
- Case goal:
To enable students to master the working principle and method of light-emitting diodes, use Arduino to write programs, compile and download programs.
- Case hardware equipment:
Install Arduino software on a computer, a set of UNO development boards, a light-emitting diode, a 220 ohm resistor, a breadboard, and several connections.
- Case effect:
- Case theory knowledge:
- Case circuit connection diagram
- Program list:
Procedure 1:
void setup() {
// initialize digital pin 13 as an output.
#define led 2
pinMode(led, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
Procedure 2:
void setup() {
// initialize digital pin 2 an output.
pinMode(2, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(2, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(2, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
- summary:
Control the IO pin through 2, and control the LED light-emitting diode to switch once every second. Program 1 and Program 2 have the same function, please compare them, what is the difference? Please use the digital 13 port to write a program to achieve the same function?