LED Blink

From SainSmart Wiki
Jump to: navigation, search

What’s light emitting diode?

The light emitting diode referred to as LED. By gallium (Ga) and arsenic (AS) and phosphorus (P) made of a compound of the diode, when the electron and hole recombination can radiate visible light, and thus can be used to prepare a light-emitting diode in the circuit and the instrument as the indicator, or the composition of the text or digital display. Ga As P diode hair red, gallium phosphide diode green silicon carbide diode yellow.

A flashing LED lights experiment Experiment component •LED lamp : 1 •220Ω resistor : 1 •Breadboard & Jumper wires

Connect your circuit as the below diagram

Example code:

int ledPin=8; //set IO pin of LED in control
void setup()
{
   pinMode(ledPin,OUTPUT);//set digital pin IO is OUTPUT
}
void loop()
{  
   digitalWrite(ledPin,HIGH); //set PIN8 is HIGH , about 5V
   delay(1000); //delay 1000ms, 1000ms = 1s
   digitalWrite(ledPin,LOW); //set PIN8 is LOW, 0V
   delay(1000); //delay 1000ms, 1000ms = 1s
}

setup()

The setup() function is called when a sketch starts. Use it to initialize variables, pin modes, start using libraries, etc. The setup function will only run once, after each powerup or reset of the Arduino board.

loop()

After creating a setup() function, which initializes and sets the initial values, the loop() function does precisely what its name suggests, and loops consecutively, allowing your program to change and respond. Use it to actively control the Arduino board.