Brooke's LED Fade
From CHS Sigma
Assignment:
Our first assignment was to make a LED fade in and out. This assignment demonstrates the use of analogWrite(). Analogwrite() uses pulse width modulation (PWM) to make the fading effect. The result of the project was a wave of text growing and shrinking the LED brightness.
Process:
First, I wired up my circuit using a 220Ω resistor and made the LED blink. Then went to trying to make the LED fade in and out, rather then blink. I then used analogWrite() to make the fading effect.
Problems and Solutions:
One problem I had was using analogWrite in the code to make the fade. I then solved my problem by researching about analogWrite and how to use correctly in a code. After doing my researching about analogWrite i correctly used it in the code to make the LED fade in and out.
Circuit Diagram:
Code:
int led = 9; int brightness = 0; int fadeAmount = 5; void setup() { pinMode (9, OUTPUT); } void loop() { analogWrite(led, brightness); brightness = brightness + fadeAmount; if (brightness <= 0 || brightness >= 255) { fadeAmount = -fadeAmount; } delay(30); }