Welcome to Code Sharer, a code gallery for creating, saving and sharing all kinds of code snippets.

Arduino (c) — Analog Output Fading

Posted On: Wednesday, January 11, 2017 at 3:24 PM Last updated: Wednesday, May 9, 2018 at 12:30 PM

Fade the output of an analog output pin on an arduino.
int ledPin  =  9 ;         // LED connected  to  d i g i t a l  pin 9
void setup( ) {
}
// nothing to declare in the set up BUT it still needs to be defined
void loop ( ) {
// fade in from min to max in increments of 5 points :
for(int fadeValue = 0 ; fadeValue<= 2 5 5 ; fadeValue += 5 ) {
// s e t s the value ( range from 0 to 255):
analog Write ( l e dP i n , fadeValue );
// wait for 30 milliseconds to see the dimming to occur delay ( 3 0 ) ;
}

// fade out from max to min in increments of 5 points :
for (int fadeValue = 255 ; fadeValue>= 0 ; fadeValue= 5 ) {
// s e t s the value ( range from 0 to 255):
analogWrite ( ledPin , fadeValue ) ; // wait for 30 milliseconds to see the dimming occur delay ( 3 0 ) ;
}
}

Ryan Bradley-Evans (Admin)

Joined on
Contributed 16 Snips

Get Social and Share

Tags