// This example makes a led connected to analog output (PWM) pin 3 fade in // and out, by changing its voltage between 0V and 5V. // In Arduino a maximum output value of 255 corresponds to output voltage 5V. #define pinPWM 3 // analog output (PWM) pin with connected led int v = 0; // analog output value int s = 5; // speed of fading void setup() { } void loop() { v += s; // change v with step s if ((v < 0) || (v > 255)) { // if v outside its value range, then s *= -1; // reverse direction of fading v += s; // restore v to within value range } analogWrite(pinPWM, v); // set PWM pin a to value v delay(10); }