/* Program 5-5: Use analogWrite() function to dim an LED */ const int LED = 5; /* connect an LED */ void setup() { pinMode(LED, OUTPUT); /* set LED pin as output */ } void loop() { int dutycycle; /* increase duty cycle from 0 to 255 */ for (dutycycle = 0; dutycycle < 256; dutycycle++) { analogWrite(LED, dutycycle); delay(30); /* let each duty cycle to last for 30ms */ } }