//*************************************
//Program:pwm.pde
//Crate by:Deryoung.com
//Resulte: LED fade-in and out
//Interface: LED pin(+) to digital-9 and pin(-) to Ground
//*************************************
int ledPin = 9; // LED connected to digital pin 9
void setup() {
// nothing happen here!
}
void loop() {
int i; // time for fade-in/out
for(i=0;i<=255;i+=5) { // count up from 0 to 255,with 5+ step
analogWrite(ledPin,i);
delay(10);
}
for(i=255;i>=0;i-=5) { // count down from 255 to 0,with 5- step
analogWrite(ledPin,i);
delay(10);
}
}
|