Framework (A-Z)

Reference for Wiring version 1.0 Build 0100+ If you have a previous version, use the reference included with your software. If see any errors or have any comments, let us know.

Name

analogWrite()

Examples
int outpin = 29;
int val = 0;

void setup() {
  pinMode(outpin, OUTPUT);   // set the PWM pin as OUTPUT
}

void loop() {
  analogWrite(outpin, val);  // sets the value of PWM pin 29
  val = (val + 10) % 255;    // increment value and keep it in 
                             // the 0-255 range.
}
Description The analogWrite() method sets the value of a PWM output pin. By default possible values range from 0-255 (see the setPWMResolution() command). On Wiring v1 boards the PWM capable pins are: 29, 30, 31, 35, 36 and 37. On Wiring S board the PWM capable pins are: 4, 5, 6, 7, 19 and 20. Note: analogWrite is an alias for the PWMWrite() command. Doing analogWrite() on a non PWM pin will cause the pin to be set to HIGH with no other effect.
Syntax
analogWrite(pin,value)
Parameters
pin int: The PWM output pin number
value int: a value in the range 0-255
Returns None
Usage Application
Related noAnalogWrite()
setPWMResolution()
setPWMPrescale()
analogRead()
Updated on July 07, 2011 11:07:48pm PDT

Creative Commons License