Hardware
Source: Arduino-UNO-LED
software
only official Arduino IDE can provide.
When you are ready to the above, as long as the next circuit connected, knocking a few simple lines of code, you can let the lamp flashes up!
Connecting circuit
code is as follows:
void setup ()
{
pinMode(13,OUTPUT);
}
void loop()
{
//循环语句,控制PWM亮度的增加
for (int a=0; a<=255;a++)
{
analogWrite(11,a);
delay(8);//当前亮度级别维持的时间,单位毫秒
}
//循环语句,控制PWM亮度减小
for (int a=255; a>=0;a--)
{
analogWrite(11,a);
delay(10);//当前亮度的维持的时间,单位毫秒
}
delay(800);//完成一个循环后等待的时间,单位毫秒
}