1 <?xml version="1.0" encoding="ISO-8859-1"?>
2 <?xml-stylesheet type="text/xsl" href="helma.xsl"?>
3 <xmlroot xmlns:hop="http://www.helma.org/docs/guide/features/database">
4 <hopobject id="2640" name="analogWrite" prototype="Page" created="1368744741967" lastModified="1376942759668">
5 <hop:parent idref="2471" prototyperef="Page"/>
6 <is_xhtml type="boolean">true</is_xhtml>
7 <http_remotehost>192.94.94.106</http_remotehost>
8 <http_language>en-US,en;q=0.8</http_language>
10 <http_browser>Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36</http_browser>
11 <time type="date">19.08.2013 15:05:59 CDT</time>
12 <hopsession>192.94.94.172.24.115.1w0b3ne8n8y0m</hopsession>
13 <body><script src="/static/bonescript-demo.js"></script>
\r
14 <div id='side-menu' class="t3_sidebar">
\r
15 <ul class="left-menu"><strong>Navigation</strong>
\r
16 <li><a href="/static/side-menu.html">Menu contents</a></li>
\r
19 <div class="t3_content_1"><div id='connect-status'></div><div id="content_child">
\r
20 <h1>analogWrite(pin, value, [freq], [callback])</h1>
\r
21 <p>Output a pulse width modulated signal on pin.</p>
\r
22 <p>The name 'analogWrite' comes from other open source libraries with
\r
23 recognition that a PWM tied to a low-pass filter will produce an analog
\r
24 voltage level. A PWM can also be used to control some types of motors.
\r
25 Read more about PWMs on the <a href="https://en.wikipedia.org/wiki/Pulse-width_modulation">
\r
26 Wikipedia pulse-width modulation page
\r
29 <p>Valid pins are highlighted in
\r
30 yellow with "PWM" in their names (timers not yet supported):<br />
\r
31 <img src="http://beagleboard.org/static/images/cape-headers-pwm.png" width="70%" />
\r
33 <p><strong><em>Note:</em> This function is currently incompatible with pinMode
\r
34 which may force the pin mux to GPIO mode only.
\r
35 </strong></p>
\r
36 <h2>Arguments</h2>
\r
38 <li><em>pin</em>: the <a href="/Support/BoneScript/#pin">BeagleBone pin</a> identifier</li>
\r
39 <li><em>value</em>: duty cycle of the PWM as a value between 0 and 1</li>
\r
40 <li><em>freq</em>: frequency of the PWM in Hz (default is 2kHz)</li>
\r
41 <li><em>callback</em>: called upon completion</li>
\r
43 <h2>Return value</h2>
\r
45 <li><a href="/Support/BoneScript/#true">true</a> if successful</li>
\r
46 <li><a href="/Support/BoneScript/#false">false</a> on failure</li>
\r
48 <h2>callback(x)</h2>
\r
50 <li><em>x.err</em>: error status message</li>
\r
53 <button class="dynlink" onclick="demoRun('code')">run</button>
\r
54 <button class="dynlink" onclick="demoRestore('code')">restore</button>
\r
56 <pre id="code" class="use-editor" style="height:60px;">
\r
57 var b = require('bonescript');
\r
58 b.analogWrite('P9_14', 0.7, 2000, printJSON);
\r
59 function printJSON(x) { console.log(JSON.stringify(x)); }
\r
61 <div readonly id='console-output' style="height:80px;"></div>
\r
62 <h2>Build and execute instructions</h2>
\r
63 <h2>See also</h2>
\r
64 <h3>Topics</h3>
\r
66 <li><a href="/Support/BoneScript/#headers">BeagleBone expansion headers</a></li>
\r
67 <li><a href="/Support/BoneScript/#pwm">PWM</a></li>
\r
69 <h3>Related functions</h3>
\r
71 <li><a href="/Support/BoneScript/#require">require</a></li>
\r
72 <li><a href="/Support/BoneScript/pinMode">pinMode</a></li>
\r
74 <h3>Examples</h3>
\r
76 <li><a href="/Support/BoneScript/cape_bacon">Bacon Cape</a></li>
\r
77 <li><a href="/Support/BoneScript/educationalBoosterPack">Educational BoosterPack</a></li>
\r
79 </div></div><div style="clear: both;"></div></body>
80 <pseudoparent idref="2471" prototyperef="Page"/>
81 <http_referer>http://beagleboard.org/support/BoneScript/analogWrite/edit</http_referer>
82 <http_host>beagleboard.org</http_host>
83 <user>jkridner@gmail.com</user>