下一个程序 呼吸灯breathing LED

回复
shengnian
帖子: 23
注册时间: 周二 2月 14, 2017 6:20 am

下一个程序 呼吸灯breathing LED

帖子 shengnian » 周五 12月 01, 2017 5:23 am

// breathing LED light

int ledPin = 10;

void setup() {
pinMode(OUTPUT,ledPin);

}

void loop() {
// put your main code here, to run repeatedly:
fadeOn(2000,5);
fadeOff(1500,5);
}

void fadeOn(unsigned int time, int increament){
for (byte value=0; value<255;value+=increament){
analogWrite(ledPin, value);
delay(time/(255/increament));
}
}

void fadeOff(unsigned int time, int decreament){
for (byte value =255; value >0; value-=decreament){
analogWrite(ledPin, value);
delay(time/(255/decreament));
}
}

shengnian
帖子: 23
注册时间: 周二 2月 14, 2017 6:20 am

Re: 下一个程序 呼吸灯breathing LED

帖子 shengnian » 周日 12月 03, 2017 5:45 am

analogWrite(ledPin, Value);

The analogWrite() function is to assign the PWM pin an analog value between 0 and 255.

Roughly every 1/500 of a second, the PWM pins outputs a pulse using digital signals. By controlling the length of on and off, it creates an equivalent effect of carrying out voltage between 0 volts and 5 volts. The length of pulse is called “pulse width” so PWM refers to pulse width modulation.


It's different from digitalWrite(ledPin,HIGH/LOW)

回复

在线用户

正浏览此版面之用户: 没有注册用户 和 1 访客