Last active
August 29, 2015 14:01
-
-
Save randrews/48f9798817ef5650e2af 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
int angle = 0; | |
int redState = 0; | |
void setup() { | |
pinMode(0, OUTPUT); | |
pinMode(1, OUTPUT); | |
pinMode(2, OUTPUT); | |
} | |
void loop() { | |
angle = (++angle) % 360; | |
double level0 = sin(angle * 3.14159 / 180.0); | |
double level1 = sin(((angle+180) % 360) * 3.14159 / 180.0); | |
if(angle == 0) redState = !redState; | |
analogWrite(0, convert(level0)); | |
analogWrite(1, convert(level1)); | |
digitalWrite(2, redState); | |
delay(8); | |
} | |
// Convert -1..1 to 0..255 | |
int convert(double level){ | |
return (level + 1.0) / 2.0 * 255.0; | |
} |
Because it's already in a loop, and I might want to do other things in loop() besides fade an LED. :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
why don't you simply wrap it in a for loop condition?, you might think about turning on and off too