/**********************************
The code has been modified to make the Red, Green, and Blue LEDs fade in and
out simultaneously. This was achieved by applying the same gamma-corrected
brightness value to all three LEDs at the same time during both the fade-in and fade-out phases, instead of fading each color separately.
Difference Between LED Blinking and Fading with Gamma Correction:
LED Blinking:
Blinking refers to turning an LED on and off at a specific interval. It’s
either fully on or fully off, with no gradual transition in brightness.
Example: The LED is on for 1 second, then off for 1 second, repeating.
Effect: A sharp transition between on and off states.
Use: Typically used for signaling or simple visual feedback.
LED Fading:
Fading refers to gradually increasing or decreasing the brightness of an LED.
This is achieved by varying the PWM (Pulse Width Modulation) signal sent to
the LED over time.
Example: The LED gradually becomes brighter, reaches full brightness, then
gradually dims down to off.
Effect: A smooth transition of brightness.
Use: Often used in aesthetic lighting, transitions, or visual effects.
Gamma Correction:
Gamma correction adjusts the brightness curve to account for the human eye’s
non-linear perception of brightness. Without it, LED brightness may not appear
smooth or uniform to human eyes.
Effect: With gamma correction, the LED's brightness levels are adjusted so that
they look more natural and smoother to human perception.
Use: Ensures that the fading effect looks even and gradual, making the transitions
more visually appealing.
Summary:
LED Blinking is a simple on-off action, while LED Fading is a smooth transition
between brightness levels.
Gamma Correction is applied during fading to ensure the brightness changes appear
uniform to human eyes.
arvind ptil 12/10/24
/**********************************************************
#define RED_PIN 3 // PWM pin for Red LED
#define GREEN_PIN 6 // PWM pin for Green LED
#define BLUE_PIN 10 // PWM pin for Blue LED
#define FADE_SPEED 10 // lower is faster
// Gamma table for brightness correction
const uint8_t PROGMEM gamma8[] = {
// (same gamma table as in the original code)
};
void setup() {
pinMode(RED_PIN, OUTPUT);
pinMode(GREEN_PIN, OUTPUT);
pinMode(BLUE_PIN, OUTPUT);
}
void loop() {
// Fade in all LEDs simultaneously
for (int i = 0; i < 255; i++) {
uint8_t brightness = pgm_read_byte(&gamma8[i]);
analogWrite(RED_PIN, brightness); // Fade in Red
analogWrite(GREEN_PIN, brightness); // Fade in Green
analogWrite(BLUE_PIN, brightness); // Fade in Blue
delay(FADE_SPEED);
}
// Fade out all LEDs simultaneously
for (int i = 255; i > 0; i--) {
uint8_t brightness = pgm_read_byte(&gamma8[i]);
analogWrite(RED_PIN, brightness); // Fade out Red
analogWrite(GREEN_PIN, brightness); // Fade out Green
analogWrite(BLUE_PIN, brightness); // Fade out Blue
delay(FADE_SPEED);
}
}