Skip to content

Instantly share code, notes, and snippets.

@i5ar
Last active July 7, 2018 16:32
Show Gist options
  • Save i5ar/fa95e5be75e852f9a736a0f815b04223 to your computer and use it in GitHub Desktop.
Save i5ar/fa95e5be75e852f9a736a0f815b04223 to your computer and use it in GitHub Desktop.
Pro Micro RGB led loop
/* Pro Micro loop RGB led common cathode */
//int yellowPin = 10;
//int brightness = 8;
//int fadeAmount = 8;
int redPin = 3;
int greenPin = 5;
int bluePin = 6;
int redAmount = 8;
int greenAmount = 8;
int blueAmount = 8;
int redVal = 224;
int greenVal = 128;
int blueVal = 8;
void setup() {
// pinMode(yellowPin, OUTPUT);
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
}
void loop() {
// analogWrite(yellowPin, brightness);
// brightness = brightness + fadeAmount;
analogWrite(redPin, redVal);
analogWrite(greenPin, greenVal);
analogWrite(bluePin, blueVal);
redVal = redVal + redAmount;
greenVal = greenVal + greenAmount;
blueVal = blueVal + blueAmount;
// if (brightness <= 8 || brightness >= 224) {
// fadeAmount = -fadeAmount;
// }
if (redVal <= 8 || redVal >= 224) {
redAmount = -redAmount;
}
if (greenVal <= 8 || greenVal >= 224) {
greenAmount = -greenAmount;
}
if (blueVal <= 8 || blueVal >= 224) {
blueAmount = -blueAmount;
}
delay(64); // milliseconds
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment