五,新建demo
通过IO 口来模拟 PWM,,来实现呼吸灯。具体见下面的代码:
#define MAX 1500int LED = 13;int times = 0;void setup() { // put your setup code here, to run once: pinMode(LED,OUTPUT);}void loop() { // put your main code here, to run repeatedly: times = 0; while(times<MAX) { times++; digitalWrite(LED,HIGH); delayMicroseconds(MAX-times); digitalWrite(LED,LOW); delayMicroseconds(times); } delay(500); times = 0; while(times<MAX) { times++; digitalWrite(LED,HIGH); delayMicroseconds(times); digitalWrite(LED,LOW); delayMicroseconds(MAX-times); } }下载带开发板,即可看到 呼吸灯。。。