ESP8266 Arduino-PWM点亮LED灯

/**

* 模块管脚 <--> 开发板管脚 <--> 外设管脚

*  GPIO16          D0              LED

*/

 

#define LED_PIN D0

 

void setup() {

  // put your setup code here, to run once:

  // 设置管脚为输出模式

  pinMode(LED_PIN, OUTPUT);

  // 初始化时输出低电位(最亮)

  analogWrite(LED_PIN, 0);

}

 

void loop() {

  // put your main code here, to run repeatedly:

  // 电平升高,从明到暗

  for (int i = 0; i < 1024; i++)

  {

     analogWrite(LED_PIN, i);

     delay(2);

   }

   // 电平降低,从暗到明

   for (int i = 1024; i >= 0; i--)

   {

     analogWrite(LED_PIN, i);

     delay(2);

   }

}

你可能感兴趣的:(ESP8266,Arduino)