Created
June 26, 2015 14:26
-
-
Save woodif/b5981d946ab85852103a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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