aboutsummaryrefslogtreecommitdiffstats
path: root/docs/source/lang/api/pwmwrite.rst
diff options
context:
space:
mode:
authorHanna Mendes Levitin <hanna@anomaly-3.local>2010-12-01 03:37:07 -0600
committerHanna Mendes Levitin <hanna@anomaly-3.local>2010-12-01 03:37:07 -0600
commita0549b4a15a7093f990fffa4bc1d2d52ec1c16e2 (patch)
tree9c6383570be6d045db4d8942ca3137fc3cb5b8a0 /docs/source/lang/api/pwmwrite.rst
parent3b7f16dba295da3a0071564ac284c25dc56e6b18 (diff)
downloadlibrambutan-a0549b4a15a7093f990fffa4bc1d2d52ec1c16e2.tar.gz
librambutan-a0549b4a15a7093f990fffa4bc1d2d52ec1c16e2.zip
docs, now with style
Diffstat (limited to 'docs/source/lang/api/pwmwrite.rst')
-rw-r--r--docs/source/lang/api/pwmwrite.rst49
1 files changed, 49 insertions, 0 deletions
diff --git a/docs/source/lang/api/pwmwrite.rst b/docs/source/lang/api/pwmwrite.rst
new file mode 100644
index 0000000..7a1d51f
--- /dev/null
+++ b/docs/source/lang/api/pwmwrite.rst
@@ -0,0 +1,49 @@
+.. highlight:: cpp
+
+.. _lang-pwmwrite:
+
+pwmWrite()
+==========
+
+Writes a :ref:`PWM wave <pwm>` to a pin. You can use this to make an
+LED get brighter or dimmer, control a servomotor, etc. After a call to
+pwmWrite(), the pin will output a steady square wave with the given
+duty cycle. You can change the duty cycle later by calling pwmWrite()
+again with the same pin and a different duty.
+
+.. contents:: Contents
+ :local:
+
+Library Documentation
+---------------------
+
+.. doxygenfunction:: pwmWrite
+
+Example
+-------
+
+Sets the output to the LED proportional to the value read from the
+potentiometer::
+
+ int ledPin = 13; // LED connected to pin 13 (Maple)
+ int analogPin = 3; // potentiometer connected to analog pin 3
+ int val = 0; // variable to store the read value
+
+ void setup() {
+ pinMode(ledPin, OUTPUT); // sets the LED pin as output
+
+ pinMode(analogPin, PWM); // sets the potentiometer pin as PWM
+ // output
+ }
+
+ void loop() {
+ val = analogRead(analogPin); // read the input pin
+
+ analogWrite(ledPin, val / 16); // analogRead values go from 0 to 4095,
+ // analogWrite values from 0 to 65535
+ }
+
+See Also
+--------
+
+- :ref:`Maple PWM tutorial <pwm>`