Created
April 19, 2016 13:35
-
-
Save MarieKirya/202d5be5c10be984bb3263f7abca747a 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 plus = 2; | |
int gpin = 0; | |
int rpin = 1; | |
int bpin = 4; | |
float red = 0; | |
float green = 0; | |
float blue = 0; | |
int stage = 0; | |
float numColors = 128; | |
float frequency = 0; | |
float i = 0; | |
boolean dir = true; | |
long lastTime = 0; | |
// the setup routine runs once when you press reset: | |
void setup() { | |
// initialize the digital pin as an output. | |
pinMode(plus, OUTPUT); | |
pinMode(gpin, OUTPUT); | |
pinMode(rpin, OUTPUT); | |
pinMode(bpin, OUTPUT); | |
digitalWrite(plus, HIGH); | |
frequency = 5/numColors; | |
} | |
void loop() { | |
analogWrite(rpin, red); | |
analogWrite(gpin, green); | |
analogWrite(bpin, blue); | |
if (millis() - lastTime > 100) { | |
lastTime = millis(); | |
red = sin(frequency * i) * (127.0) + 128.0; | |
green = sin(frequency * i + 2.0) * (127.0) + 128.0; | |
blue = sin(frequency * i + 4.0) * (127.0) + 128.0; | |
if (dir) { | |
i = i + 1; | |
} | |
else { | |
i = i - 1; | |
} | |
if (i > numColors) { | |
dir = !dir; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment