Skip to content

Instantly share code, notes, and snippets.

@woodif
Created June 26, 2015 14:26
Show Gist options
  • Save woodif/b5981d946ab85852103a to your computer and use it in GitHub Desktop.
Save woodif/b5981d946ab85852103a to your computer and use it in GitHub Desktop.
// 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(10, flip);
}
void loop() {
// non-blocking
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment