|
Post by 邱老师 on Feb 3, 2021 17:59:50 GMT
这里演示了三只依次点亮的LED效果 nano插到51芯片的位置,使程序开发更简洁,连线更少,可靠性更高。 三根PWM信号线连到数码管的输入端,任意三个接口都可以,数码管的接口都对应一只LED,注意观察,这三个LED是依次点亮和熄灭,展示出一种特殊的效果。 关于NANO与开发板的针脚对照图, 可看这个链接链接:https://pan.baidu.com/s/1vjhzWEpkFFnIbqTvuRiykQ 提取码:b2qa int led1 = 9;// 指定硬件引脚,对应管脚:P3.2,P3.3,P3.4
int led2=10;
int led3=11;
int brightness = 0; // 灯的亮度变量
void setup() {
//定义3个输出引脚
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
}
void loop() {
// 设定LED脚亮度
if(brightness==0)
{
for(brightness=0;brightness<256;brightness+=5)
{
analogWrite(led1, brightness);
delay(30);
analogWrite(led2, brightness);
delay(30);
analogWrite(led3, brightness);
}
delay(30);
}
else{
for(brightness=255;brightness>0;brightness-=5)
{
analogWrite(led1, brightness);
delay(30);
analogWrite(led2, brightness);
delay(30);
analogWrite(led3, brightness);
}
delay(30);
}
}
|
|