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="3093" name="RGB LED (Hello World for BBB)" prototype="Page" created="1379386965520" lastModified="1395748639359">
5 <hop:parent idref="20" prototyperef="Page"/>
6 <edit_skin>edit_project</edit_skin>
7 <updatetime type="date">16.09.2013 22:02:45 CDT</updatetime>
8 <uri>RGB LED (Hello World for BBB)</uri>
9 <time type="date">16.09.2013 22:02:45 CDT</time>
10 <pseudoparent idref="20" prototyperef="Page"/>
11 <registrant>jnormandin63@gmail.com</registrant>
12 <pname>RGB LED Hello World Beagle Bord Project</pname>
13 <user>jnormandin63@gmail.com</user>
14 <pvcount type="float">5.0</pvcount>
15 <body><p>Here's a real simple hello world project.&nbsp; This uses 3 pwm pins. I disabled my HDMI port.</p>
16 <p>Here's the pic of my wiring and also the code.&nbsp; I'll post more info later.&nbsp; For now this code wull fad&nbsp; red to green to blue.&nbsp; next will be walking through a rgb table.&nbsp; I already wrote&nbsp; a&nbsp; crzy spinning effect but that will be posted later.</p>
17 <p>&nbsp;</p>
18 <p>Here's the board.. just ignore the accelerometer and yello led.&nbsp; You want to copy the lower full spectrum led wiring.&nbsp; Just look at the code, or&nbsp; adapt the code whatever pins you decide to use.</p>
19 <p><img alt="" /></p>
20 <p>Here's the code:</p>
21 <p>cat fadergb.js<br />var b = require('bonescript');<br /><br />// setup starting conditions<br /><br />var awValue = 0.000001;<br />var awDirection = 1;<br />// var awPin = "P8_46";<br />var greenPin = "P8_46";<br />var bluePin = "P8_45";<br />var redPin = "P8_34";<br />var green;<br />var blue;<br /><br />// configure pin <br />b.pinMode(redPin, b.OUTPUT);<br />b.pinMode(greenPin, b.OUTPUT);<br />b.pinMode(bluePin, b.OUTPUT);<br /><br />b.analogWrite(redPin,1);<br />b.analogWrite(greenPin,1);<br />b.analogWrite(bluePin,1);<br />// call function to update brightness every 10ms<br />var red=setInterval (fade_red,5);<br />var fadeloops=0;<br /><br />function fade_red() {<br />&nbsp;b.analogWrite(redPin, awValue);<br />&nbsp;awValue = awValue + (awDirection*0.01);<br />&nbsp;if(awValue &gt; 1.0) { awValue = 1.0; awDirection = -1;&nbsp; <br />&nbsp;if(fadeloops &gt;= 1) { clearInterval(red);b.analogWrite(redPin,1);green =setInterval (fade_green,5); }}<br />&nbsp;else if(awValue &lt;= 0.01) { awValue = 0.000001; awDirection = 1;fadeloops=fadeloops +1;<br />&nbsp;}<br />}<br /><br />function fade_green() {<br />&nbsp;b.analogWrite(greenPin, awValue);<br />&nbsp;awValue = awValue + (awDirection*0.01);<br />&nbsp;if(awValue &gt; 1.0) { awValue = 1.0; awDirection = -1; <br />&nbsp;if(fadeloops &gt;= 1) { clearInterval(green); b.analogWrite(greenPin,1);blue=setInterval (fade_blue,5); }}<br />&nbsp;else if(awValue &lt;= 0.01) { awValue = 0.000001; awDirection = 1;fadeloops=fadeloops +1;<br />&nbsp;}<br />}<br /><br />function fade_blue()<br />{<br />&nbsp;b.analogWrite(bluePin, awValue);<br />&nbsp;awValue = awValue + (awDirection*0.01);<br />&nbsp;if(awValue &gt; 1.0) { awValue = 1.0; awDirection = -1; <br />&nbsp;if(fadeloops &gt;= 1) { clearInterval(blue);clearInterval(green);clearInterval(red); <br />&nbsp;&nbsp;&nbsp; &nbsp;b.analogWrite(redPin,1);b.analogWrite(greenPin,1);<br />&nbsp;&nbsp;&nbsp; &nbsp;b.analogWrite(bluePin,1);red=setInterval (fade_red,5); }}<br />&nbsp; else if(awValue &lt;= 0.01) { awValue = 0.000001; awDirection = 1;fadeloops=fadeloops +1;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; }<br /><br />&nbsp;}</p></body>
24 <render_skin>project</render_skin>
25 <shortdesc>Here's a simple start to learning how to use the Node API.
26 I picked up a rgb led and some 220 ohm resistors from radio shack. The code is real simple.. and your learn how to use setInterval and clear Interval.</shortdesc>