c_cpp esp8266.arduino.test.pwm.ino

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c_cpp esp8266.arduino.test.pwm.ino相关的知识,希望对你有一定的参考价值。

// 
// SIMPLE PWM WITH ESP8266 & ARDUINO IDE
// USE Ticker class instead of delay() function
//

#include <Ticker.h>
#define SCALER 20

Ticker flipper;

int count = 0;
int d = 1;

void flip()
{
  // when the counter reaches a certain value, start blinking like crazy
  if (count >= PWMRANGE - 1*SCALER)
  {
    d = -1;
  }
  else if (count <= 0 + 1*SCALER) {
    d = 1;
  }
  
  count = count+d*5;
  
  analogWrite(1, count);
}

void setup() {
  //flipper.attach(0.001, flip);
  flipper.attach_ms(1, flip);  
}

void loop() {
 // non-blocking 
}
// 
// SIMPLE PWM WITH ESP8266 & ARDUINO IDE
// USE delay() function
//

int count = 0;
int d = 1;

void flip()
{
  // when the counter reaches a certain value, start blinking like crazy
  if (count >= PWMRANGE)
  {
    d = -1;
  }
  else if (count <= 1) {
    d = 1;
  }
  
  count = count+d;
  
  analogWrite(1, count);
}

void setup() {
  // setup is not required.
}

void loop() {
  flip();
  delay(2);  
}

以上是关于c_cpp esp8266.arduino.test.pwm.ino的主要内容,如果未能解决你的问题,请参考以下文章

c_cpp esp8266-webserver.ino

c_cpp esp8266.tv.ino

c_cpp esp8266oled.ino

c_cpp sprintf.esp8266.ino

c_cpp ESP8266使用Web服务器或MQTT进行ESP-01继电器控制

c_cpp ESP32-后Data.ino