//
// 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);
}