LEDIntensity \ Learning \ Wiring ALPHA 1.0
Author: Hernando Barragán
Description: Wiring is an electronic sketchbook and hardware electronics for developing ideas. It is a context for learning fundamentals of computer programming and prototyping with electronics within the context of the electronic arts.
Keywords: Wiring, Processing, Interactive Media, Electronic Arts, Programming, C, C++, Hernando Barragán

Search wiring.org.co:

This example is for Wiring version 0023+. 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.

Fading in/out, controlling an LED Intensity by BARRAGAN
Demonstrates the use of PWM pins (analog output) by dimming a light (LED) from off to maximum intensity and back.

    int value = 0;   // variable to keep the actual value
    int ledpin = 0;  // light connected to analog pin 0

    void setup()
    {
      // nothing for setup
    }

    void loop()
    {
      for(value = 0 ; value <= 1023; value+=5)  // fade in (from min to max)
      {
        analogWrite(ledpin, value);             // sets the value (range from 0 to 1023)
        delay(30);                              // waits for 30 milli seconds to see the dimming effect
      }
      for(value = 1023; value >=0; value-=5)    // fade out (from max to min)
      {
        analogWrite(ledpin, value);
        delay(30);
      }
    }