Tutorial.Fade History

Hide minor edits - Show changes to markup

May 02, 2012, at 03:35 AM by Scott Fitzgerald -
Changed line 42 from:
to:
November 16, 2011, at 12:26 AM by Scott Fitzgerald -
Changed lines 39-40 from:
to:
November 16, 2011, at 12:22 AM by Scott Fitzgerald -
Changed line 41 from:
to:
September 30, 2011, at 02:57 AM by Scott Fitzgerald -
Changed line 41 from:
to:
September 28, 2010, at 01:29 PM by Tom Igoe -
Changed lines 29-30 from:
to:
Changed lines 39-40 from:
to:
September 23, 2010, at 10:28 PM by Christian Cerrito -
Changed lines 3-4 from:

Fading

to:

Fading

Changed lines 7-8 from:

Hardware Required

to:

Hardware Required

September 17, 2010, at 05:16 PM by Tom Igoe -
Changed lines 53-57 from:
  • BareMinimum - bare minimum code needed to start a sketch
  • Blink? -turn an LED on and off.
  • DigitalReadSerial - read a switch, print the state out to the Serial Monitor
  • AnalogReadSerial - read a potentiometer, print the state out to the Serial Monitor
  • Analog Input - use a potentiometer to control an LED's brightness
to:
September 16, 2010, at 10:02 PM by Tom Igoe -
Changed line 41 from:
to:
September 16, 2010, at 10:01 PM by Tom Igoe -
Changed line 41 from:
to:
September 08, 2010, at 08:03 PM by Tom Igoe -
Changed lines 35-51 from:

In order to fade your LED off and on, gradually increase your PWM value from 0 (all the way off) to 255 (all the way on), and then back to 0 once again to complete the cycle. You do this using two for() loops, one which fades your LED up, and another which dims it back down.

In the first of these for() loops:

for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=5)

a variable called fadeValue starts with a value of 0 and is increased by five points each pass through the lfor loop while fadeValue is <= (less then or equal too) 255. This number is then written to your ledPin, gradually increasing the brightness of your LED. A short delay() of 30 milliseconds is used during each loop of this process, creating a gradual fade.

After fadeValue reaches it's maximum value, 255, this process is reversed in the second loop:

for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=5)

This time, 5 points is subtracted from fadeValue with each cycle of your program. After another short delay(), the process is repeated while fadeValue is >= (greater than or equal to) 0, gradually dimming your LED.

Once fadeValue goes back to 0, the program moves back into original for() loop, and the entire cycle begins again.

to:

In order to fade your LED off and on, gradually increase your PWM value from 0 (all the way off) to 255 (all the way on), and then back to 0 once again to complete the cycle. In the sketch below, the PWM value is set using a variable called brightness. Each time through the loop, it increases by the value of the variable fadeAmount.

If brightness is at either extreme of its value (either 0 or 255), then fadeAmount is changed to its negative. In other words, if fadeAmount is 5, then it is set to -5. If it's 55, then it's set to 5. The next time through the loop, this change causes brightness to change direction as well.

analogWrite() can change the PWM value very fast, so the delay at the end of the sketch controls the speed of the fade. Try changing the value of the delay and see how it changes the program.

September 08, 2010, at 07:56 PM by Tom Igoe -
Changed lines 35-36 from:

In order to fade your LED off and on, it is necessary to gradually increase your PWM value from 0 (all the way off) to 255 (all the way on), and then back to 0 once again to complete the cycle. You accomplish this using two for() loops, one which fades your LED up, and another which dims it back down.

to:

In order to fade your LED off and on, gradually increase your PWM value from 0 (all the way off) to 255 (all the way on), and then back to 0 once again to complete the cycle. You do this using two for() loops, one which fades your LED up, and another which dims it back down.

Changed lines 41-42 from:

a variable called fadeValue, with an original value of 0, is increased by five points each pass through the program while fadeValue is <= (less then or equal too) 255. This number is then written to your ledPin, gradually increasing the brightness of your LED. A short delay() of 30 milliseconds is used during each loop of this process, creating a gradual fade.

to:

a variable called fadeValue starts with a value of 0 and is increased by five points each pass through the lfor loop while fadeValue is <= (less then or equal too) 255. This number is then written to your ledPin, gradually increasing the brightness of your LED. A short delay() of 30 milliseconds is used during each loop of this process, creating a gradual fade.

September 08, 2010, at 07:52 PM by Tom Igoe -
Changed lines 5-6 from:

Demonstrates the use of the analogWrite() function in fading an LED off and on. AnalogWrite uses pulse width modulation ?, turning a digital pin on and off very quickly, to create a fading effect.

to:

Demonstrates the use of the analogWrite() function in fading an LED off and on. AnalogWrite uses pulse width modulation (PWM), turning a digital pin on and off very quickly, to create a fading effect.

September 08, 2010, at 07:51 PM by Tom Igoe -
Changed lines 5-6 from:

Demonstrates the use of the analogWrite() function in fading an LED off and on.

to:

Demonstrates the use of the analogWrite() function in fading an LED off and on. AnalogWrite uses pulse width modulation ?, turning a digital pin on and off very quickly, to create a fading effect.

Changed lines 31-34 from:

After declaring pin 9 to be your ledPin, there is nothing to take care of in the setup() function of your code.

The analogWrite() function that you will be using in the main loop of your code expect two arguments: One telling the function which pin to write to, and one indicating what PWM value to write.

to:

After declaring pin 9 to be your ledPin, there is nothing to do in the setup() function of your code.

The analogWrite() function that you will be using in the main loop of your code requires two arguments: One telling the function which pin to write to, and one indicating what PWM value to write.

September 08, 2010, at 07:48 PM by Tom Igoe -
Changed line 53 from:
to:
September 08, 2010, at 07:47 PM by Tom Igoe -
Changed lines 15-16 from:

Connect the anode (the longer, positive leg) of your LED to digital output pin 9 on your Arduino through a 220-ohm resistor. Connect the cathode (the shorter, negative leg) directly to ground.

to:

Connect the anode (the longer, positive leg) of your LED to digital output pin 9 on your Arduino through a 220-ohm resistor. Connect the cathode (the shorter, negative leg) directly to ground.

September 08, 2010, at 07:47 PM by Tom Igoe -
August 29, 2010, at 06:54 PM by Christian Cerrito -
Changed lines 31-32 from:
 After declaring pin 9 to be your ledPin, there is nothing to take care of in the setup() function of your code. 
to:

After declaring pin 9 to be your ledPin, there is nothing to take care of in the setup() function of your code.

Changed lines 35-36 from:

In order to fade your LED off and on, it is necessary to gradually increase your PWM value from 0 (all the way off) to 255 (all the way on), and then back to 0 once again to complete the cycle. This is accomplished using two for() loops, one which fades your LED up, and another which dims it back down.

to:

In order to fade your LED off and on, it is necessary to gradually increase your PWM value from 0 (all the way off) to 255 (all the way on), and then back to 0 once again to complete the cycle. You accomplish this using two for() loops, one which fades your LED up, and another which dims it back down.

August 24, 2010, at 07:53 AM by Christian Cerrito -
August 24, 2010, at 07:44 AM by Christian Cerrito -
Changed lines 56-57 from:
  • See Also
to:

See Also

August 24, 2010, at 07:44 AM by Christian Cerrito -
Changed lines 60-63 from:
to:
Changed lines 67-69 from:
  • DigitalReadSerial - Read a switch, print the state out to the Serial Monitor
  • AnalogReadSerial - Read a potentiometer, print the state out to the Serial Monitor
  • Analog Input - Use a potentiometer to control an LED's brightness
to:
  • DigitalReadSerial - read a switch, print the state out to the Serial Monitor
  • AnalogReadSerial - read a potentiometer, print the state out to the Serial Monitor
  • Analog Input - use a potentiometer to control an LED's brightness
August 24, 2010, at 07:42 AM by Christian Cerrito -
Changed lines 55-68 from:
to:
August 23, 2010, at 11:51 PM by Christian Cerrito -
Changed lines 11-13 from:
  • LED
  • 220 ohm resistor
to:
  • a LED
  • a 220 ohm resistor
August 23, 2010, at 11:32 PM by Christian Cerrito -
Changed lines 49-51 from:

Once fadeValue again equals 0, we move back into original for() loop, and the entire cycle begins again.

to:

Once fadeValue goes back to 0, the program moves back into original for() loop, and the entire cycle begins again.

August 23, 2010, at 11:09 PM by Christian Cerrito -
Changed lines 31-36 from:
 After declaring pin 9 to be our ledPin, there is nothing to cake care of in the setup() function of your code. 

The analogWrite() functions that you will be using in the main loop of your code expect two arguments: One telling the function which pin to write to, and one indicating what PWM value, from 0 to to 255, to write.

In order to gradually fade your LED of and on, you first need to gradually increase this PWM value from 0 (all the way off) to 255 (all the way on), and then back to 0 once again for a complete cycle. This is accomplished using two for() loops.

to:
 After declaring pin 9 to be your ledPin, there is nothing to take care of in the setup() function of your code. 

The analogWrite() function that you will be using in the main loop of your code expect two arguments: One telling the function which pin to write to, and one indicating what PWM value to write.

In order to fade your LED off and on, it is necessary to gradually increase your PWM value from 0 (all the way off) to 255 (all the way on), and then back to 0 once again to complete the cycle. This is accomplished using two for() loops, one which fades your LED up, and another which dims it back down.

Changed lines 41-42 from:

a variable called fadeValue, with an original value of 0, is increased by five points each pass through the program. While fadeValue is <= (less then or equal too) 255, this number is written to your ledPin, gradually increasing the brightness of your LED. A short delay() of 30 milliseconds is used during each loop of this process, creating a gradual fade.

to:

a variable called fadeValue, with an original value of 0, is increased by five points each pass through the program while fadeValue is <= (less then or equal too) 255. This number is then written to your ledPin, gradually increasing the brightness of your LED. A short delay() of 30 milliseconds is used during each loop of this process, creating a gradual fade.

Changed lines 47-49 from:

This time, 5 points is subtracted from fadeValue and written to ledPin. After another short delay(), the process is repeated all the while fadeValue is >= (greater than or equal to) 0, gradually dimming your LED. Once fadeValue hits 0, we move back into original for() loop, and the cycle begins again.

to:

This time, 5 points is subtracted from fadeValue with each cycle of your program. After another short delay(), the process is repeated while fadeValue is >= (greater than or equal to) 0, gradually dimming your LED.

Once fadeValue again equals 0, we move back into original for() loop, and the entire cycle begins again.

August 23, 2010, at 11:01 PM by Christian Cerrito -
Changed lines 33-49 from:

The analogWrite() functions that you will be using in the main loop of your code expect two arguments: One telling the function which pin to write to, and one indicating what PWM value value to write. analogWrite() is capable of

to:

The analogWrite() functions that you will be using in the main loop of your code expect two arguments: One telling the function which pin to write to, and one indicating what PWM value, from 0 to to 255, to write.

In order to gradually fade your LED of and on, you first need to gradually increase this PWM value from 0 (all the way off) to 255 (all the way on), and then back to 0 once again for a complete cycle. This is accomplished using two for() loops.

In the first of these for() loops:

for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=5)

a variable called fadeValue, with an original value of 0, is increased by five points each pass through the program. While fadeValue is <= (less then or equal too) 255, this number is written to your ledPin, gradually increasing the brightness of your LED. A short delay() of 30 milliseconds is used during each loop of this process, creating a gradual fade.

After fadeValue reaches it's maximum value, 255, this process is reversed in the second loop:

for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=5)

This time, 5 points is subtracted from fadeValue and written to ledPin. After another short delay(), the process is repeated all the while fadeValue is >= (greater than or equal to) 0, gradually dimming your LED. Once fadeValue hits 0, we move back into original for() loop, and the cycle begins again.

August 23, 2010, at 10:39 PM by Christian Cerrito -
Changed lines 5-6 from:

Demonstrates the use of the analogWrite] function in fading an LED off and on.

to:

Demonstrates the use of the analogWrite() function in fading an LED off and on.

Changed line 33 from:

The analogWrite() functions that you will be using in the main loop of your code expect two arguments: One telling the function which pin to write to, and one indicating what [Tutorial/PWM | PWM] value]] value to write. analogWrite() is capable of

to:

The analogWrite() functions that you will be using in the main loop of your code expect two arguments: One telling the function which pin to write to, and one indicating what PWM value value to write. analogWrite() is capable of

August 23, 2010, at 10:37 PM by Christian Cerrito -
Changed lines 5-6 from:

Demonstrates the use of the analogWrite in fading an LED off and on.

to:

Demonstrates the use of the analogWrite] function in fading an LED off and on.

Added lines 30-33:
 After declaring pin 9 to be our ledPin, there is nothing to cake care of in the setup() function of your code. 

The analogWrite() functions that you will be using in the main loop of your code expect two arguments: One telling the function which pin to write to, and one indicating what [Tutorial/PWM | PWM] value]] value to write. analogWrite() is capable of

August 23, 2010, at 10:19 PM by Christian Cerrito -
August 23, 2010, at 10:17 PM by Christian Cerrito -
Changed lines 5-6 from:

Demonstrates the use of the analogWrite

to:

Demonstrates the use of the analogWrite in fading an LED off and on.

Changed lines 15-16 from:

An LED connected to digital output pin 9 through a 220-ohm resistor.

to:

Connect the anode (the longer, positive leg) of your LED to digital output pin 9 on your Arduino through a 220-ohm resistor. Connect the cathode (the shorter, negative leg) directly to ground.

August 23, 2010, at 10:14 PM by Christian Cerrito -
Changed lines 5-6 from:

Demonstrates the use of analog output (PWM) to fade an LED.

to:

Demonstrates the use of the analogWrite

August 23, 2010, at 10:12 PM by Christian Cerrito -
Changed lines 7-13 from:
to:

Hardware Required

  • Arduino board
  • Breadboard
  • LED
  • 220 ohm resistor
August 23, 2010, at 09:47 PM by Christian Cerrito -
Changed lines 17-18 from:
to:
August 23, 2010, at 09:45 PM by Christian Cerrito -
Changed lines 12-13 from:
to:
August 23, 2010, at 09:43 PM by Christian Cerrito -
Changed lines 12-13 from:
to:
August 23, 2010, at 09:41 PM by Christian Cerrito -
Changed lines 12-13 from:
to:
Changed lines 17-18 from:
to:
August 23, 2010, at 09:40 PM by Christian Cerrito -
Changed lines 17-18 from:
to:
August 23, 2010, at 09:39 PM by Christian Cerrito -
Changed lines 1-18 from:
to:

Examples > Analog I/O

Fading

Demonstrates the use of analog output (PWM) to fade an LED.

Circuit

An LED connected to digital output pin 9 through a 220-ohm resistor.

click the image to enlarge

Schematic

click the image to enlarge

Changed lines 21-31 from:
to:

Code

Changed lines 24-30 from:
to:
August 23, 2010, at 09:36 PM by Christian Cerrito -
Deleted line 24:

<<<<<<<

Changed lines 28-30 from:
to:
August 23, 2010, at 09:35 PM by Christian Cerrito -
Changed lines 17-18 from:
to:
Changed lines 25-29 from:
to:
August 23, 2010, at 09:34 PM by Christian Cerrito -
Added lines 10-11:
  • LED
  • 220 ohm resistor
Changed lines 17-18 from:
to:
Changed line 25 from:
to:
August 21, 2010, at 08:37 AM by Christian Cerrito -
Changed lines 15-16 from:
to:
Changed line 23 from:
to:
August 13, 2010, at 10:23 PM by Tom Igoe -
Added lines 1-35:

Share