Created
November 27, 2010 00:58
-
-
Save ColinHarrington/717424 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 RED_PIN = 3; | |
int GREEN_PIN = 6; | |
int BLUE_PIN = 11; | |
int MAXSPEED = 255; | |
int SPEEDPAD = 80; | |
int tick = 1; | |
int rSpeed = 0; | |
int rval = 0; | |
int rGoal = 0; | |
int gSpeed = 0; | |
int gval = 0; | |
int gGoal = 0; | |
int bSpeed = 0; | |
int bval = 0; | |
int bGoal = 0; | |
void setup() { | |
rGoal = random(255); | |
gGoal = random(255); | |
bGoal = random(255); | |
rSpeed = newSpeed(); | |
gSpeed = newSpeed();; | |
bSpeed = newSpeed(); | |
pinMode(RED_PIN, OUTPUT); | |
pinMode(GREEN_PIN, OUTPUT); | |
pinMode(BLUE_PIN, OUTPUT); | |
} | |
void loop() { | |
if (tick % rSpeed == 0) { | |
if (rval == rGoal) { | |
rGoal = random(255); | |
rSpeed = newSpeed(); | |
} else if(rval < rGoal) { | |
rval++; | |
} else { rval--; } | |
analogWrite(RED_PIN, rval); | |
} | |
if (tick % gSpeed == 0) { | |
if (gval == gGoal) { | |
gGoal = random(255); | |
gSpeed = newSpeed(); | |
} else if(gval < gGoal) { | |
gval++; | |
} else { gval--; } | |
analogWrite(GREEN_PIN, gval); | |
} | |
if (tick % bSpeed == 0) { | |
if (bval == bGoal) { | |
bGoal = random(255); | |
bSpeed = newSpeed(); | |
} else if(bval < bGoal) { | |
bval++; | |
} else { bval--; } | |
analogWrite(BLUE_PIN, bval); | |
} | |
tick++; | |
} | |
int newSpeed() { | |
return random(MAXSPEED) + SPEEDPAD; | |
} | |
void writeRGB(int r, int g, int b) { | |
analogWrite(RED_PIN, r); | |
analogWrite(GREEN_PIN, g); | |
analogWrite(BLUE_PIN, b); | |
delay(1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment