Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Fairy Lamp Code Arduino
int redPin = 5;
int greenPin = 6;
int bluePin = 3;
int ledMax = 40;
int ledMin = 5;
//int brightness = ledMin;
//int fadeAmount = 1;
int redVal = ledMin;
int greenVal = ledMin;
int blueVal = ledMin;
int redFade = 1;
int greenFade = 2;
int blueFade = 3;
void setup() {
pinMode (redPin, OUTPUT);
pinMode (greenPin, OUTPUT);
pinMode (bluePin, OUTPUT);
}
void loop() {
// setColor(brightness, brightness, brightness);
// brightness = brightness + fadeAmount;
// if (brightness <= ledMin || brightness >= ledMax) {
// fadeAmount = -fadeAmount;
// }
setColor(redVal, greenVal, blueVal);
redVal = redVal + redFade;
greenVal = greenVal + greenFade;
blueVal = blueVal + blueFade;
if (redVal <= ledMin || redVal >= ledMax) {
redFade = -redFade;
}
if (greenVal <= ledMin || greenVal >= ledMax) {
greenFade = -greenFade;
}
if (blueVal <= ledMin || blueVal >= ledMax) {
blueFade = -blueFade;
}
delay(120);
}
void setColor (int red, int green, int blue) {
// using common anode LED
red = 255 - red;
green = 255 - green;
blue = 255 - blue;
analogWrite (redPin, red);
analogWrite (greenPin, green);
analogWrite(bluePin, blue);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.