1
0
Fork 0
unlondon-workshops/sketchbook/RGB-Fade/RGB-Fade.ino

48 lines
1002 B
Arduino
Raw Normal View History

/*
RGB Fade-in, Fade-out
Alternates R, G and B LED on for one second, then off for one second, repeatedly.
Fading in and out
This example code is in the public domain.
modified 20 May 2016
by Shawn Nock
*/
#define RED 6
#define GREEN 5
#define BLUE 3
#define STEPS 8
#define MAX_BRIGHTNESS 255
#define BRIGHTNESS_INCREMENT (MAX_BRIGHTNESS / STEPS)
2016-05-23 20:48:26 -04:00
#define DELAY 100
#define DELAY_INCREMENT (DELAY / STEPS)
int leds[3] = {RED, GREEN, BLUE};
void setup() {
pinMode(RED, OUTPUT);
pinMode(GREEN, OUTPUT);
pinMode(BLUE, OUTPUT);
}
void loop() {
for (int i = 0; i < 3; i++) {
int cur_led = leds[i];
for (int x = 1; x <= STEPS; x++) {
int cur_brightness = BRIGHTNESS_INCREMENT * x;
analogWrite(cur_led, cur_brightness);
delay(DELAY_INCREMENT * x);
}
2016-05-23 20:48:26 -04:00
for (int x = STEPS; x > 0; x--) {
int cur_brightness = BRIGHTNESS_INCREMENT * x;
analogWrite(cur_led, cur_brightness);
delay(DELAY_INCREMENT * x);
}
}
delay(DELAY);
}