Thursday, September 8, 2011

analogWrite() - a way of controlling motor speed

analogWrite()

Description:    Writes an analog value (PWM wave) to a pin. 


Can be used to light a LED at varying brightnesses or drive a motor at various speeds.
After a call to analogWrite(), the pin will generate a steady square wave of the specified duty cycle 
until the next call to analogWrite() (or a call to digitalRead() or digitalWrite() on the same pin).

The frequency of the PWM signal is approximately 490 Hz

On most Arduino boards (those with the ATmega168 or ATmega328),
this function works on pins 3, 5, 6, 9, 10, and 11.

You do not need to call pinMode() to set the pin as an output before calling analogWrite().

The analogWrite function has nothing whatsoever to do with the analog pins or the analogRead function.

Syntax:          analogWrite(pin, value)

Parameters:   pin:     the pin to write to.
                      value:  the duty cycle: between 0 (always off) and 255 (always on).

Returns:         nothing


Reference: http://arduino.cc/en/Reference/AnalogWrite

No comments:

Post a Comment