// This example makes a led connected to analog output (PWM) // pin 0 fade in and out, by changing the voltage between 0V // and 5V. In Wiring a maximum output value of 1023 corresponds // to output voltage 5V. // For Arduino i/o boards, the analog output pins are numbered // differently, and their output value ranges between 0 (0V) // and 255 (5V). int a = 0; // analog output pin with connected led int v = 0; // analog output value int s = 5; // speed of led fading void setup() { } void loop() { v += s; // change v with step s if ((v < 0) || (v >= 1024)) { // if v outside its value range s *= -1; // reverse direction of fading v += s; // restore v to within value range } analogWrite(a, v); // set analog out pin a to value v delay(10); }