Photoresistor

This example is for Wiring version 0027+. If you have a previous version, use the examples included with your software. If you see any errors or have comments, please let us know.

Fade an LED brightness by BARRAGAN

Demonstrates the use of PWM pin 37 dimming an LED using the analogWrite() command


int brightness = 0;    // LED brightness
int increment = 5;     // brightness increment

void setup()
{
  pinMode(37, OUTPUT);  // set PWM pin as output
}

void loop()
{
  analogWrite(37, brightness);  
  brightness = brightness + increment;  // increment brightness for next loop iteration

  if (brightness < 0 || brightness > 1023) {  // reverse the direction of the fading 

    increment = -increment; 
  }     
  delay(20);  // wait for 20 milliseconds to see the dimming effect                          
}