Original Address-Https://www.arduino.cc/en/Tutorial/Blink
Flashing
This example shows the simplest thing you can do with a Arduino/genuino board: blinking The LEDs on the board.
Hardware requirements
Arduino Development Board
LED (not necessary)
220 Ohm resistor (not required)
Circuit
This routine uses LEDs on most of the Arduino/genuino development boards. This led lamp is connected to the digital pin, and it has different pin numbers on the various models of the Development Board. For the convenience of everyone, we have defined a constant led_builtin for each of the Development Board's profiles. With this constant, it is more convenient for you to have LED lights on the control panel. The following is a comparison of the values of the respective Development Board constants and the corresponding digital PIN numbers:
- D13-101
- D13-due
- D1-gemma
- D13-intel Edison
- D13-intel Galileo Gen2
- D13-leonardo and Micro
- D13-lilypad
- D13-lilypad USB
- d13-mega2560
- D13-mini
- d6-mkr1000
- D13-nano
- D13-pro
- D13-pro Mini
- D13-uno
- D13-yún
- D13–zero
If you want to use this code to light an external LED, you need to build the circuit yourself. First, a pin of the resistor is connected to the digital pin specified by the Led_builtin constant, and then the longer one foot of the LED is connected to the resistor, and the other foot (negative, cathode) of the short LED is then connected to GND. We show the connection of the UNO board, and its Led_builtin constant value is D13.
The resistor resistance of the connected LEDs can be higher than 220 ohms, as long as the LEDs below 1K are lit.
Schematic diagram
Code
Once you've built the above circuit and connected your Arduino/genuino board to your computer, you can open the Arduino IDE software and enter the following code. You can also call this code directly from the menu File/examples/01.basics/blink. The first thing you need to do in the code is to configure the Led_builtin pin as the output pin, as follows:
Pinmode (Led_builtin, OUTPUT);
In the main loop code, you need to light the LEDs with this code:
Digitalwrite (Led_builtin, high);
This will power the LED anode 5V. This causes the two pin of the LED to generate a voltage difference and light it up. Then you will use the following code to turn off the LEDs:
Digitalwrite (Led_builtin, low);
This line of code causes the Led_builtin pin to go back to 0V, leaving the LED off. Between the light and the off, you will want to have enough time intervals so that the human eye can see the light and off changes, the delay () command is to let the development Board in 1000 milliseconds (1 seconds) to stop doing nothing. When you use the delay () command, nothing happens within the delay time you specify. Once you understand each of the basic examples, you can look at the Blinkwithoutdelay routines to learn how to generate a delay while letting the board do something else.
When you understand this example, refer to the Digitalreadserial routine to learn how to read a button that connects to the Development Board.
/* Blink Turns on a LED on for one second, then off for one second, repeatedly. Most Arduinos has an on-board LED can control. On the UNO, MEGA and ZERO it's attached to digital pin-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 was connected to on your Arduino model, check the Technical Specs of your Bo ARD at Https://www.arduino.cc/en/Main/Products This example code was in the public domain. Flashes the LED for one second, then turns off for a second, and keeps cycling almost all Arduino development boards have led lights on the board to control. In UNO, MEGA, and ZERO it is connected to the D13 pin, while the MKR1000 is connected to the 6 pin. The value of the led_builtin is the correct pin value that has been set to the corresponding Development Board. If you would like to know if the LEDs on your Arduino board are connected to that pin, please take a look at the technical specifications of your development Board, which you can refer to Https://www.arduino.cc/en/Main/Products modified 8 May 20 by Scott Fitzgerald modified 2 Sep by Arturo Guadalupi modified 8 Sep by Colby newman*///setup function is when You perform a void Setup () {//Initialize the digital pin led_builtin as output pinmode (Led_builtin, outputs) after you power up or restart the board;The}//loop function is continuously looping through the Void loop () {Digitalwrite (led_builtin, high); LED light (High level) delay (1000) is lit; Wait one second digitalwrite (Led_builtin, low); Give the LED light off delay (1000) to low level; Wait a second}
QQ Group
Welcome to join our extended family Click to join Arduino Fever player Group number 8580606
Reference
- Setup ()
- Loop ()
- Pinmode ()
- Digitalwrite ()
- Delay ()
- Analogreadserial-Read the potentiometer and output its status to the Arduino serial window
- Bareminimum-A necessary code block for writing an Arduino code
- Digitalreadserial-Reads a key and outputs its status to the Arduino serial window
- Fade-demonstrates the use of analog outputs to darken the LEDs.
- Readanalogvoltage-Read the analog input and output the voltage to the Arduino serial window
Arduino Translator Series-LED light flashing