(PWM)Pulse with Modulation is a kind of technique for getting analog output results with digital control controller used to form a square wave, a signal switched between 0 or 1 or On / Off.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
int brightness = 0; int fadeAmount = 5; // set the value of fadeAmount void setup() { pinMode(9, OUTPUT); //defines the pin 9 to output; } void loop() { analogWrite(9, brightness);// set the brightness; brightness = brightness + fadeAmount;//change the brightness if (brightness == 0 || brightness == 255) { fadeAmount = -fadeAmount ; } delay(30); // Set the Delay } |
Download the sample code here > 14Core_PWM_Control
Starter #3 Pulse with modulation or PWM in Arduino