<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Lucky Larry</title>
	
	<link>http://luckylarry.co.uk</link>
	<description>Whats in my head...</description>
	<lastBuildDate>Sun, 07 Mar 2010 00:44:37 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/LuckyLarry" /><feedburner:info uri="luckylarry" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license><image><link>http://creativecommons.org/licenses/by-nc-sa/3.0/</link><url>http://creativecommons.org/images/public/somerights20.gif</url><title>Some Rights Reserved</title></image><item>
		<title>Easy way to make Canvas Box Frames</title>
		<link>http://feedproxy.google.com/~r/LuckyLarry/~3/-5rSTvPeKhI/</link>
		<comments>http://luckylarry.co.uk/2010/03/easy-way-to-make-canvas-box-frames/#comments</comments>
		<pubDate>Sun, 07 Mar 2010 00:30:14 +0000</pubDate>
		<dc:creator>larry</dc:creator>
				<category><![CDATA[Passing Time]]></category>
		<category><![CDATA[Photography]]></category>
		<category><![CDATA[Photoshop]]></category>
		<category><![CDATA[Box]]></category>
		<category><![CDATA[Canvas]]></category>
		<category><![CDATA[Cheap]]></category>
		<category><![CDATA[Epson]]></category>
		<category><![CDATA[Frame]]></category>
		<category><![CDATA[How to make]]></category>
		<category><![CDATA[Photo]]></category>
		<category><![CDATA[Printer]]></category>
		<category><![CDATA[Prints]]></category>
		<category><![CDATA[Quick]]></category>
		<category><![CDATA[R1900]]></category>
		<category><![CDATA[Roll]]></category>
		<category><![CDATA[Roll feed]]></category>
		<category><![CDATA[Staple gun]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://luckylarry.co.uk/?p=785</guid>
		<description><![CDATA[I like the idea of having canvas photo prints on the wall but I also have enough of an ego to think that I can take a photo good enough to warrant printing my own canvas. Also I think it&#8217;s a bit more personal too when it&#8217;s your own photo/ art.
I take alot of photos [...]


Related posts:<ol><li><a href='http://luckylarry.co.uk/2009/06/mixing-black-and-white-layers-with-colour-in-photoshop/' rel='bookmark' title='Permanent Link: Mixing black and white layers with colour in Photoshop'>Mixing black and white layers with colour in Photoshop</li><li><a href='http://luckylarry.co.uk/2009/06/how-to-photoshop-montage-quickly-and-dirty/' rel='bookmark' title='Permanent Link: How to Photoshop montage quickly and dirty&#8230;'>How to Photoshop montage quickly and dirty&#8230;</li><li><a href='http://luckylarry.co.uk/2009/08/setting-sizes-for-images-in-photoshop-and-any-other-image-editing-software/' rel='bookmark' title='Permanent Link: Setting sizes for images in Photoshop (and any other image editing software)'>Setting sizes for images in Photoshop (and any other image editing software)</li></ol>]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;"><strong>I like the idea of having canvas photo prints on the wall but I also have enough of an ego to think that I can take a photo good enough to warrant printing my own canvas. Also I think it&#8217;s a bit more personal too when it&#8217;s your own photo/ art.</strong></p>
<p style="text-align: justify;">I take alot of photos and never do anything with them, I always think about framing but to get the benefits you need to print big or do a series of panels, which is what I&#8217;ll be showing how to do along with a bit of printer/ photoshop advice. Just so you know Photoshop CS3 has some excellent tools for stitching photos together to make panoramas.</p>
<p style="text-align: justify;">There are alot of shops that will print and frame your photos on canvas for you and you can get canvas framing kits to help, so no worries if you don&#8217;t have a capable printer, it will probably just cost a bit more. I genuinely think anything over A3 you&#8217;ll want to pay to get printed anyway &#8211; because I doubt you&#8217;ll want to spend £1,000+ on an A2+ printer just to print one picture.</p>
<p style="text-align: justify;">However, I am lucky enough to have worked for Epson so I own a <a href="http://www.amazon.co.uk/gp/product/B001169T54?ie=UTF8&amp;tag=luclar-21&amp;linkCode=as2&amp;camp=1634&amp;creative=19450&amp;creativeASIN=B001169T54">Stylus Photo R1900</a>. It&#8217;s fairly cheap I guess for what it can do but it&#8217;s limited to A3, so its just on the edge of the realm of large format printers. But doing your own framing is only cheap if you already have the printer &#8211; I doubt any decent shop will charge you more than £25 per A3 canvas print so don&#8217;t buy a printer specifically to do one print!</p>
<p style="text-align: justify;"><strong>The right printer, media and ink</strong><br />
Whether using Epson printers or not to print canvas you need a decent printer and it&#8217;s all about the type of inks used, your average inkjet ink won&#8217;t stick to canvas and you need a printer that can also deal with thicker media and roll feeds. The R1900 can do that and it&#8217;s the cheapest one that you can get from Epson (around £400) &#8211; also look for the R1800, R2400 and <a href="http://www.amazon.co.uk/gp/product/B001A4YR2C?ie=UTF8&amp;tag=luclar-21&amp;linkCode=as2&amp;camp=1634&amp;creative=19450&amp;creativeASIN=B001A4YR2C">R2880</a> as good ones to try. I would recommend the R800 but the smallest canvas roll you can get is A3 (13inches/ 330mm wide), there is a cheaper A3 one, the 1400 but don&#8217;t bother as its inks  (Claria) will just flake off canvas. Not sure about whats out there from Canon, HP etc&#8230; but I guess what I&#8217;m saying is check what your printer can do any decent manufacturer or shop should do you a test sample regardless.</p>
<p style="text-align: justify;">Ok so you got the printer, now remember that I have worked for Epson, so please take what  I say as slightly biased and with a pinch of salt: Get the genuine Epson ink and media! (or the equivalent for your printer). You will honestly see the difference, in the case of the Epson stuff all the media is coated specifically for the inks and printer, so cheaper non-Epson paper/ canvas won&#8217;t work as well and you&#8217;ll see prints fade, smudge, chip off and blur &#8211; same for HP, Canon etc&#8230; If you use refills on these inkjets you&#8217;ll see the same kind of thing but you&#8217;ll also jam up your print heads &#8211; its the biggest cause of issues with the photo printers &#8211; that and continous ink feed systems. So if you use the shitty materials for this then expect the shitty results that&#8217;ll follow!</p>
<p style="text-align: justify;">For the R1900 you&#8217;re talking about <a href="http://www.amazon.co.uk/gp/redirect.html?ie=UTF8&amp;location=http%3A%2F%2Fwww.amazon.co.uk%2Fs%3Fie%3DUTF8%26x%3D0%26ref_%3Dnb%5Fsb%5Fnoss%26y%3D0%26field-keywords%3DR1900%2520original%2520ink%26url%3Dsearch-alias%253Delectronics&amp;tag=luclar-21&amp;linkCode=ur2&amp;camp=1634&amp;creative=19450">£95 for a full set of inks</a> and <a href="http://www.amazon.co.uk/gp/product/B000PMGR0U?ie=UTF8&amp;tag=luclar-21&amp;linkCode=as2&amp;camp=1634&amp;creative=19450&amp;creativeASIN=B000PMGR0U">£35-40 for the canvas roll</a>. The £140 media outlay might seem high but this will let you do around 12 A3 panels, so works out about £10 per A3 panel with plenty of ink to spare to do other stuff, if like me you do A4 panels then I&#8217;ll easily get 20 on a roll &#8211; either way using this stuff is going to get you good results, even on auto settings. My only gripe with the R1900 is that it cains the inks so you have to be sure not to waste any prints &#8211; if I could, I would have the R2400/R2880.</p>
<p style="text-align: justify;">Anyway so you get the idea: good printer, good media, good ink. Or just get your canvas printed by someone else &#8211; I&#8217;ll do it for you if you pay for the ink, media and postage!</p>
<p style="text-align: justify;"><strong>Making the frames</strong><br />
Now you can spend some money and buy the wood, glue, tools etc&#8230; to make your own frames but you can get frames for around £2-3 for A4, maybe less (any good sources please let me know). Take a trip to your local wilkos, poundland etc&#8230; and find some existing box canvas prints (or cheap wooden photo frames). Check the dimensions to make sure your canvas will adequately cover the entire frame, the sides and some of the back for the best results, if you&#8217;re using a roll feed on the printer then the frame can be as long as you want just as long as the canvas can cover the frames width. I took a piece of canvas with me and a tape measure to ensure I got the best frames and odd looks from fellow consumers and store staff.</p>
<p><a title="Pull out the canvas and staples by Lucky Larry, on Flickr" href="http://www.flickr.com/photos/peplop/4411604303/"><img src="http://farm3.static.flickr.com/2426/4411604303_c4b297fbbf_b.jpg" alt="Pull out the canvas and staples" width="630" height="421" /></a></p>
<p style="text-align: justify;">That&#8217;s it! Your frames are built &#8211; just strip off the existing canvas using some needle nose pliers and pull out the staples and you&#8217;ve got your frame ready in far less time and effort as constructing one yourself. Don&#8217;t worry about damaging the old canvas, chances are if you were cheap like me the picture on there was crap anyway.</p>
<p><a title="3 A4 Frames for £9 by Lucky Larry, on Flickr" href="http://www.flickr.com/photos/peplop/4411611369/"><img src="http://farm5.static.flickr.com/4060/4411611369_35698e13a0_b.jpg" alt="3 A4 Frames for £9" width="630" height="421" /></a></p>
<p style="text-align: justify;"><strong>Setting up to print your canvas</strong><br />
Whether or not you&#8217;re printing your canvas these instructions still apply. We need to create a template to help us print, crop and frame the canvas &#8211; please scroll down to the framing section to get an idea.</p>
<p style="text-align: justify;">First measure up the width and height of the frame from edge to edge, now measure how thick  the frame is and finally measure the width of the wood used to make the frame.</p>
<p style="text-align: justify;">For example my frame is 30 cm x 20cm, my frame thickness is 2cm and the width of each piece is 3cm. So my material needs to be at the very most 30cm x 40cm to get the best results. If you want to try and use as much canvas as possible for your print then just ensure that it covers the sides of the frame and around 1cm on the back to give you something to staple into and tension.</p>
<p style="text-align: justify;">My printed area is going to be the area of the frame (30 x 20 cm) plus the sides, so that&#8217;s 34 x 24 cm.</p>
<p style="text-align: justify;">For folding the canvas and getting a nice fit you&#8217;ll need to cut the corners off so make sure to add lines to your template. If you scroll down you&#8217;ll see why/ how this is done.</p>
<p style="text-align: justify;">I used Photoshop CS3 to do my print templates but you should be able to  follow the steps and do this in any basic application that lets you draw a few guides and lines over a photo. I guess if you&#8217;ve got a decent photo printer then you&#8217;re using Photoshop &#8211; CS3 and onwards has a much better print interface.</p>
<p style="text-align: justify;">Create a new document, from the measurements of the frame and make sure its at a minimum of 300 dpi resolution and use RGB colour.</p>
<p style="text-align: justify;">Next show your rulers (CTRL + R) make sure you&#8217;re setup for mm or cm (Edit, menu then Preferences to change).</p>
<p style="text-align: justify;">Drag guides to mark the sides of the frame.</p>
<p style="text-align: justify;">Draw lines for cutting the corners off.</p>
<p style="text-align: justify;">Create a white frame around the outside in a new layer &#8211; to save wasting ink on the material being stapled to the frame.</p>
<p style="text-align: justify;"><a href="http://luckylarry.co.uk/wp-content/uploads/2010/03/box-frame-template.jpg"><img class="aligncenter size-full wp-image-790" title="box-frame-template" src="http://luckylarry.co.uk/wp-content/uploads/2010/03/box-frame-template.jpg" alt="" width="630" height="738" /></a></p>
<p style="text-align: justify;">Now you can put your photo in this document for printing and it will be perfectly positioned for you. This works also if you&#8217;re doing multiple panels. I won&#8217;t go into colour correction here, I&#8217;ll assume that you&#8217;ve done all this.</p>
<p style="text-align: justify;"><strong>Printing&#8230;<br />
</strong>First to save wasting paper do a very small test print to make sure your print heads are aligned and nothing funky is happening in your images.<strong></strong></p>
<p style="text-align: justify;">OK so we&#8217;re ready to print. You&#8217;ll need to first load the canvas roll typically at the back of the printer &#8211; this can be a pain to do as the printer won&#8217;t feed the roll unless its absolutely straight. To remedy this before clipping the canvas roll on the printer feed it first into the printer and press the roll button on your printer. It&#8217;s hit and miss but eventually it will take it, you just need to feed the paper in straight.</p>
<p style="text-align: justify;">Now clip the roll on to the back of the printer and you&#8217;re ready to go. When printing you just need to set a few basic things, the media type (Watercolour paper &#8211; radiant white), to use the roll instead of sheet and to set the paper size to user defined (size of your document).</p>
<p style="text-align: justify;">I always tick photo enhance and best photo options, also using the gloss optimiser. I leave the printer drivers to render the best colour conversion it can, generally few colours in my prints are out of the gamut. To get better results spend time playing with these setting but be prepared to waste some ink.</p>
<p style="text-align: justify;"><a href="http://luckylarry.co.uk/wp-content/uploads/2010/03/box-frame-print-settings.jpg"><img class="aligncenter size-full wp-image-792" title="box-frame-print-settings" src="http://luckylarry.co.uk/wp-content/uploads/2010/03/box-frame-print-settings.jpg" alt="" width="630" height="458" /></a></p>
<p style="text-align: justify;">Click print and thats it. Once you&#8217;re done, press the roll feed button on the printer to feed the canvas out so you can cut it &#8211; the R1900 can attempt to cut the canvas but it&#8217;s  too thick. Once you&#8217;ve cut it (It only needs to be roughly straight) then press the roll feed button again to retract the leftover canvas ready for the next time &#8211; for doing panels I printed all of them and then cut the roll after the last print to save canvas.</p>
<p><a title="3 panels printed by Lucky Larry, on Flickr" href="http://www.flickr.com/photos/peplop/4411614957/"><img src="http://farm3.static.flickr.com/2804/4411614957_7de6a05332_b.jpg" alt="3 panels printed" width="630" height="421" /></a></p>
<p style="text-align: justify;"><strong>Framing your canvas</strong><br />
OK, you&#8217;ll need a staple gun with 6-10mm staples to do this. Its pretty easy to do and takes about 5-10 minutes per frame.</p>
<p><a title="Cut off the corners by Lucky Larry, on Flickr" href="http://www.flickr.com/photos/peplop/4412387186/"><img src="http://farm5.static.flickr.com/4006/4412387186_cb38001a21_b.jpg" alt="Cut off the corners" width="630" height="942" /></a></p>
<p style="text-align: justify;">Remember the corner lines I added in my template first cut these off.</p>
<p><a title="Mark the sides of the frame. by Lucky Larry, on Flickr" href="http://www.flickr.com/photos/peplop/4411622053/"><img src="http://farm5.static.flickr.com/4035/4411622053_4b25334420_b.jpg" alt="Mark the sides of the frame." width="630" height="421" /></a></p>
<p style="text-align: justify;">Now mark and measure in the depth of your frame on each side of your canvas, so on mine, I mark the edge at 2cm and at 22cm for example &#8211; you need these marks to make sure you get your frame in the right place.</p>
<p><a title="Fold the canvas. by Lucky Larry, on Flickr" href="http://www.flickr.com/photos/peplop/4412394276/"><img src="http://farm5.static.flickr.com/4034/4412394276_fdc4cec88d_b.jpg" alt="Fold the canvas." width="630" height="421" /></a></p>
<p style="text-align: justify;">With the canvas face down fold back along the edge of the picture.</p>
<p><a title="Staple the canvas to the frame by Lucky Larry, on Flickr" href="http://www.flickr.com/photos/peplop/4411628125/"><img src="http://farm5.static.flickr.com/4020/4411628125_03b6551b33_b.jpg" alt="Staple the canvas to the frame" width="630" height="421" /></a></p>
<p style="text-align: justify;">You should be able to line up the edges of your canvas with the frame, put in a staple to secure.</p>
<p style="text-align: justify;">Pull the canvas tight, and staple the opposite side.</p>
<p><a title="Fold the top by Lucky Larry, on Flickr" href="http://www.flickr.com/photos/peplop/4412400412/"><img src="http://farm5.static.flickr.com/4059/4412400412_7d5314be13_b.jpg" alt="Fold the top" width="630" height="421" /></a></p>
<p style="text-align: justify;">Tuck the corners in at the top and staple down, repeat at the bottom making sure to pull the canvas tight.</p>
<p><a title="Finished stapling the frame by Lucky Larry, on Flickr" href="http://www.flickr.com/photos/peplop/4412407048/"><img src="http://farm5.static.flickr.com/4012/4412407048_e2d03e8e64_b.jpg" alt="Finished stapling the frame" width="630" height="421" /></a></p>
<p style="text-align: justify;">Finish off by stapling all sides down &#8211; can be as messy as you like, no one will see.</p>
<p style="text-align: justify;">You should be left with a nice end result! <img src='http://luckylarry.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Please feel free to ask if you need a hand or something explained &#8211; or if you want me to print your photos!</p>
<p><a title="First box frame attempt by Lucky Larry, on Flickr" href="http://www.flickr.com/photos/peplop/4410733175/"><img src="http://farm3.static.flickr.com/2743/4410733175_6051b50d21_b.jpg" alt="First box frame attempt" width="630" height="421" /></a></p>
<hr /><small>Copyright &copy; 2009<br /> This feed is for personal, non-commercial use only. <br /> The use of this feed on other websites breaches copyright. If this content is not in your news reader, it makes the page you are viewing an infringement of the copyright. (Digital Fingerprint:<br /> 0f170a4373044c85a96d646f719885c6)</small>

<p>Related posts:<ol><li><a href='http://luckylarry.co.uk/2009/06/mixing-black-and-white-layers-with-colour-in-photoshop/' rel='bookmark' title='Permanent Link: Mixing black and white layers with colour in Photoshop'>Mixing black and white layers with colour in Photoshop</li><li><a href='http://luckylarry.co.uk/2009/06/how-to-photoshop-montage-quickly-and-dirty/' rel='bookmark' title='Permanent Link: How to Photoshop montage quickly and dirty&#8230;'>How to Photoshop montage quickly and dirty&#8230;</li><li><a href='http://luckylarry.co.uk/2009/08/setting-sizes-for-images-in-photoshop-and-any-other-image-editing-software/' rel='bookmark' title='Permanent Link: Setting sizes for images in Photoshop (and any other image editing software)'>Setting sizes for images in Photoshop (and any other image editing software)</li></ol></p>
<p><a href="http://feedads.g.doubleclick.net/~a/GxDSG35cwCkGgbfGPa-Ptfomdso/0/da"><img src="http://feedads.g.doubleclick.net/~a/GxDSG35cwCkGgbfGPa-Ptfomdso/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/GxDSG35cwCkGgbfGPa-Ptfomdso/1/da"><img src="http://feedads.g.doubleclick.net/~a/GxDSG35cwCkGgbfGPa-Ptfomdso/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/LuckyLarry/~4/-5rSTvPeKhI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://luckylarry.co.uk/2010/03/easy-way-to-make-canvas-box-frames/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://luckylarry.co.uk/2010/03/easy-way-to-make-canvas-box-frames/</feedburner:origLink></item>
		<item>
		<title>Removing Crackle from Guitar</title>
		<link>http://feedproxy.google.com/~r/LuckyLarry/~3/ZCJvp1b1cis/</link>
		<comments>http://luckylarry.co.uk/2010/03/removing-crackle-from-guitar/#comments</comments>
		<pubDate>Mon, 01 Mar 2010 00:29:22 +0000</pubDate>
		<dc:creator>larry</dc:creator>
				<category><![CDATA[Electronics]]></category>
		<category><![CDATA[Guitar]]></category>
		<category><![CDATA[Music]]></category>
		<category><![CDATA[Crackle]]></category>
		<category><![CDATA[Fender]]></category>
		<category><![CDATA[Fixing electrics]]></category>
		<category><![CDATA[Jack]]></category>
		<category><![CDATA[Legend]]></category>
		<category><![CDATA[Loose connection]]></category>
		<category><![CDATA[Pot]]></category>
		<category><![CDATA[Potentiometer]]></category>
		<category><![CDATA[Repair]]></category>
		<category><![CDATA[Squire]]></category>
		<category><![CDATA[Static]]></category>
		<category><![CDATA[Strat]]></category>

		<guid isPermaLink="false">http://luckylarry.co.uk/?p=779</guid>
		<description><![CDATA[Got a cheap fender-like guitar I&#8217;ve had a while and it doesn&#8217;t always work, I plug it and then it crackles and cuts out frequently and if I turn the dials it also crackles. A friend wanted to use it so I&#8217;ve got motivated and I&#8217;ve gotten round to fixing it.
These steps apply to most [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;"><strong>Got a cheap fender-like guitar I&#8217;ve had a while and it doesn&#8217;t always work, I plug it and then it crackles and cuts out frequently and if I turn the dials it also crackles. A friend wanted to use it so I&#8217;ve got motivated and I&#8217;ve gotten round to fixing it.</strong></p>
<p style="text-align: justify;">These steps apply to most modern guitars &#8211; if it&#8217;s a vintage you may not want to follow the steps.</p>
<p style="text-align: justify;">It&#8217;s very simple to fix the electrics for the average guitar nothing really that concerning and removing the crackle from the pots/ dials is as easy as just buying some cleaner. It really is that easy.</p>
<p><a title="Testing the jack with a mini amp by Lucky Larry, on Flickr" href="http://www.flickr.com/photos/peplop/4396650294/"><img src="http://farm3.static.flickr.com/2700/4396650294_6d1c195766.jpg" alt="Testing the jack with a mini amp" width="630" height="473" /></a></p>
<p style="text-align: justify;">To test the connections/ circuitry as well as a multimeter I found it really useful to use a mini amp and headphones so I could listen for changes and improvements as I reproduced the fault.</p>
<p style="text-align: justify;">First things first start with the jack and remove this from the guitar to inspect the connections. Should be a couple of screws holding the jack plate in and you&#8217;ll need to remove this and then unscrew the jack from the plate &#8211; there should be a couple of nuts holding it in place.</p>
<p><a title="Faulty jack - half the problem... by Lucky Larry, on Flickr" href="http://www.flickr.com/photos/peplop/4395879183/"><img src="http://farm3.static.flickr.com/2719/4395879183_19bd1c4e69.jpg" alt="Faulty jack - half the problem..." width="630" height="473" /></a></p>
<p style="text-align: justify;">Next have a look for something obvious &#8211; in my case the joint just wasn&#8217;t soldered properly. I cut the wires, stripped the ends, then resoldered the connections after removing the previous solder (or lack of in this case).</p>
<p><a title="Cut wires from jack and strip wire down by Lucky Larry, on Flickr" href="http://www.flickr.com/photos/peplop/4396652188/"><img class="" src="http://farm3.static.flickr.com/2714/4396652188_021f983eb7.jpg" alt="Cut wires from jack and strip wire down" width="630" height="473" /></a></p>
<p><a title="Repaired jack by Lucky Larry, on Flickr" href="http://www.flickr.com/photos/peplop/4395886315/"><img src="http://farm5.static.flickr.com/4024/4395886315_82984cd0c9.jpg" alt="Repaired jack" width="630" height="473" /></a></p>
<p style="text-align: justify;">Moving the jack with the amp and headphones connected, listening now I can see the connection is fixed but turning the pots/ dials I hear the crackling still. The jack is the first place to start for a loose connection but if the problem is not the jack or still persists with an intermittent connection  after you&#8217;ve fixed the jack then you have a loose connection elsewhere. Next obvious place to check is the grounding/ earth wire &#8211; normally attached in the back of the guitar, there is a plate to remove to access this and the truss rod. Basically you&#8217;re looking for a wire that is connected to the guitar itself by way of a plate or something similar.</p>
<p><a title="Check all the connections by Lucky Larry, on Flickr" href="http://www.flickr.com/photos/peplop/4395880951/"><img src="http://farm3.static.flickr.com/2791/4395880951_2fecb6de66.jpg" alt="Check all the connections" width="630" height="473" /></a></p>
<p style="text-align: justify;">If that connection looks fine, next check the connections on each pickup, in cheap guitars these joints can be poorly soldered so check and repair. Lastly check the connections on the switches the wiring isn&#8217;t too tricky to check just be methodical.</p>
<p style="text-align: justify;">Hopefully you&#8217;ve found your loose connection(s) and fixed them, if not you&#8217;ll need to go through each connection with the multimeter. If however you&#8217;re now left with a crackle/ static sound anytime you turn a dial or use the pickup selector switch read on.</p>
<p style="text-align: justify;"><strong>Removing the crackle</strong><br />
So to remove the crackle when turning the dials etc&#8230; Just take the pickguard off, if you haven&#8217;t already, by removing the screws around the outside. You&#8217;ll need some electrical contact cleaner in a spray can with a straw. You need to have a cleaner that is solvent based but also include lubricant since potentiometers and switches should be greased and not left dry as that will make things worse. I found a can down in my local motor store and any decent electronics store should sell it. Again make sure the spray is a lubricant!</p>
<p><a title="Spray contact cleaner into pots and switches by Lucky Larry, on Flickr" href="http://www.flickr.com/photos/peplop/4396657330/"><img src="http://farm3.static.flickr.com/2701/4396657330_435bdbda36.jpg" alt="Spray contact cleaner into pots and switches" width="630" height="473" /></a></p>
<p style="text-align: justify;">On each switch or pot spray the cleaner  between the back of the pickgaurd and the dial. Keep you face away as it&#8217;s likely to spray back a bit and you dont want this in your eyes! You don&#8217;t need much spray just a couple of squirts, when done turn the dials back and forth to work in the cleaner, you should feel an improvement and the dial should feel smoother to turn. Repeat for each pot/ dial. For the pickup selector switch spray into the top of the switch from the front of the pickguard and work the cleaner in by flicking the switch back and forth.</p>
<p><a title="Testing electrics by Lucky Larry, on Flickr" href="http://www.flickr.com/photos/peplop/4395888095/"><img src="http://farm5.static.flickr.com/4048/4395888095_8f4cd2d07c.jpg" alt="Testing electrics" width="630" height="473" /></a></p>
<p style="text-align: justify;">So now plug in the amp and headphones and listen for the crackle &#8211; it should be gone now &#8211; good way to test as put a string on the guitar and play it.</p>
<p style="text-align: justify;">Hopefully that&#8217;s fixed your issues.</p>
<hr /><small>Copyright &copy; 2009<br /> This feed is for personal, non-commercial use only. <br /> The use of this feed on other websites breaches copyright. If this content is not in your news reader, it makes the page you are viewing an infringement of the copyright. (Digital Fingerprint:<br /> 0f170a4373044c85a96d646f719885c6)</small>

<p>No related posts.</p>
<p><a href="http://feedads.g.doubleclick.net/~a/XcTdVORDumF7VNPqG3_oAfmXyk0/0/da"><img src="http://feedads.g.doubleclick.net/~a/XcTdVORDumF7VNPqG3_oAfmXyk0/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/XcTdVORDumF7VNPqG3_oAfmXyk0/1/da"><img src="http://feedads.g.doubleclick.net/~a/XcTdVORDumF7VNPqG3_oAfmXyk0/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/LuckyLarry/~4/ZCJvp1b1cis" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://luckylarry.co.uk/2010/03/removing-crackle-from-guitar/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://luckylarry.co.uk/2010/03/removing-crackle-from-guitar/</feedburner:origLink></item>
		<item>
		<title>Tenacious D: Classico on the Bass Guitar</title>
		<link>http://feedproxy.google.com/~r/LuckyLarry/~3/t3MsPuKKgbY/</link>
		<comments>http://luckylarry.co.uk/2010/02/tenacious-d-classico-on-the-bass-guitar/#comments</comments>
		<pubDate>Sun, 21 Feb 2010 23:07:27 +0000</pubDate>
		<dc:creator>larry</dc:creator>
				<category><![CDATA[Bass Guitar]]></category>
		<category><![CDATA[Music]]></category>
		<category><![CDATA[Bass]]></category>
		<category><![CDATA[Bouree in E Minor (Bach)]]></category>
		<category><![CDATA[Classico]]></category>
		<category><![CDATA[Eine Kleine Nachtmusik (Mozart)]]></category>
		<category><![CDATA[Fur Elise (Beethoven)]]></category>
		<category><![CDATA[Tab]]></category>
		<category><![CDATA[Tablature]]></category>
		<category><![CDATA[Tenacious D]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://luckylarry.co.uk/?p=761</guid>
		<description><![CDATA[Not so sure I&#8217;ve tabbed this 100% but it&#8217;s a start, Tenacious D&#8217;s Classico for the Bass guitar. Video at the bottom showing it being played. 
It&#8217;s essentially parts from Bachs Bouree in E Minor, Beethovens Fur Elise and Mozarts Eine Kleine Nachtmusik. I&#8217;ve translated the notes as best I can on the bass but [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;"><strong>Not so sure I&#8217;ve tabbed this 100% but it&#8217;s a start, Tenacious D&#8217;s Classico for the Bass guitar. Video at the bottom showing it being played. </strong></p>
<p style="text-align: justify;">It&#8217;s essentially parts from Bachs Bouree in E Minor, Beethovens Fur Elise and Mozarts Eine Kleine Nachtmusik. I&#8217;ve translated the notes as best I can on the bass but let me know if I&#8217;ve got it wrong, I&#8217;ve also done this in <a href="http://www.luckylarry.co.uk/downloads/classico-for-bass.ptb">power tab as well here</a>. Click the image below to see it a bit bigger and better quality.</p>
<p style="text-align: justify;"><a href="http://luckylarry.co.uk/wp-content/uploads/2010/02/Classico-on-bass.jpg"><img class="aligncenter size-full wp-image-770" title="Classico-on-bass" src="http://luckylarry.co.uk/wp-content/uploads/2010/02/Classico-on-bass-630x1176-custom.jpg" alt="" width="630" height="1176" /></a></p>
<p style="text-align: justify;">I do apologise for the sound quality in the video below but through decent speakers you can actually hear the bass, shame about the hissing but its a good enough start.</p>
<p style="text-align: justify;"><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="344" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/bcxUyP6JBQ0&amp;hl=en_GB&amp;fs=1&amp;" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="425" height="344" src="http://www.youtube.com/v/bcxUyP6JBQ0&amp;hl=en_GB&amp;fs=1&amp;" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<hr /><small>Copyright &copy; 2009<br /> This feed is for personal, non-commercial use only. <br /> The use of this feed on other websites breaches copyright. If this content is not in your news reader, it makes the page you are viewing an infringement of the copyright. (Digital Fingerprint:<br /> 0f170a4373044c85a96d646f719885c6)</small>

<p>No related posts.</p>
<p><a href="http://feedads.g.doubleclick.net/~a/7DbqcaAtubWRNINm48KoGssEgkE/0/da"><img src="http://feedads.g.doubleclick.net/~a/7DbqcaAtubWRNINm48KoGssEgkE/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/7DbqcaAtubWRNINm48KoGssEgkE/1/da"><img src="http://feedads.g.doubleclick.net/~a/7DbqcaAtubWRNINm48KoGssEgkE/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/LuckyLarry/~4/t3MsPuKKgbY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://luckylarry.co.uk/2010/02/tenacious-d-classico-on-the-bass-guitar/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://luckylarry.co.uk/2010/02/tenacious-d-classico-on-the-bass-guitar/</feedburner:origLink></item>
		<item>
		<title>XS750: The Death Machine Cometh</title>
		<link>http://feedproxy.google.com/~r/LuckyLarry/~3/mOD1LUpJZjU/</link>
		<comments>http://luckylarry.co.uk/2010/02/xs750-the-death-machine-cometh/#comments</comments>
		<pubDate>Sun, 21 Feb 2010 18:51:55 +0000</pubDate>
		<dc:creator>larry</dc:creator>
				<category><![CDATA[Motorbikes]]></category>
		<category><![CDATA[Death Machine]]></category>
		<category><![CDATA[Motorcycle]]></category>
		<category><![CDATA[Triple]]></category>
		<category><![CDATA[XS750]]></category>
		<category><![CDATA[Yamaha]]></category>

		<guid isPermaLink="false">http://luckylarry.co.uk/?p=762</guid>
		<description><![CDATA[Wooo! Well after our work with cleaning the carbs and fixing the 2nd gear we got the bike started and it sounds awesome &#8211; it also seems to be running fine. As well as clean and refurbish the carburetors we fitted new sparkplugs and a new battery, the old plugs being burnt black and the [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;"><strong>Wooo! Well after our work with cleaning the carbs and fixing the 2nd gear we got the bike started and it sounds awesome &#8211; it also seems to be running fine. As well as clean and refurbish the carburetors we fitted new sparkplugs and a new battery, the old plugs being burnt black and the old battery  was 2 amps under the needed capacity for the bike &#8211; that and it was leaking.</strong></p>
<p style="text-align: justify;">It was pretty easy putting the carbs back together and on the bike, most of our day was spent sitting around waiting for the battery to charge and then spending an hour or so trying to get the bike to start &#8211; checking the spark, each chamber, the carbs, the timing plate etc&#8230; and just dogged peserverance with the belief that it would start eventually.</p>
<p style="text-align: justify;">Anyway thought I would share a video on here of its first time running since we got it <img src='http://luckylarry.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  It sounds amazing&#8230; my neighbours will really hate me now.</p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="400" height="320" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="data" value="http://www.flickr.com/apps/video/stewart.swf?v=71377" /><param name="flashvars" value="intl_lang=en-us&amp;photo_secret=7fbdc09c8e&amp;photo_id=4375926817" /><param name="bgcolor" value="#000000" /><param name="allowFullScreen" value="true" /><param name="src" value="http://www.flickr.com/apps/video/stewart.swf?v=71377" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="400" height="320" src="http://www.flickr.com/apps/video/stewart.swf?v=71377" allowfullscreen="true" bgcolor="#000000" flashvars="intl_lang=en-us&amp;photo_secret=7fbdc09c8e&amp;photo_id=4375926817" data="http://www.flickr.com/apps/video/stewart.swf?v=71377"></embed></object></p>
<p>Still needs some work doing to it though:</p>
<p style="padding-left: 30px;">The carbs idle settings need to be adjusted, even after warm the bike will stall with the choke fully in. But its good to see that it&#8217;s not hunting revs. although the fuel/air mix its drawing may also need looking at since the old spark plugs were black.</p>
<p style="padding-left: 30px;">The clutch currently has a mind of its own too so it&#8217;ll either be a new cable or attempting to fix the current one to make it more responsive.</p>
<p style="padding-left: 30px;">Brakes work but the fronts a bit too stiff and the rear is a spongy.</p>
<p style="padding-left: 30px;">Lights currently not working &#8211; could be time for the multimeter I think.</p>
<p style="padding-left: 30px;">Exhaust seals need looking at.</p>
<p>But these are all minor things to fix so hopefully this will get taxed and MoT&#8217;d in the next few weeks. After this we can begin looking at customising the bike and refitting the original front wheel and dual discs, new handle bars and moving the pegs further back.</p>
<hr /><small>Copyright &copy; 2009<br /> This feed is for personal, non-commercial use only. <br /> The use of this feed on other websites breaches copyright. If this content is not in your news reader, it makes the page you are viewing an infringement of the copyright. (Digital Fingerprint:<br /> 0f170a4373044c85a96d646f719885c6)</small>

<p>No related posts.</p>
<p><a href="http://feedads.g.doubleclick.net/~a/v2igoo35ISVhcMY-CQc82NZmqO8/0/da"><img src="http://feedads.g.doubleclick.net/~a/v2igoo35ISVhcMY-CQc82NZmqO8/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/v2igoo35ISVhcMY-CQc82NZmqO8/1/da"><img src="http://feedads.g.doubleclick.net/~a/v2igoo35ISVhcMY-CQc82NZmqO8/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/LuckyLarry/~4/mOD1LUpJZjU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://luckylarry.co.uk/2010/02/xs750-the-death-machine-cometh/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://luckylarry.co.uk/2010/02/xs750-the-death-machine-cometh/</feedburner:origLink></item>
		<item>
		<title>Cleaning and Refurbishing Carburetors (XS750)</title>
		<link>http://feedproxy.google.com/~r/LuckyLarry/~3/2QEWQBYHT6A/</link>
		<comments>http://luckylarry.co.uk/2010/02/cleaning-and-refurbishing-carburetors-xs750/#comments</comments>
		<pubDate>Mon, 15 Feb 2010 00:35:32 +0000</pubDate>
		<dc:creator>larry</dc:creator>
				<category><![CDATA[Motorbikes]]></category>
		<category><![CDATA[Carbs]]></category>
		<category><![CDATA[Carburetors]]></category>
		<category><![CDATA[Cleaning]]></category>
		<category><![CDATA[Motorcycle]]></category>
		<category><![CDATA[Refurbishing]]></category>
		<category><![CDATA[Triple]]></category>
		<category><![CDATA[XS750]]></category>
		<category><![CDATA[Yamaha]]></category>

		<guid isPermaLink="false">http://luckylarry.co.uk/?p=754</guid>
		<description><![CDATA[I guess this works pretty much for all motorcycle carburetors. Take them off and give them a good clean.
The problem with the XS750 is that the previous rider mentioned that when the engine ran it felt a bit lumpy which he suspected the carburetors were causing the issue. Its an old bike and since we [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;"><strong>I guess this works pretty much for all motorcycle carburetors. Take them off and give them a good clean.</strong></p>
<p style="text-align: justify;">The problem with the XS750 is that the previous rider mentioned that when the engine ran it felt a bit lumpy which he suspected the carburetors were causing the issue. Its an old bike and since we were having issues starting the bike it seemed logical that we&#8217;d need to check the carbs anyway whilst we waited for parts to arrive.</p>
<p style="text-align: justify;"><strong>Removing the carbs</strong><br />
First things first &#8211; test to see if the petcocks are working, the bike draws in fuel through the carburetors by using a vacuum. So if we remove the fuel feed hoses that run to the back of the carbs, there are two of them split between the three carbs, we should be able to turn the petcocks to on/fuel and nothing should drip out &#8211; turn the petcocks to prime or reserve and it should start draining the fuel from the tank. To get to the hoses you may need to remove the air filters first -held on with jubilee clips.</p>
<p><a title="Petcocks are working, no leakage by Lucky Larry, on Flickr" href="http://www.flickr.com/photos/peplop/4357944580/"><img src="http://farm5.static.flickr.com/4005/4357944580_2f621a955e_b.jpg" alt="Petcocks are working, no leakage" width="630" height="421" /></a></p>
<p style="text-align: justify;">The bonus is we now know that the fuel lines and taps are working as they should. The carburetors on the XS750 are sealed on using jubilee clips, loosen these and you should be able to wiggle the carbs free of the engine block &#8211; it will take a bit of effort and a long screwdriver to get to the central carb.</p>
<p><a title="Awkward middle carb jubliee clips by Lucky Larry, on Flickr" href="http://www.flickr.com/photos/peplop/4357940564/"><img src="http://farm5.static.flickr.com/4056/4357940564_f15e15be6d_b.jpg" alt="Awkward middle carb jubliee clips" width="630" height="421" /></a></p>
<p style="text-align: justify;">So we&#8217;ve removed the carbs, have a  bucket on standby to empty the majority of the fuel out into &#8211; may take a while to get the most out. We can also remove any remaining air filters &#8211; you may want to change them, ours look fairly new so no need. Now we can work on the carbs separately and in the warmth of indoors &#8211; just use a container to in case of further spillages.</p>
<p><a title="Just give 'em a tug. by Lucky Larry, on Flickr" href="http://www.flickr.com/photos/peplop/4357200203/"><img src="http://farm3.static.flickr.com/2703/4357200203_b505cd356e_b.jpg" alt="Just give 'em a tug." width="630" height="943" /></a></p>
<p style="text-align: justify;"><strong>Stripping the carbs down</strong><br />
We looking for issues such as build of petrol deposits &#8211; petrol can cause a varnish to appear on the inside of the carbs and can also create what can only be described as gunk. We&#8217;re also looking for any signs of wear on the needles, seals and float chambers along with any of the diaphragms perishing.</p>
<p><a title="Pesky bolts! by Lucky Larry, on Flickr" href="http://www.flickr.com/photos/peplop/4357208799/"><img src="http://farm5.static.flickr.com/4048/4357208799_f733b01c05_b.jpg" alt="Pesky bolts!" width="630" height="943" /></a></p>
<p style="text-align: justify;">First thing we noticed the bolts on the top of the carbs were very worn and rusted &#8211; so we&#8217;ll end up getting a new set of bolts. With our favourite tool, the mallet, we hammered in a screwdriver to get a better purchase on the bolt head and between two of us we forced each bolt out. Otherwise we would have probably had to drill the bolts out.</p>
<p><a title="Tops off showing diaphragms by Lucky Larry, on Flickr" href="http://www.flickr.com/photos/peplop/4357959608/"><img src="http://farm3.static.flickr.com/2680/4357959608_0da08508e2_b.jpg" alt="Tops off showing diaphragms" width="630" height="421" /></a></p>
<p style="text-align: justify;">Inspecting inside the tops showed no immediate problems, everything looked fine here and looking through the carbs showed that they were very clean. So we proceeded to remove the base of each carb and inspect the float chamber.</p>
<p><a title="Removing the float hinge pins by Lucky Larry, on Flickr" href="http://www.flickr.com/photos/peplop/4357219851/"><img src="http://farm3.static.flickr.com/2781/4357219851_a10b72ae28_b.jpg" alt="Removing the float hinge pins" width="630" height="421" /></a></p>
<p style="text-align: justify;">In here we could see the gasket seals had perished and after removing the float chambers &#8211; using a nail and a hammer to aid removing the hinge pin, we could see each float value and filter was very blocked, inspecting further into each fuel line we found dark heavy slimey deposits. With the carbs otherwise looking clean and in good condition considering the age, I think we found our problem.</p>
<p><a title="Removing the float bowl gasket seal by Lucky Larry, on Flickr" href="http://www.flickr.com/photos/peplop/4357970118/"><img src="http://farm5.static.flickr.com/4040/4357970118_8955033710_b.jpg" alt="Removing the float bowl gasket seal" width="630" height="421" /></a></p>
<p style="text-align: justify;">Solution &#8211; get some carb cleaner (Redux etc&#8230;) and soak through the fuel lines that run in to the float chambers via the float needle. We&#8217;ve left this for a few days to soak through and also soaking the gause filters for each float chamber will also be a good idea.</p>
<p><a title="Getting some of the gunk out by Lucky Larry, on Flickr" href="http://www.flickr.com/photos/peplop/4357226175/"><img src="http://farm5.static.flickr.com/4040/4357226175_48c18a1f3f_b.jpg" alt="Getting some of the gunk out" width="630" height="421" /></a></p>
<p style="text-align: justify;"><strong>Refurbishing the carbs</strong><br />
We&#8217;ve got a refurb kit for each carb which is a new needle, float chamber gasket and 10mm threaded bolt/seat for each float needle &#8211; nothing else seems to be needed so when the carbs are done soaking, we&#8217;ve cleaned them and once we&#8217;ve got the replacement bolts we&#8217;ll fit the new parts.</p>
<p><a href="http://luckylarry.co.uk/wp-content/uploads/2010/02/carb-refurb-kit.jpg"><img class="aligncenter size-full wp-image-758" title="carb-refurb-kit" src="http://luckylarry.co.uk/wp-content/uploads/2010/02/carb-refurb-kit.jpg" alt="" width="150" height="100" /></a></p>
<p>I was going to follow up with a separate post but it was pretty simple to refurb the carbs. Just follow whats already there and make sure that they&#8217;re cleaned.</p>
<hr /><small>Copyright &copy; 2009<br /> This feed is for personal, non-commercial use only. <br /> The use of this feed on other websites breaches copyright. If this content is not in your news reader, it makes the page you are viewing an infringement of the copyright. (Digital Fingerprint:<br /> 0f170a4373044c85a96d646f719885c6)</small>

<p>No related posts.</p>
<p><a href="http://feedads.g.doubleclick.net/~a/xGNq-EXFLIheXMfg3AJbHqVOWgM/0/da"><img src="http://feedads.g.doubleclick.net/~a/xGNq-EXFLIheXMfg3AJbHqVOWgM/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/xGNq-EXFLIheXMfg3AJbHqVOWgM/1/da"><img src="http://feedads.g.doubleclick.net/~a/xGNq-EXFLIheXMfg3AJbHqVOWgM/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/LuckyLarry/~4/2QEWQBYHT6A" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://luckylarry.co.uk/2010/02/cleaning-and-refurbishing-carburetors-xs750/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://luckylarry.co.uk/2010/02/cleaning-and-refurbishing-carburetors-xs750/</feedburner:origLink></item>
		<item>
		<title>Arduino: Controlling the Robot Arm</title>
		<link>http://feedproxy.google.com/~r/LuckyLarry/~3/QvxFXoowYKw/</link>
		<comments>http://luckylarry.co.uk/2010/02/arduino-modifying-a-robot-arm-part-2/#comments</comments>
		<pubDate>Wed, 10 Feb 2010 00:09:20 +0000</pubDate>
		<dc:creator>larry</dc:creator>
				<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Arduino C/C++]]></category>
		<category><![CDATA[Electronics]]></category>
		<category><![CDATA[Processing]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Robots]]></category>
		<category><![CDATA[Control a DC motor]]></category>
		<category><![CDATA[Edge Robotic Arm Kit]]></category>
		<category><![CDATA[H-Bridge]]></category>
		<category><![CDATA[Hacking]]></category>
		<category><![CDATA[keyPressed]]></category>
		<category><![CDATA[L293D]]></category>
		<category><![CDATA[Modifying]]></category>
		<category><![CDATA[motors]]></category>
		<category><![CDATA[mousePressed]]></category>
		<category><![CDATA[Robot Arm]]></category>
		<category><![CDATA[Serial port]]></category>
		<category><![CDATA[Setting values via Processing]]></category>
		<category><![CDATA[SN754410]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[User Interface]]></category>

		<guid isPermaLink="false">http://luckylarry.co.uk/?p=744</guid>
		<description><![CDATA[So the arm is wired into Arduino as per the previous post, Arduino: Modifying a Robot Arm and hopefully this has worked. In this next part I alter the Arduino sketch slightly and write the first Processing sketch to test control of the arm &#8211; video at the bottom.
To control the robot arm we&#8217;ll be [...]


Related posts:<ol><li><a href='http://luckylarry.co.uk/2010/01/arduino-modifying-a-robot-arm/' rel='bookmark' title='Permanent Link: Arduino: Modifying a Robot Arm'>Arduino: Modifying a Robot Arm</li><li><a href='http://luckylarry.co.uk/2009/08/obstacle-avoidance-robot-build-your-own-larrybot/' rel='bookmark' title='Permanent Link: Obstacle avoidance robot &#8211; build your own larryBot'>Obstacle avoidance robot &#8211; build your own larryBot</li><li><a href='http://luckylarry.co.uk/2009/12/using-processing-to-send-values-to-arduino/' rel='bookmark' title='Permanent Link: Using Processing to Send Values to Arduino'>Using Processing to Send Values to Arduino</li></ol>]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;"><strong>So the arm is wired into Arduino as per the previous post, <a href="http://luckylarry.co.uk/2010/01/arduino-modifying-a-robot-arm/">Arduino: Modifying a Robot Arm</a> and hopefully this has worked. In this next part I alter the Arduino sketch slightly and write the first Processing sketch to test control of the arm &#8211; video at the bottom.</strong></p>
<p style="text-align: justify;">To control the robot arm we&#8217;ll be sending a byte value over the serial port and then reading that in the Arduino code. Depending upon the value sent different motors will be activated.</p>
<p style="text-align: justify;">For the processing sketch I&#8217;ve made a few buttons for each motor and also coded the use of the keyboard for another control method. Using either arbitrarily moves the arms motors.</p>
<p style="text-align: justify;">This sketch is the basis for all the further work as well as testing the arm, from this I will move to inverse kinematics as well as programming repeat actions for the arm to perform. Ultimately leading to the arm responding to sensors and other stimuli &#8211; eventually! (I have a lot to write up).</p>
<p style="text-align: justify;">For a basic example of working with controlling Arduino using Processing please read my tutorial &#8220;<a href="http://luckylarry.co.uk/2009/12/using-processing-to-send-values-to-arduino/">Using Processing to Send Values to Arduino</a>&#8221; which explains about sending data over the serial port.</p>
<p style="text-align: justify;"><strong>The Arduino Sketch</strong><br />
Nothing much has changed from the sketch in the previous post, the main difference is that now you can see we&#8217;re reading values from the serial port and acting accordingly. All the logic happens in the Processing code.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">/* controls each motor in an Edge Robotic Arm using data sent from 
    a Processing Sketch
    luckylarry.co.uk
&nbsp;
*/</span>
<span style="color: #666666; font-style: italic;">// set the output pins</span>
<span style="color: #666666; font-style: italic;">// 14-18 are actually analog pins 0-4</span>
<span style="color: #000066; font-weight: bold;">int</span> baseMotorEnablePin <span style="color: #339933;">=</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">int</span> baseMotorPin1 <span style="color: #339933;">=</span> <span style="color: #cc66cc;">3</span><span style="color: #339933;">;</span>                             
<span style="color: #000066; font-weight: bold;">int</span> baseMotorPin2 <span style="color: #339933;">=</span> <span style="color: #cc66cc;">4</span><span style="color: #339933;">;</span>                           
<span style="color: #000066; font-weight: bold;">int</span> shoulderMotorEnablePin <span style="color: #339933;">=</span> <span style="color: #cc66cc;">14</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">int</span> shoulderMotorPin1 <span style="color: #339933;">=</span> <span style="color: #cc66cc;">15</span><span style="color: #339933;">;</span>                             
<span style="color: #000066; font-weight: bold;">int</span> shoulderMotorPin2 <span style="color: #339933;">=</span> <span style="color: #cc66cc;">16</span><span style="color: #339933;">;</span> 
<span style="color: #000066; font-weight: bold;">int</span> elbowMotorEnablePin <span style="color: #339933;">=</span> <span style="color: #cc66cc;">8</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">int</span> elbowMotorPin1 <span style="color: #339933;">=</span> <span style="color: #cc66cc;">9</span><span style="color: #339933;">;</span>                             
<span style="color: #000066; font-weight: bold;">int</span> elbowMotorPin2 <span style="color: #339933;">=</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">;</span>                           
<span style="color: #000066; font-weight: bold;">int</span> wristMotorEnablePin <span style="color: #339933;">=</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">int</span> wristMotorPin1 <span style="color: #339933;">=</span> <span style="color: #cc66cc;">6</span><span style="color: #339933;">;</span>                             
<span style="color: #000066; font-weight: bold;">int</span> wristMotorPin2 <span style="color: #339933;">=</span> <span style="color: #cc66cc;">7</span><span style="color: #339933;">;</span> 
<span style="color: #000066; font-weight: bold;">int</span> handMotorEnablePin <span style="color: #339933;">=</span> <span style="color: #cc66cc;">11</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">int</span> handMotorPin1 <span style="color: #339933;">=</span> <span style="color: #cc66cc;">17</span><span style="color: #339933;">;</span>                             
<span style="color: #000066; font-weight: bold;">int</span> handMotorPin2 <span style="color: #339933;">=</span> <span style="color: #cc66cc;">18</span><span style="color: #339933;">;</span> 
<span style="color: #666666; font-style: italic;">// set a variable to store the byte sent from the serial port</span>
<span style="color: #000066; font-weight: bold;">int</span> incomingByte<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">void</span> setup<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;">// set the SN754410 pins as outputs:</span>
  pinMode<span style="color: #009900;">&#40;</span>baseMotorPin1, OUTPUT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  pinMode<span style="color: #009900;">&#40;</span>baseMotorPin2, OUTPUT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  pinMode<span style="color: #009900;">&#40;</span>baseMotorEnablePin, OUTPUT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  digitalWrite<span style="color: #009900;">&#40;</span>baseMotorEnablePin, HIGH<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  pinMode<span style="color: #009900;">&#40;</span>shoulderMotorPin1, OUTPUT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  pinMode<span style="color: #009900;">&#40;</span>shoulderMotorPin2, OUTPUT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  pinMode<span style="color: #009900;">&#40;</span>shoulderMotorEnablePin, OUTPUT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  digitalWrite<span style="color: #009900;">&#40;</span>shoulderMotorEnablePin, HIGH<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  pinMode<span style="color: #009900;">&#40;</span>elbowMotorPin1, OUTPUT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  pinMode<span style="color: #009900;">&#40;</span>elbowMotorPin2, OUTPUT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  pinMode<span style="color: #009900;">&#40;</span>elbowMotorEnablePin, OUTPUT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  digitalWrite<span style="color: #009900;">&#40;</span>elbowMotorEnablePin, HIGH<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  pinMode<span style="color: #009900;">&#40;</span>wristMotorPin1, OUTPUT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  pinMode<span style="color: #009900;">&#40;</span>wristMotorPin2, OUTPUT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  pinMode<span style="color: #009900;">&#40;</span>wristMotorEnablePin, OUTPUT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  digitalWrite<span style="color: #009900;">&#40;</span>wristMotorEnablePin, HIGH<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  pinMode<span style="color: #009900;">&#40;</span>handMotorPin1, OUTPUT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  pinMode<span style="color: #009900;">&#40;</span>handMotorPin2, OUTPUT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  pinMode<span style="color: #009900;">&#40;</span>handMotorEnablePin, OUTPUT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  digitalWrite<span style="color: #009900;">&#40;</span>handMotorEnablePin, HIGH<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #666666; font-style: italic;">// start sending data at 9600 baud rate</span>
  Serial.<span style="color: #006633;">begin</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">9600</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">void</span> loop<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;">// check that there's something in the serial buffer</span>
  <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>Serial.<span style="color: #006633;">available</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// read the byte and store it in our variable </span>
    <span style="color: #666666; font-style: italic;">// the byte sent is actually an ascii value</span>
    incomingByte <span style="color: #339933;">=</span> Serial.<span style="color: #006633;">read</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// note the upper casing of each letter!</span>
    <span style="color: #666666; font-style: italic;">// each letter turns a motor different way.</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>incomingByte <span style="color: #339933;">==</span> <span style="color: #0000ff;">'Q'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    digitalWrite<span style="color: #009900;">&#40;</span>baseMotorPin1, LOW<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>   
    digitalWrite<span style="color: #009900;">&#40;</span>baseMotorPin2, HIGH<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  
    <span style="color: #009900;">&#125;</span> 
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>incomingByte <span style="color: #339933;">==</span> <span style="color: #0000ff;">'W'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    digitalWrite<span style="color: #009900;">&#40;</span>baseMotorPin1, HIGH<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>   
    digitalWrite<span style="color: #009900;">&#40;</span>baseMotorPin2, LOW<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>incomingByte <span style="color: #339933;">==</span> <span style="color: #0000ff;">'E'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    digitalWrite<span style="color: #009900;">&#40;</span>shoulderMotorPin1, LOW<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>   
    digitalWrite<span style="color: #009900;">&#40;</span>shoulderMotorPin2, HIGH<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  
    <span style="color: #009900;">&#125;</span> 
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>incomingByte <span style="color: #339933;">==</span> <span style="color: #0000ff;">'R'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    digitalWrite<span style="color: #009900;">&#40;</span>shoulderMotorPin1, HIGH<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>   
    digitalWrite<span style="color: #009900;">&#40;</span>shoulderMotorPin2, LOW<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>incomingByte <span style="color: #339933;">==</span> <span style="color: #0000ff;">'A'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    digitalWrite<span style="color: #009900;">&#40;</span>elbowMotorPin1, LOW<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>   
    digitalWrite<span style="color: #009900;">&#40;</span>elbowMotorPin2, HIGH<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  
    <span style="color: #009900;">&#125;</span> 
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>incomingByte <span style="color: #339933;">==</span> <span style="color: #0000ff;">'S'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    digitalWrite<span style="color: #009900;">&#40;</span>elbowMotorPin1, HIGH<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>   
    digitalWrite<span style="color: #009900;">&#40;</span>elbowMotorPin2, LOW<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>incomingByte <span style="color: #339933;">==</span> <span style="color: #0000ff;">'D'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    digitalWrite<span style="color: #009900;">&#40;</span>wristMotorPin1, LOW<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>   
    digitalWrite<span style="color: #009900;">&#40;</span>wristMotorPin2, HIGH<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  
    <span style="color: #009900;">&#125;</span> 
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>incomingByte <span style="color: #339933;">==</span> <span style="color: #0000ff;">'F'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    digitalWrite<span style="color: #009900;">&#40;</span>wristMotorPin1, HIGH<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>   
    digitalWrite<span style="color: #009900;">&#40;</span>wristMotorPin2, LOW<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>incomingByte <span style="color: #339933;">==</span> <span style="color: #0000ff;">'Z'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    digitalWrite<span style="color: #009900;">&#40;</span>handMotorPin1, LOW<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>   
    digitalWrite<span style="color: #009900;">&#40;</span>handMotorPin2, HIGH<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  
    <span style="color: #009900;">&#125;</span> 
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>incomingByte <span style="color: #339933;">==</span> <span style="color: #0000ff;">'X'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    digitalWrite<span style="color: #009900;">&#40;</span>handMotorPin1, HIGH<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>   
    digitalWrite<span style="color: #009900;">&#40;</span>handMotorPin2, LOW<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  
    <span style="color: #009900;">&#125;</span>
    <span style="color: #666666; font-style: italic;">// if a O is sent make sure the motors are turned off</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>incomingByte <span style="color: #339933;">==</span> <span style="color: #0000ff;">'O'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    digitalWrite<span style="color: #009900;">&#40;</span>baseMotorPin1, LOW<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>   
    digitalWrite<span style="color: #009900;">&#40;</span>baseMotorPin2, LOW<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  
    digitalWrite<span style="color: #009900;">&#40;</span>shoulderMotorPin1, LOW<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>   
    digitalWrite<span style="color: #009900;">&#40;</span>shoulderMotorPin2, LOW<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
    digitalWrite<span style="color: #009900;">&#40;</span>elbowMotorPin1, LOW<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>   
    digitalWrite<span style="color: #009900;">&#40;</span>elbowMotorPin2, LOW<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  
    digitalWrite<span style="color: #009900;">&#40;</span>wristMotorPin1, LOW<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>   
    digitalWrite<span style="color: #009900;">&#40;</span>wristMotorPin2, LOW<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
    digitalWrite<span style="color: #009900;">&#40;</span>handMotorPin1, LOW<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>   
    digitalWrite<span style="color: #009900;">&#40;</span>handMotorPin2, LOW<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p style="text-align: justify;"><strong>The Processing Sketch</strong><br />
I&#8217;ve drawn some fancy arrows for my buttons in this sketch but otherwise the code is pretty simple &#8211; if I press Q or q on the keyboard or if I press an arrow button then send the ascii value of Q (note the uppercase) over the serial port for the Arduino to pick up and turn the motor on. There is nothing here really complicated just a fair few lines of code for the user interface.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">/* 
   Processing sketch that send a ascii byte character to Arduino which
   then subsquentally controls a motor
   luckylarry.co.uk
&nbsp;
*/</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// load the serial library for Processing</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">processing.serial.*</span><span style="color: #339933;">;</span> 
<span style="color: #666666; font-style: italic;">// instance of the serial class</span>
Serial port<span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// values to store X, Y for each button</span>
<span style="color: #000066; font-weight: bold;">int</span> M1LX, M1RX, M2LX, M2RX, M3LX, M3RX, M4LX, M4RX, M5LX, M5RX<span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">int</span> M1LY, M1RY, M2LY, M2RY, M3LY, M3RY, M4LY, M4RY, M5LY, M5RY<span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// stores the width/height of the box</span>
<span style="color: #000066; font-weight: bold;">int</span> boxSize <span style="color: #339933;">=</span> <span style="color: #cc66cc;">64</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// 2 new instances of my arrow class</span>
<span style="color: #666666; font-style: italic;">// also set an array of coordinates for each arrow</span>
arrow myRightArrow<span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span>rightArrowxpoints<span style="color: #339933;">=</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">30</span>,<span style="color: #cc66cc;">54</span>,<span style="color: #cc66cc;">30</span>,<span style="color: #cc66cc;">30</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">30</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span> 
<span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span>rightArrowypoints<span style="color: #339933;">=</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">27</span>,<span style="color: #cc66cc;">54</span>,<span style="color: #cc66cc;">40</span>,<span style="color: #cc66cc;">40</span>,<span style="color: #cc66cc;">15</span>,<span style="color: #cc66cc;">15</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
arrow myLeftArrow<span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span>leftArrowxpoints<span style="color: #339933;">=</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">24</span>,<span style="color: #cc66cc;">24</span>,<span style="color: #cc66cc;">54</span>,<span style="color: #cc66cc;">54</span>,<span style="color: #cc66cc;">24</span>,<span style="color: #cc66cc;">24</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span> 
<span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span>leftArrowypoints<span style="color: #339933;">=</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">27</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">15</span>,<span style="color: #cc66cc;">15</span>,<span style="color: #cc66cc;">40</span>,<span style="color: #cc66cc;">40</span>,<span style="color: #cc66cc;">54</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// set the font</span>
PFont myFont<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">void</span> setup<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>  <span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;">// screen size of the program</span>
  size<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">145</span>, <span style="color: #cc66cc;">455</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #666666; font-style: italic;">// set the coordinates of each button box</span>
  <span style="color: #666666; font-style: italic;">// base motor M1LX = Motor 1 Left X  etc..</span>
  M1LX <span style="color: #339933;">=</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span>
  M1LY <span style="color: #339933;">=</span> <span style="color: #cc66cc;">25</span><span style="color: #339933;">;</span>
  M1RX <span style="color: #339933;">=</span> <span style="color: #cc66cc;">75</span><span style="color: #339933;">;</span>
  M1RY <span style="color: #339933;">=</span> <span style="color: #cc66cc;">25</span><span style="color: #339933;">;</span>  
  <span style="color: #666666; font-style: italic;">// shoulder motor</span>
  M2LX <span style="color: #339933;">=</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span>
  M2LY <span style="color: #339933;">=</span> <span style="color: #cc66cc;">115</span><span style="color: #339933;">;</span>
  M2RX <span style="color: #339933;">=</span> <span style="color: #cc66cc;">75</span><span style="color: #339933;">;</span>
  M2RY <span style="color: #339933;">=</span> <span style="color: #cc66cc;">115</span><span style="color: #339933;">;</span>
  <span style="color: #666666; font-style: italic;">// elbow motor</span>
  M3LX <span style="color: #339933;">=</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span>
  M3LY <span style="color: #339933;">=</span> <span style="color: #cc66cc;">205</span><span style="color: #339933;">;</span>
  M3RX <span style="color: #339933;">=</span> <span style="color: #cc66cc;">75</span><span style="color: #339933;">;</span>
  M3RY <span style="color: #339933;">=</span> <span style="color: #cc66cc;">205</span><span style="color: #339933;">;</span>
  <span style="color: #666666; font-style: italic;">// wrist motor</span>
  M4LX <span style="color: #339933;">=</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span>
  M4LY <span style="color: #339933;">=</span> <span style="color: #cc66cc;">295</span><span style="color: #339933;">;</span>
  M4RX <span style="color: #339933;">=</span> <span style="color: #cc66cc;">75</span><span style="color: #339933;">;</span>
  M4RY <span style="color: #339933;">=</span> <span style="color: #cc66cc;">295</span><span style="color: #339933;">;</span>
  <span style="color: #666666; font-style: italic;">// hand motor</span>
  M5LX <span style="color: #339933;">=</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span>
  M5LY <span style="color: #339933;">=</span> <span style="color: #cc66cc;">385</span><span style="color: #339933;">;</span>
  M5RX <span style="color: #339933;">=</span> <span style="color: #cc66cc;">75</span><span style="color: #339933;">;</span>
  M5RY <span style="color: #339933;">=</span> <span style="color: #cc66cc;">385</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// List all the available serial ports in the output pane. </span>
  <span style="color: #666666; font-style: italic;">// You will need to choose the port that the Arduino board is </span>
  <span style="color: #666666; font-style: italic;">// connected to from this list. The first port in the list is </span>
  <span style="color: #666666; font-style: italic;">// port #0 and the third port in the list is port #2. </span>
  println<span style="color: #009900;">&#40;</span>Serial.<span style="color: #006633;">list</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
  <span style="color: #666666; font-style: italic;">// set the font to use</span>
  myFont <span style="color: #339933;">=</span> createFont<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;verdana&quot;</span>, <span style="color: #cc66cc;">12</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  textFont<span style="color: #009900;">&#40;</span>myFont<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #666666; font-style: italic;">// Open the port that the Arduino board is connected to (in this case #0) </span>
  <span style="color: #666666; font-style: italic;">// Make sure to open the port at the same speed Arduino is using (9600bps)</span>
  port <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Serial<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>, Serial.<span style="color: #006633;">list</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span>, <span style="color: #cc66cc;">9600</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
  <span style="color: #666666; font-style: italic;">// create the base arrow</span>
  myRightArrow <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> arrow<span style="color: #009900;">&#40;</span>rightArrowxpoints,rightArrowypoints,<span style="color: #cc66cc;">7</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  myLeftArrow <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> arrow<span style="color: #009900;">&#40;</span>leftArrowxpoints,leftArrowypoints,<span style="color: #cc66cc;">7</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">void</span> draw<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> 
<span style="color: #009900;">&#123;</span> 
  background<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  noStroke<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  fill<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">150</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #666666; font-style: italic;">// draw each box/ button with a label above each    </span>
  text<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Base Motor (Q/W)&quot;</span>, <span style="color: #cc66cc;">5</span>, <span style="color: #cc66cc;">5</span>, <span style="color: #cc66cc;">200</span>, <span style="color: #cc66cc;">75</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
  text<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Shoulder Motor (E/R)&quot;</span>, <span style="color: #cc66cc;">5</span>, <span style="color: #cc66cc;">95</span>, <span style="color: #cc66cc;">200</span>, <span style="color: #cc66cc;">75</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  text<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Elbow Motor (A/S)&quot;</span>, <span style="color: #cc66cc;">5</span>, <span style="color: #cc66cc;">185</span>, <span style="color: #cc66cc;">200</span>, <span style="color: #cc66cc;">75</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  text<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Wrist Motor (D/F)&quot;</span>, <span style="color: #cc66cc;">5</span>, <span style="color: #cc66cc;">275</span>, <span style="color: #cc66cc;">200</span>, <span style="color: #cc66cc;">75</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>     
  text<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Hand Motor (Z/X)&quot;</span>, <span style="color: #cc66cc;">5</span>, <span style="color: #cc66cc;">365</span>, <span style="color: #cc66cc;">200</span>, <span style="color: #cc66cc;">75</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// start looking to see whats pressed and send a value</span>
  <span style="color: #666666; font-style: italic;">// over the serial port</span>
  <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>keyPressed<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>key <span style="color: #339933;">==</span> <span style="color: #0000ff;">'q'</span> <span style="color: #339933;">||</span> key <span style="color: #339933;">==</span> <span style="color: #0000ff;">'Q'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      port.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Q'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>key <span style="color: #339933;">==</span> <span style="color: #0000ff;">'w'</span> <span style="color: #339933;">||</span> key <span style="color: #339933;">==</span> <span style="color: #0000ff;">'W'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      port.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'W'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>key <span style="color: #339933;">==</span> <span style="color: #0000ff;">'e'</span> <span style="color: #339933;">||</span> key <span style="color: #339933;">==</span> <span style="color: #0000ff;">'E'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      port.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'E'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>key <span style="color: #339933;">==</span> <span style="color: #0000ff;">'r'</span> <span style="color: #339933;">||</span> key <span style="color: #339933;">==</span> <span style="color: #0000ff;">'R'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      port.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'R'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>key <span style="color: #339933;">==</span> <span style="color: #0000ff;">'a'</span> <span style="color: #339933;">||</span> key <span style="color: #339933;">==</span> <span style="color: #0000ff;">'A'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      port.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'A'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>key <span style="color: #339933;">==</span> <span style="color: #0000ff;">'s'</span> <span style="color: #339933;">||</span> key <span style="color: #339933;">==</span> <span style="color: #0000ff;">'S'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      port.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'S'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>key <span style="color: #339933;">==</span> <span style="color: #0000ff;">'d'</span> <span style="color: #339933;">||</span> key <span style="color: #339933;">==</span> <span style="color: #0000ff;">'D'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      port.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'D'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>key <span style="color: #339933;">==</span> <span style="color: #0000ff;">'f'</span> <span style="color: #339933;">||</span> key <span style="color: #339933;">==</span> <span style="color: #0000ff;">'F'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      port.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'F'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>key <span style="color: #339933;">==</span> <span style="color: #0000ff;">'z'</span> <span style="color: #339933;">||</span> key <span style="color: #339933;">==</span> <span style="color: #0000ff;">'Z'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      port.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Z'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>key <span style="color: #339933;">==</span> <span style="color: #0000ff;">'x'</span> <span style="color: #339933;">||</span> key <span style="color: #339933;">==</span> <span style="color: #0000ff;">'X'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      port.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'X'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span> 
  <span style="color: #666666; font-style: italic;">// if no key is pressed check to see if the mouse button is pressed</span>
  <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>mousePressed <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// check to see if the mouse is inside each box/ button if so send the value</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>mouseX <span style="color: #339933;">&gt;</span> M1LX<span style="color: #339933;">-</span>boxSize <span style="color: #339933;">&amp;&amp;</span> mouseX <span style="color: #339933;">&lt;</span> M1LX<span style="color: #339933;">+</span>boxSize <span style="color: #339933;">&amp;&amp;</span> 
      mouseY <span style="color: #339933;">&gt;</span> M1LY<span style="color: #339933;">-</span>boxSize <span style="color: #339933;">&amp;&amp;</span> mouseY <span style="color: #339933;">&lt;</span> M1LY<span style="color: #339933;">+</span>boxSize<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        port.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Q'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
    <span style="color: #009900;">&#125;</span> 
    <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>mouseX <span style="color: #339933;">&gt;</span> M1RX<span style="color: #339933;">-</span>boxSize <span style="color: #339933;">&amp;&amp;</span> mouseX <span style="color: #339933;">&lt;</span> M1RX<span style="color: #339933;">+</span>boxSize <span style="color: #339933;">&amp;&amp;</span> 
      mouseY <span style="color: #339933;">&gt;</span> M1RY<span style="color: #339933;">-</span>boxSize <span style="color: #339933;">&amp;&amp;</span> mouseY <span style="color: #339933;">&lt;</span> M1RY<span style="color: #339933;">+</span>boxSize<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        port.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'W'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
    <span style="color: #009900;">&#125;</span> 
    <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>mouseX <span style="color: #339933;">&gt;</span> M2LX<span style="color: #339933;">-</span>boxSize <span style="color: #339933;">&amp;&amp;</span> mouseX <span style="color: #339933;">&lt;</span> M2LX<span style="color: #339933;">+</span>boxSize <span style="color: #339933;">&amp;&amp;</span> 
      mouseY <span style="color: #339933;">&gt;</span> M2LY<span style="color: #339933;">-</span>boxSize <span style="color: #339933;">&amp;&amp;</span> mouseY <span style="color: #339933;">&lt;</span> M2LY<span style="color: #339933;">+</span>boxSize<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        port.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'E'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
    <span style="color: #009900;">&#125;</span> 
    <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>mouseX <span style="color: #339933;">&gt;</span> M2RX<span style="color: #339933;">-</span>boxSize <span style="color: #339933;">&amp;&amp;</span> mouseX <span style="color: #339933;">&lt;</span> M2RX<span style="color: #339933;">+</span>boxSize <span style="color: #339933;">&amp;&amp;</span> 
      mouseY <span style="color: #339933;">&gt;</span> M2RY<span style="color: #339933;">-</span>boxSize <span style="color: #339933;">&amp;&amp;</span> mouseY <span style="color: #339933;">&lt;</span> M2RY<span style="color: #339933;">+</span>boxSize<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        port.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'R'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
    <span style="color: #009900;">&#125;</span> 
    <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>mouseX <span style="color: #339933;">&gt;</span> M3LX<span style="color: #339933;">-</span>boxSize <span style="color: #339933;">&amp;&amp;</span> mouseX <span style="color: #339933;">&lt;</span> M3LX<span style="color: #339933;">+</span>boxSize <span style="color: #339933;">&amp;&amp;</span> 
      mouseY <span style="color: #339933;">&gt;</span> M3LY<span style="color: #339933;">-</span>boxSize <span style="color: #339933;">&amp;&amp;</span> mouseY <span style="color: #339933;">&lt;</span> M3LY<span style="color: #339933;">+</span>boxSize<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        port.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'A'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>   
    <span style="color: #009900;">&#125;</span> 
    <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>mouseX <span style="color: #339933;">&gt;</span> M3RX<span style="color: #339933;">-</span>boxSize <span style="color: #339933;">&amp;&amp;</span> mouseX <span style="color: #339933;">&lt;</span> M3RX<span style="color: #339933;">+</span>boxSize <span style="color: #339933;">&amp;&amp;</span> 
      mouseY <span style="color: #339933;">&gt;</span> M3RY<span style="color: #339933;">-</span>boxSize <span style="color: #339933;">&amp;&amp;</span> mouseY <span style="color: #339933;">&lt;</span> M3RY<span style="color: #339933;">+</span>boxSize<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        fill<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">200</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        port.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'S'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>     
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>mouseX <span style="color: #339933;">&gt;</span> M4LX<span style="color: #339933;">-</span>boxSize <span style="color: #339933;">&amp;&amp;</span> mouseX <span style="color: #339933;">&lt;</span> M4LX<span style="color: #339933;">+</span>boxSize <span style="color: #339933;">&amp;&amp;</span> 
      mouseY <span style="color: #339933;">&gt;</span> M4LY<span style="color: #339933;">-</span>boxSize <span style="color: #339933;">&amp;&amp;</span> mouseY <span style="color: #339933;">&lt;</span> M4LY<span style="color: #339933;">+</span>boxSize<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        port.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'D'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>     
    <span style="color: #009900;">&#125;</span> 
    <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>mouseX <span style="color: #339933;">&gt;</span> M4RX<span style="color: #339933;">-</span>boxSize <span style="color: #339933;">&amp;&amp;</span> mouseX <span style="color: #339933;">&lt;</span> M4RX<span style="color: #339933;">+</span>boxSize <span style="color: #339933;">&amp;&amp;</span> 
      mouseY <span style="color: #339933;">&gt;</span> M4RY<span style="color: #339933;">-</span>boxSize <span style="color: #339933;">&amp;&amp;</span> mouseY <span style="color: #339933;">&lt;</span> M4RY<span style="color: #339933;">+</span>boxSize<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        port.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'F'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  
    <span style="color: #009900;">&#125;</span> 
    <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>mouseX <span style="color: #339933;">&gt;</span> M5LX<span style="color: #339933;">-</span>boxSize <span style="color: #339933;">&amp;&amp;</span> mouseX <span style="color: #339933;">&lt;</span> M5LX<span style="color: #339933;">+</span>boxSize <span style="color: #339933;">&amp;&amp;</span> 
      mouseY <span style="color: #339933;">&gt;</span> M5LY<span style="color: #339933;">-</span>boxSize <span style="color: #339933;">&amp;&amp;</span> mouseY <span style="color: #339933;">&lt;</span> M5LY<span style="color: #339933;">+</span>boxSize<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        port.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Z'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>mouseX <span style="color: #339933;">&gt;</span> M5RX<span style="color: #339933;">-</span>boxSize <span style="color: #339933;">&amp;&amp;</span> mouseX <span style="color: #339933;">&lt;</span> M5RX<span style="color: #339933;">+</span>boxSize <span style="color: #339933;">&amp;&amp;</span> 
      mouseY <span style="color: #339933;">&gt;</span> M5RY<span style="color: #339933;">-</span>boxSize <span style="color: #339933;">&amp;&amp;</span> mouseY <span style="color: #339933;">&lt;</span> M5RY<span style="color: #339933;">+</span>boxSize<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        port.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'X'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>    
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #666666; font-style: italic;">// if the mouse is pressed but not with in a box make sure nothings moving</span>
      port.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'O'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>   
    <span style="color: #009900;">&#125;</span> 
  <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// no key or mouse press then make sure nothings moving.</span>
    port.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'O'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>   
  <span style="color: #009900;">&#125;</span> 
&nbsp;
  <span style="color: #666666; font-style: italic;">// draw the buttons</span>
  myRightArrow.<span style="color: #006633;">drawArrow</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">80</span>,<span style="color: #cc66cc;">30</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  myRightArrow.<span style="color: #006633;">drawArrow</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">80</span>,<span style="color: #cc66cc;">120</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  myRightArrow.<span style="color: #006633;">drawArrow</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">80</span>,<span style="color: #cc66cc;">210</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  myRightArrow.<span style="color: #006633;">drawArrow</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">80</span>,<span style="color: #cc66cc;">300</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  myRightArrow.<span style="color: #006633;">drawArrow</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">80</span>,<span style="color: #cc66cc;">390</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  myLeftArrow.<span style="color: #006633;">drawArrow</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">10</span>,<span style="color: #cc66cc;">30</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  myLeftArrow.<span style="color: #006633;">drawArrow</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">10</span>,<span style="color: #cc66cc;">120</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  myLeftArrow.<span style="color: #006633;">drawArrow</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">10</span>,<span style="color: #cc66cc;">210</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  myLeftArrow.<span style="color: #006633;">drawArrow</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">10</span>,<span style="color: #cc66cc;">300</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  myLeftArrow.<span style="color: #006633;">drawArrow</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">10</span>,<span style="color: #cc66cc;">390</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> arrow <span style="color: #000000; font-weight: bold;">extends</span> java.<span style="color: #006633;">awt</span>.<span style="color: #003399;">Polygon</span> <span style="color: #009900;">&#123;</span> 
  <span style="color: #666666; font-style: italic;">/* our class is basically an instance of java.awt.Polygons and this class expects and array of X points, Y points and the number of 
     points in our shape. The variable names also have to be direct references to what this class expects, so xpoints, ypoints and npoints are all
     set/defined in the java class.
  */</span>
  <span style="color: #000000; font-weight: bold;">public</span> arrow<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> xpoints,<span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> ypoints, <span style="color: #000066; font-weight: bold;">int</span> npoints<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// super invokes the java.awt.Polygon class</span>
    <span style="color: #000000; font-weight: bold;">super</span><span style="color: #009900;">&#40;</span>xpoints,ypoints,npoints<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #009900;">&#125;</span> 
    <span style="color: #666666; font-style: italic;">// supply offsets to draw the arrow, means I don't need to set points for each one</span>
    <span style="color: #000066; font-weight: bold;">void</span> drawArrow<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> xOffset, <span style="color: #000066; font-weight: bold;">int</span> yOffset<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    fill<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">150</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    rect<span style="color: #009900;">&#40;</span>xOffset<span style="color: #339933;">-</span><span style="color: #cc66cc;">5</span>, yOffset<span style="color: #339933;">-</span><span style="color: #cc66cc;">5</span>, boxSize, boxSize<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    fill<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    beginShape<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i<span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;</span>npoints<span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      vertex<span style="color: #009900;">&#40;</span>xpoints<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span>xOffset,ypoints<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span>yOffset<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span> 
    endShape<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p style="text-align: justify;"><strong>Does it work?</strong><br />
Hopefully the sketch is working and you can control the arm via your computer. If not then first check that all motors are wired in properly and your batteries are not flat. If you arrow moves the arm the wrong way then you can either switch the motor pins on the circuit or change the Arduino sketch to alter the motors direction.</p>
<p style="text-align: justify;"><strong>Calibrating the arm</strong><br />
We need to set start positions for the arm and note the positions and counts in order to later calculate the positions for the next parts of this work. This is where we&#8217;ll look to more benefits of Arduino and possibly PID (Proportional, Integral, Derivative) control, PWM or someother way to get accurate positions for the motor. The only catch is each motor is in a gearbox so using an encoder or other device to measure motor rotations is not an option. But for now we can control our arm from the computer at least &#8211; check out the video below.</p>
<p><object type="application/x-shockwave-flash" width="400" height="300" data="http://www.flickr.com/apps/video/stewart.swf?v=71377" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"><param name="flashvars" value="intl_lang=en-us&#038;photo_secret=d6fba287a2&#038;photo_id=4344951474"></param><param name="movie" value="http://www.flickr.com/apps/video/stewart.swf?v=71377"></param><param name="bgcolor" value="#000000"></param><param name="allowFullScreen" value="true"></param><embed type="application/x-shockwave-flash" src="http://www.flickr.com/apps/video/stewart.swf?v=71377" bgcolor="#000000" allowfullscreen="true" flashvars="intl_lang=en-us&#038;photo_secret=d6fba287a2&#038;photo_id=4344951474" height="300" width="400"></embed></object><br />
<a href="http://luckylarry.co.uk/2010/01/arduino-modifying-a-robot-arm/">Arduino: Modifying a Robot Arm</a>: How to wire up the robot arm to Arduino.</p>
<hr /><small>Copyright &copy; 2009<br /> This feed is for personal, non-commercial use only. <br /> The use of this feed on other websites breaches copyright. If this content is not in your news reader, it makes the page you are viewing an infringement of the copyright. (Digital Fingerprint:<br /> 0f170a4373044c85a96d646f719885c6)</small>

<p>Related posts:<ol><li><a href='http://luckylarry.co.uk/2010/01/arduino-modifying-a-robot-arm/' rel='bookmark' title='Permanent Link: Arduino: Modifying a Robot Arm'>Arduino: Modifying a Robot Arm</li><li><a href='http://luckylarry.co.uk/2009/08/obstacle-avoidance-robot-build-your-own-larrybot/' rel='bookmark' title='Permanent Link: Obstacle avoidance robot &#8211; build your own larryBot'>Obstacle avoidance robot &#8211; build your own larryBot</li><li><a href='http://luckylarry.co.uk/2009/12/using-processing-to-send-values-to-arduino/' rel='bookmark' title='Permanent Link: Using Processing to Send Values to Arduino'>Using Processing to Send Values to Arduino</li></ol></p>
<p><a href="http://feedads.g.doubleclick.net/~a/c972B-AUISBDxk7M8yAcGDD5Jdc/0/da"><img src="http://feedads.g.doubleclick.net/~a/c972B-AUISBDxk7M8yAcGDD5Jdc/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/c972B-AUISBDxk7M8yAcGDD5Jdc/1/da"><img src="http://feedads.g.doubleclick.net/~a/c972B-AUISBDxk7M8yAcGDD5Jdc/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/LuckyLarry/~4/QvxFXoowYKw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://luckylarry.co.uk/2010/02/arduino-modifying-a-robot-arm-part-2/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		<feedburner:origLink>http://luckylarry.co.uk/2010/02/arduino-modifying-a-robot-arm-part-2/</feedburner:origLink></item>
		<item>
		<title>Fixing the 2nd Gear on a Yamaha Triple Engine</title>
		<link>http://feedproxy.google.com/~r/LuckyLarry/~3/H-0noxOl804/</link>
		<comments>http://luckylarry.co.uk/2010/01/fixing-the-2nd-gear-on-a-yamaha-triple-engine/#comments</comments>
		<pubDate>Sun, 24 Jan 2010 23:45:51 +0000</pubDate>
		<dc:creator>larry</dc:creator>
				<category><![CDATA[Motorbikes]]></category>
		<category><![CDATA[Fixing 2nd gear]]></category>
		<category><![CDATA[Motorcycle]]></category>
		<category><![CDATA[Second gear]]></category>
		<category><![CDATA[Triple]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[XS750]]></category>
		<category><![CDATA[Yamaha]]></category>

		<guid isPermaLink="false">http://luckylarry.co.uk/?p=734</guid>
		<description><![CDATA[True to form our 1978 XS750 seems to pop out of 2nd gear and it seems common with the Yamaha triple engines. After looking around we found a few forum posts on fixing this but nothing really with pictures and more detail. 
So far we&#8217;ve removed the shim/ spacer between 2nd and 5th gear but [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;"><strong>True to form our 1978 XS750 seems to pop out of 2nd gear and it seems common with the Yamaha triple engines. After looking around we found a few forum posts on fixing this but nothing really with pictures and more detail. </strong></p>
<p style="text-align: justify;">So far we&#8217;ve removed the shim/ spacer between 2nd and 5th gear but need to repair the gasket seals before testing to see if this helps the gears mesh together. We&#8217;ve really just been focusing on getting access to the 2nd gear on the lay shaft and I&#8217;ll update this post if we have to do anything else to resolve this problem.</p>
<p style="text-align: justify;">The work itself is easy and you&#8217;ll probably want someone to help you but its not necessary it just makes things a bit easier. You&#8217;re going to have to be quite forceful in getting the bolts and casing off along with removing the 2nd gear on the lay shaft, but we managed to do this with basic tools and alot of straining.</p>
<p style="text-align: justify;">First a diagram from the manual of what we&#8217;re after and then why&#8230;</p>
<p><a title="XS750 gear diagram by Lucky Larry, on Flickr" href="http://www.flickr.com/photos/peplop/4301430275/"><img src="http://farm3.static.flickr.com/2723/4301430275_2b1f7e7fcc.jpg" alt="XS750 gear diagram" width="375" height="500" /></a></p>
<p style="text-align: justify;">The reason why the gears slip is wear between the 2nd and 5th gear pinions on the lay shaft, the 5th gear has dogs/ studs which connect and lock into the second gear, if these studs are worn or rounded or the slots in the 2nd gear are worn this will allow the gears to slip out. One fix for this is to move the gears closer together by removing a spacer to stop them slipping which is what I&#8217;ve started looking at.</p>
<p style="text-align: justify;">You&#8217;ll need hex keys, a mallet, some emery cloth and a few spanners &#8211; mainly to get extra leverage on the hex bolts, unless you&#8217;ve got decent ratchet handles etc&#8230; You may also need some silicon gasket sealant or new gaskets if like mine your&#8217;s have torn.</p>
<p style="text-align: justify;"><em><strong>Get the bike up on a lift or paddock stands and drain the oil before proceeding&#8230; you may also want to remove the exhaust section if using a lift.</strong></em><strong> </strong></p>
<p style="text-align: justify;"><strong>Step 1</strong><br />
<a title="Before left hand side removal by Lucky Larry, on Flickr" href="http://www.flickr.com/photos/peplop/4301482020/"><img src="http://farm3.static.flickr.com/2790/4301482020_e6dae7f50f.jpg" alt="Before left hand side removal" width="500" height="334" /></a><br />
On the left hand side of the bike we need to remove the casing. First remove the clutch cable, gear shifter and foot peg.</p>
<p><strong>Step 2<br />
</strong><a title="Remove timing plate by Lucky Larry, on Flickr" href="http://www.flickr.com/photos/peplop/4300739847/"><img src="http://farm3.static.flickr.com/2723/4300739847_3905ecc9bb.jpg" alt="Remove timing plate" width="500" height="334" /></a><br />
Remove the 3 bolts for the timing case cover and remove the cover &#8211; its the  bit with Yamaha written on it. Inside there are 3 screws that hold on the timing plate, you need to mark their positions &#8211; take a photo and use a knife to scratch in a mark for each one and remove each one. Next remove the center bolt, hold the outer nut (gold) and loosen the center bolt (silver) to remove it.</p>
<p>Now thats done you can either completely remove the timing plate or just let it hang from the wire. Now we can work around the rest of the casing removing the bolts. Start at one point and work clockwise around keeping the screws in order of removal so you can make sure you replace them as you found them.</p>
<p style="text-align: justify;"><strong>Step 3</strong><br />
<a title="Left hand side cover removed by Lucky Larry, on Flickr" href="http://www.flickr.com/photos/peplop/4301494454/"><img src="http://farm5.static.flickr.com/4002/4301494454_67e40e8fce.jpg" alt="Left hand side cover removed" width="500" height="334" /></a><br />
If its been a while since this casing was removed its going to be really stiff, time to call in Senior Tappy! Basically get something to protect the casing, e.g folded tea towel etc..  and with that between the casing and a hammer/mallet hit it a few times to loosen the seal. The casing then should come loose. Remove the casing, watch out for spindles and cogs &#8211; there&#8217;ll only be one loose.</p>
<p style="text-align: justify;"><strong>Step 4</strong><br />
<a title="Layshaft bearing housing removed by Lucky Larry, on Flickr" href="http://www.flickr.com/photos/peplop/4300820689/"><img src="http://farm3.static.flickr.com/2729/4300820689_91b2c99ffa.jpg" alt="Layshaft bearing housing removed" width="500" height="334" /></a><br />
Now we can remove the  layshaft bearing housing cover which will give us access to the area we need to work on. There are 4 screws to this cover and it sits behind the gear shift lever. Its going to be really stiff to remove so you&#8217;ll need Senior Tappy again to shake/tap it loose. It will take a lot of work but persist it will free up just keep wriggling it to get it over the gear shift lever.</p>
<p style="text-align: justify;"><strong>Step 5 </strong><br />
<a title="Remove shims and circlip in front of 2nd gear by Lucky Larry, on Flickr" href="http://www.flickr.com/photos/peplop/4301572516/"><img src="http://farm3.static.flickr.com/2752/4301572516_c3cbb96f9b.jpg" alt="Remove shims and circlip in front of 2nd gear" width="334" height="500" /></a><br />
Ok, now if you look inside you should see a cog. That&#8217;s 2nd gear on the layshaft which apparently is what causes the issues of the gears popping. So we&#8217;ll remove the circlip and shim in front of the cog, for the circlip some needlenose pliers should do the job.</p>
<p style="text-align: justify;"><strong>Step 6</strong><br />
<a title="Removing 2nd gear by Lucky Larry, on Flickr" href="http://www.flickr.com/photos/peplop/4301577046/"><img src="http://farm3.static.flickr.com/2735/4301577046_cb9f92a5b4.jpg" alt="Removing 2nd gear" width="500" height="334" /></a><br />
Here&#8217;s the worst bit &#8211; removing the cog. Now you can take the sump cover from the bottom of the bike but its a hassle and as long as we&#8217;re only dealing with 2nd gear here we can get away with out needing to do this. First get some emery cloth and lightly sand down the tops of the 6 ridges that were in front of the shim and circlip. We only want to remove the dirt and crud there so the cog will slip off. To get this cog in and out you&#8217;re going to need brute force and a few small hex keys. You should be able to get the short length of the hex key behind the cog by sliding it down the left hand side of the gear. With this in place get some pliers and get a really good grip on the hex key and begin to pull the cog out &#8211; it should give. It will take some time but keep at it &#8211; best to have 2 people taking turns. If you take the sump cover off you can probably push the gear off rather than pull it this way but its more effort really and my XS750 doesn&#8217;t have a centre stand and its on a jack.</p>
<p style="text-align: justify;"><strong>Step 7</strong><br />
<a title="Remove this metal ring to fix 2nd gear (maybe) by Lucky Larry, on Flickr" href="http://www.flickr.com/photos/peplop/4300837783/"><img src="http://farm5.static.flickr.com/4001/4300837783_a5172961bb.jpg" alt="Remove this metal ring to fix 2nd gear (maybe)" width="500" height="334" /></a><br />
Remove the shim that was behind the gear pinion &#8211; it may be attached to the rear of the gear. Now reassemble to gears and casing leaving out this shim. With this spacer gone 2nd and 5th gear should lock together better and prevent the gears slipping out, you may want to add the shim you removed to the front of the pinion to help push it closer to the 5th.</p>
<p style="text-align: justify;"><strong>Thats it! (I hope)&#8230;</strong><br />
Now if all of this doesn&#8217;t work there are a couple of extra options, you can get replacement gears off of the XS650 as its chain driven and the pinions won&#8217;t be so worn, or get new replacement pattern parts. You can also machine your existing gears to remove the rounding on the dogs of the 5th gear to get a better fit to help stop slipping. Also you can look at the shift fork on the right hand side of the bike.</p>
<p style="text-align: justify;">I&#8217;ll update this post if I have to do anything else to remedy the problem.</p>
<hr /><small>Copyright &copy; 2009<br /> This feed is for personal, non-commercial use only. <br /> The use of this feed on other websites breaches copyright. If this content is not in your news reader, it makes the page you are viewing an infringement of the copyright. (Digital Fingerprint:<br /> 0f170a4373044c85a96d646f719885c6)</small>

<p>No related posts.</p>
<p><a href="http://feedads.g.doubleclick.net/~a/qf7btCUSnIo6E-jJ7GZcomenLtA/0/da"><img src="http://feedads.g.doubleclick.net/~a/qf7btCUSnIo6E-jJ7GZcomenLtA/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/qf7btCUSnIo6E-jJ7GZcomenLtA/1/da"><img src="http://feedads.g.doubleclick.net/~a/qf7btCUSnIo6E-jJ7GZcomenLtA/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/LuckyLarry/~4/H-0noxOl804" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://luckylarry.co.uk/2010/01/fixing-the-2nd-gear-on-a-yamaha-triple-engine/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://luckylarry.co.uk/2010/01/fixing-the-2nd-gear-on-a-yamaha-triple-engine/</feedburner:origLink></item>
		<item>
		<title>Arduino: Modifying a Robot Arm</title>
		<link>http://feedproxy.google.com/~r/LuckyLarry/~3/ZXeTqUYrz3M/</link>
		<comments>http://luckylarry.co.uk/2010/01/arduino-modifying-a-robot-arm/#comments</comments>
		<pubDate>Sun, 24 Jan 2010 19:56:23 +0000</pubDate>
		<dc:creator>larry</dc:creator>
				<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Electronics]]></category>
		<category><![CDATA[Robots]]></category>
		<category><![CDATA[Control a DC motor]]></category>
		<category><![CDATA[Edge Robotic Arm Kit]]></category>
		<category><![CDATA[H-Bridge]]></category>
		<category><![CDATA[Hacking]]></category>
		<category><![CDATA[L293D]]></category>
		<category><![CDATA[Modifying]]></category>
		<category><![CDATA[motors]]></category>
		<category><![CDATA[Robot Arm]]></category>
		<category><![CDATA[SN754410]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://luckylarry.co.uk/?p=718</guid>
		<description><![CDATA[Essentially another tutorial involving controlling motors. In this post I&#8217;m going to first alter a robot arm I had built previously from a beginners kit so that it can be controlled from Arduino. Then I&#8217;m going to write a series of posts on different ways to control the robot arm using Processing and other things. [...]


Related posts:<ol><li><a href='http://luckylarry.co.uk/2010/02/arduino-modifying-a-robot-arm-part-2/' rel='bookmark' title='Permanent Link: Arduino: Controlling the Robot Arm'>Arduino: Controlling the Robot Arm</li><li><a href='http://luckylarry.co.uk/2009/08/obstacle-avoidance-robot-build-your-own-larrybot/' rel='bookmark' title='Permanent Link: Obstacle avoidance robot &#8211; build your own larryBot'>Obstacle avoidance robot &#8211; build your own larryBot</li><li><a href='http://luckylarry.co.uk/2009/08/larrybot-versions-0-1-to-0-5-lessons-learned/' rel='bookmark' title='Permanent Link: larryBot &#8211; versions 0.1 to 0.5 lessons learned'>larryBot &#8211; versions 0.1 to 0.5 lessons learned</li></ol>]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;"><strong>Essentially another tutorial involving controlling motors. In this post I&#8217;m going to first alter a robot arm I had built previously from a beginners kit so that it can be controlled from Arduino. Then I&#8217;m going to write a series of posts on different ways to control the robot arm using Processing and other things. You should be able to use all of what I write for work with other toys and motors.<br />
</strong></p>
<p style="text-align: justify;">To start with have a look at the robot arm, it&#8217;s an &#8216;Edge Robotic Arm Kit&#8217;:</p>
<p style="text-align: justify;"><a href="http://luckylarry.co.uk/wp-content/uploads/2010/01/robot-arm.jpg"><img class="aligncenter size-full wp-image-719" title="robot-arm" src="http://luckylarry.co.uk/wp-content/uploads/2010/01/robot-arm.jpg" alt="" width="467" height="467" /></a></p>
<p style="text-align: justify;">The kit is a basic construction one and costs about £30 which you can find in most gadget shops and web stores. You assemble a gear box for each motor/ joint in the arm, doesn&#8217;t take long to build (about an hour) and is controlled by a set of switches on a control box. The only thing to note here is we&#8217;re dealing with motors, not servos or stepper motors just bog standard DC motors. This means calculating positions isn&#8217;t going to be straightforward later on. The kit has 5 motors and 4 &#8216;D&#8217; series batteries to power them and can lift about 100 grammes.</p>
<p style="text-align: justify;">So this version has a controller attached that lets you move each motor by pressing a switch, the electrics are pretty basic and don&#8217;t allow much control or further input. I have seen other versions that allow you to plug it in to a computer via USB but you pretty much have the same controls.</p>
<p style="text-align: justify;">In order for us to build our own controls/ interfaces and software we need to modify the arm to allow us to interface our microcontroller &#8211; in this case an Arduino board. The best way I think do this, since we want to control a motor going backwards and forward, is to use H-bridge chips and wire each motor into a chip and then alter the power circuit to run these chips. Arduino can then digitally control the H-bridge chip to turn the motor on/off and change its direction.</p>
<p style="text-align: justify;">You can see some other work I&#8217;ve done with motor control <a href="http://luckylarry.co.uk/tag/h-bridge/">here</a> and I&#8217;ll be covering the same info throughout these posts.</p>
<p style="text-align: justify;"><strong>Parts list</strong><br />
3 H-bridge chips &#8211; I heavily recommend using the sn754410 chip but you can probably get away with the L293 series. Each chip can control 2 motors &#8211; 5 motors = 3 chips.<br />
Arduino Deumilanova w/ ATMEGA328<br />
Breadboard/ Prototyping board<br />
Jumper/ Connector wires<br />
Wire cutters/ strippers</p>
<p style="text-align: justify;"><strong>Modifying the arm</strong><br />
I hope you&#8217;re not too precious about wanting to use the control unit again, thats the first thing to go! I did look at working with this but it doesn&#8217;t give the level of control that I want. Also I&#8217;ll be cutting and stripping the wires and removing the control circuit from the arm. The only permanent damage is done to the wires &#8211; basically cutting the plugs off of the wires, so you could always get new plugs if you wanted to revert it, although once I&#8217;ve shown you what can be done I don&#8217;t think you&#8217;ll mind.</p>
<p style="text-align: justify;"><strong>Step 1</strong><br />
First we need to create our breadboard layout so we can plug in all the wires, we&#8217;re going to be using alot of pins on the Arduino, in fact I think I use pretty much all of them. You could reduce this using shift registers but for now its not an issue, although please follow the wiring diagrams as this layout gives the least hassle. Some pins e.g. digital pin 13 will make the motors move when the board is powering up so we want to avoid this.</p>
<p>First of all we need to put our H-Bridge chips on the breadboard. Make sure to put them in the center like illustrated. This means the 2 sides of the chip are isolated &#8211; it will not work otherwise!</p>
<p><a href="http://luckylarry.co.uk/wp-content/uploads/2010/01/robot-arm-board-01.jpg"><img class="aligncenter size-full wp-image-723" title="robot-arm-board-01" src="http://luckylarry.co.uk/wp-content/uploads/2010/01/robot-arm-board-01.jpg" alt="" width="630" height="488" /></a></p>
<p>Next using the above image and the following wiring diagram for the chip connect the ground and power for each chip leaving space for the motors and Arduino pins. Note that the red wires are connecting the rails together so the power will flow around the whole board! These chips will be using the battery power that runs the motors in the arm &#8211; the power will be plugged into the board, the Arduino pins are there to switch the chips on/ off etc&#8230; I&#8217;ve also got a table of outputs I&#8217;ve done for each pin on the H-Bridge chip, it&#8217;s the same for either the L293 series or SN754410. The numbers 1-16 also correspond to the numbers on the images of the circuit.</p>
<p style="text-align: justify; padding-left: 30px;">
<p style="text-align: justify;"><a href="http://luckylarry.co.uk/wp-content/uploads/2009/07/L293D.gif"><img class="aligncenter size-full wp-image-170" title="L293D Pin layout" src="http://luckylarry.co.uk/wp-content/uploads/2009/07/L293D.gif" alt="" width="411" height="399" /></a></p>
<p style="text-align: justify; padding-left: 30px;"><strong>PINS</strong><br />
1 to pin on Arduino board<br />
2 to pin on Arduino board<br />
3 to motor1  (either + or -) it wont matter as its DC<br />
4 to the gnd (-) rail on the breadboard<br />
5 to the gnd (-) rail on the breadboard<br />
6 to motor1<br />
7 to pin Arduino<br />
8 to power (+) rail.<br />
9 to pin Arduino<br />
10 to pin Arduino<br />
11 to motor2<br />
12 to GND (-) rail<br />
13 to GND (-) rail<br />
14 to motor2<br />
15 to pin Arduino<br />
16 to power (+) rail.</p>
<p style="text-align: justify;">So you should have 3 chips on the board and be ready to add the motors and connections to Arduino.</p>
<p style="text-align: justify;"><strong>Step 2</strong><br />
Now the circuit layout is complete we can start stripping down the arm. First remove the control unit and unscrew the panel above the battery pack &#8211; this should have all the motors plugged in to it. We&#8217;re going to systematically disconnect each motor plug, remove the plug, strip the wires a little bit and wire it on to the breadboard. When stripping the wires, remember to twist the exposed wires to prevent them becoming stranded &#8211; or solder pins to the wires.</p>
<p style="text-align: justify;">Here&#8217;s the first motor in on the first chip:</p>
<p style="text-align: justify;"><a href="http://luckylarry.co.uk/wp-content/uploads/2010/01/robot-arm-board-03.jpg"><img class="aligncenter size-full wp-image-724" title="robot-arm-board-03" src="http://luckylarry.co.uk/wp-content/uploads/2010/01/robot-arm-board-03.jpg" alt="" width="630" height="303" /></a></p>
<p style="text-align: justify;">Its important to remember which motor you&#8217;re plugging in to which chip but it&#8217;s not too much of an issue as with the software we&#8217;ll be writing later on we can work around this with our code, just so long as each motor is wired into a chip as above. Below is a list of my Arduino pins used.</p>
<p style="text-align: justify; padding-left: 30px;"><span style="text-decoration: underline;">Shoulder motor</span><br />
chip 1, pin 1 to Arduino pin 14 (Analog pin o)<br />
chip 1, pin 2 to Arduino pin 15 (Analog pin 1)<br />
chip 1, pin 7 to Arduino pin 16 (Analog pin 2)<br />
<span style="text-decoration: underline;">Base motor</span><br />
chip 1, pin 9 to Arduino pin 2<br />
chip 1, pin 10 to Arduino pin 3<br />
chip 1, pin 15 to Arduino pin 4<br />
<span style="text-decoration: underline;">Elbow motor</span><br />
chip 2, pin 1 to Arduino pin 8<br />
chip 2, pin 2 to Arduino pin 9<br />
chip 2, pin 7 to Arduino pin 10<br />
<span style="text-decoration: underline;"> Wrist motor</span><br />
chip 2, pin 9 to Arduino pin 5<br />
chip 2, pin 10 to Arduino pin 6<br />
chip 2, pin 15 to Arduino pin 7<br />
<span style="text-decoration: underline;">Hand motor</span><br />
chip 3, pin 9 to Arduino pin 11<br />
chip 3, pin 10 to Arduino pin 17 (Analog pin 3)<br />
chip 4, pin 15 to Arduino pin 18 (Analog pin 4)</p>
<p style="text-align: justify;">You&#8217;ll notice that rather than refer to the motors as M1, M2, M3 as the kit does, I&#8217;m calling them something more meaningful as I think it makes them easier to identify &#8211; you should be able to figure out which motor is which from my description I would hope!</p>
<p style="text-align: justify;">Second motor in:</p>
<p style="text-align: justify;"><a href="http://luckylarry.co.uk/wp-content/uploads/2010/01/robot-arm-board-04.jpg"><img class="aligncenter size-full wp-image-726" title="robot-arm-board-04" src="http://luckylarry.co.uk/wp-content/uploads/2010/01/robot-arm-board-04.jpg" alt="" width="630" height="848" /></a></p>
<p style="text-align: justify;">You can see the battery power has been added. If you have any problems you can always connect one motor at a time and use a quick sketch to test the circuit is working and below is some simple codeto help you do that. For later tutorials this isn&#8217;t going to change much.</p>
<p style="text-align: justify;">

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">int</span> baseMotorEnablePin <span style="color: #339933;">=</span> <span style="color: #0000dd;">2</span><span style="color: #339933;">;</span>
<span style="color: #993333;">int</span> baseMotorPin1 <span style="color: #339933;">=</span> <span style="color: #0000dd;">3</span><span style="color: #339933;">;</span>                             
<span style="color: #993333;">int</span> baseMotorPin2 <span style="color: #339933;">=</span> <span style="color: #0000dd;">4</span><span style="color: #339933;">;</span>                           
<span style="color: #993333;">int</span> shoulderMotorEnablePin <span style="color: #339933;">=</span> <span style="color: #0000dd;">14</span><span style="color: #339933;">;</span>
<span style="color: #993333;">int</span> shoulderMotorPin1 <span style="color: #339933;">=</span> <span style="color: #0000dd;">15</span><span style="color: #339933;">;</span>                             
<span style="color: #993333;">int</span> shoulderMotorPin2 <span style="color: #339933;">=</span> <span style="color: #0000dd;">16</span><span style="color: #339933;">;</span> 
<span style="color: #993333;">int</span> elbowMotorEnablePin <span style="color: #339933;">=</span> <span style="color: #0000dd;">8</span><span style="color: #339933;">;</span>
<span style="color: #993333;">int</span> elbowMotorPin1 <span style="color: #339933;">=</span> <span style="color: #0000dd;">9</span><span style="color: #339933;">;</span>                             
<span style="color: #993333;">int</span> elbowMotorPin2 <span style="color: #339933;">=</span> <span style="color: #0000dd;">10</span><span style="color: #339933;">;</span>                           
<span style="color: #993333;">int</span> wristMotorEnablePin <span style="color: #339933;">=</span> <span style="color: #0000dd;">5</span><span style="color: #339933;">;</span>
<span style="color: #993333;">int</span> wristMotorPin1 <span style="color: #339933;">=</span> <span style="color: #0000dd;">6</span><span style="color: #339933;">;</span>                             
<span style="color: #993333;">int</span> wristMotorPin2 <span style="color: #339933;">=</span> <span style="color: #0000dd;">7</span><span style="color: #339933;">;</span> 
<span style="color: #993333;">int</span> handMotorEnablePin <span style="color: #339933;">=</span> <span style="color: #0000dd;">11</span>
<span style="color: #993333;">int</span> handMotorPin1 <span style="color: #339933;">=</span> <span style="color: #0000dd;">17</span><span style="color: #339933;">;</span>                             
<span style="color: #993333;">int</span> handMotorPin2 <span style="color: #339933;">=</span> <span style="color: #0000dd;">18</span><span style="color: #339933;">;</span> 
&nbsp;
<span style="color: #993333;">void</span> setup<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;">// set the motor pins as outputs:</span>
  <span style="color: #666666; font-style: italic;">// set all chips to enabled state</span>
  pinMode<span style="color: #009900;">&#40;</span>baseMotorPin1<span style="color: #339933;">,</span> OUTPUT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  pinMode<span style="color: #009900;">&#40;</span>baseMotorPin2<span style="color: #339933;">,</span> OUTPUT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  pinMode<span style="color: #009900;">&#40;</span>baseMotorEnablePin<span style="color: #339933;">,</span> OUTPUT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  digitalWrite<span style="color: #009900;">&#40;</span>baseMotorEnablePin<span style="color: #339933;">,</span> HIGH<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  pinMode<span style="color: #009900;">&#40;</span>shoulderMotorPin1<span style="color: #339933;">,</span> OUTPUT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  pinMode<span style="color: #009900;">&#40;</span>shoulderMotorPin2<span style="color: #339933;">,</span> OUTPUT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  pinMode<span style="color: #009900;">&#40;</span>shoulderMotorEnablePin<span style="color: #339933;">,</span> OUTPUT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  digitalWrite<span style="color: #009900;">&#40;</span>shoulderMotorEnablePin<span style="color: #339933;">,</span> HIGH<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  pinMode<span style="color: #009900;">&#40;</span>elbowMotorPin1<span style="color: #339933;">,</span> OUTPUT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  pinMode<span style="color: #009900;">&#40;</span>elbowMotorPin2<span style="color: #339933;">,</span> OUTPUT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  pinMode<span style="color: #009900;">&#40;</span>elbowMotorEnablePin<span style="color: #339933;">,</span> OUTPUT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  digitalWrite<span style="color: #009900;">&#40;</span>elbowMotorEnablePin<span style="color: #339933;">,</span> HIGH<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  pinMode<span style="color: #009900;">&#40;</span>wristMotorPin1<span style="color: #339933;">,</span> OUTPUT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  pinMode<span style="color: #009900;">&#40;</span>wristMotorPin2<span style="color: #339933;">,</span> OUTPUT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  pinMode<span style="color: #009900;">&#40;</span>wristMotorEnablePin<span style="color: #339933;">,</span> OUTPUT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  digitalWrite<span style="color: #009900;">&#40;</span>wristMotorEnablePin<span style="color: #339933;">,</span> HIGH<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">void</span> loop<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #808080; font-style: italic;">/* 
    // SET either one to HIGH to turn the motor on.
    // e.g. 
    digitalWrite(baseMotorPin1, LOW);   
    digitalWrite(baseMotorPin2, HIGH);  
    */</span>
    digitalWrite<span style="color: #009900;">&#40;</span>baseMotorPin1<span style="color: #339933;">,</span> LOW<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>   
    digitalWrite<span style="color: #009900;">&#40;</span>baseMotorPin2<span style="color: #339933;">,</span> LOW<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  
    <span style="color: #808080; font-style: italic;">/*
    // more motors here added.
    digitalWrite(shoulderMotorPin1, LOW);   
    digitalWrite(shoulderMotorPin2, LOW); 
    digitalWrite(elbowMotorPin1, LOW);   
    digitalWrite(elbowMotorPin2, LOW);  
    digitalWrite(wristMotorPin1, LOW);   
    digitalWrite(wristMotorPin2, LOW); 
    */</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

</p>
<p><strong>Step 3</strong><br />
So now you should have all the motors wired to chips on the breadboard, now we just add the power to the board and we&#8217;re done &#8211; this is the power from the robot arm batteries, it can connect on either side of the breadboard as long as its connected to the power rails. Also remember to connect a wire from the GND rail on the breadboard to a GND pin on Arduino &#8211; there must be a common ground connection between Arduino and the H-bridge chips for this to work. Lastly Find a way to secure the Arduino and breadboard to the arm to minimise the risk of wires disconnecting, I just used some blu-tak (modelling clay etc..).</p>
<p>And here&#8217;s the final thing:</p>
<p><a href="http://luckylarry.co.uk/wp-content/uploads/2010/01/robot-arm-01.jpg"><img class="aligncenter size-full wp-image-722" title="robot-arm-01" src="http://luckylarry.co.uk/wp-content/uploads/2010/01/robot-arm-01.jpg" alt="" width="630" height="432" /></a></p>
<p style="text-align: justify;">If you want to avoid the breadboard and make a more permanent circuit you should be able ot follow this, just make sure that the pins on each side of the H-Bridge are completely isolated from each other.</p>
<p style="text-align: justify;"><strong>Onwards&#8230;</strong><br />
So thats it, the arm is ready to go &#8211; you can add your own switches and inputs to control this but we&#8217;re going  to have some fun writing software to control this arm in the next part to move each motor AND after that we&#8217;re going to be looking at using Inverse Kinematics and trigonometry to do some cool controlling of all the motors of the arm and to maybe start program tasks.</p>
<p style="text-align: justify;">Oh, Inverse Kinematics basically means we can program the arm to go after a target moving all the motors in combination to do this &#8211; trust me it is very cool!</p>
<p style="text-align: justify;">
<a href="http://luckylarry.co.uk/2010/02/arduino-modifying-a-robot-arm-part-2/">Arduino: Controlling the Robot Arm</a>: Using Processing and my laptop to control the arm</p>
<hr /><small>Copyright &copy; 2009<br /> This feed is for personal, non-commercial use only. <br /> The use of this feed on other websites breaches copyright. If this content is not in your news reader, it makes the page you are viewing an infringement of the copyright. (Digital Fingerprint:<br /> 0f170a4373044c85a96d646f719885c6)</small>

<p>Related posts:<ol><li><a href='http://luckylarry.co.uk/2010/02/arduino-modifying-a-robot-arm-part-2/' rel='bookmark' title='Permanent Link: Arduino: Controlling the Robot Arm'>Arduino: Controlling the Robot Arm</li><li><a href='http://luckylarry.co.uk/2009/08/obstacle-avoidance-robot-build-your-own-larrybot/' rel='bookmark' title='Permanent Link: Obstacle avoidance robot &#8211; build your own larryBot'>Obstacle avoidance robot &#8211; build your own larryBot</li><li><a href='http://luckylarry.co.uk/2009/08/larrybot-versions-0-1-to-0-5-lessons-learned/' rel='bookmark' title='Permanent Link: larryBot &#8211; versions 0.1 to 0.5 lessons learned'>larryBot &#8211; versions 0.1 to 0.5 lessons learned</li></ol></p>
<p><a href="http://feedads.g.doubleclick.net/~a/bq9EiPMgYPvKKRrFFmQn8dN1JfM/0/da"><img src="http://feedads.g.doubleclick.net/~a/bq9EiPMgYPvKKRrFFmQn8dN1JfM/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/bq9EiPMgYPvKKRrFFmQn8dN1JfM/1/da"><img src="http://feedads.g.doubleclick.net/~a/bq9EiPMgYPvKKRrFFmQn8dN1JfM/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/LuckyLarry/~4/ZXeTqUYrz3M" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://luckylarry.co.uk/2010/01/arduino-modifying-a-robot-arm/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://luckylarry.co.uk/2010/01/arduino-modifying-a-robot-arm/</feedburner:origLink></item>
		<item>
		<title>Fitting New Rear Disc Brake for Triumph Tiger</title>
		<link>http://feedproxy.google.com/~r/LuckyLarry/~3/zZG6BaJQkdQ/</link>
		<comments>http://luckylarry.co.uk/2010/01/fitting-new-rear-disc-brake-for-triumph-tiger/#comments</comments>
		<pubDate>Mon, 04 Jan 2010 20:47:35 +0000</pubDate>
		<dc:creator>larry</dc:creator>
				<category><![CDATA[Motorbikes]]></category>
		<category><![CDATA[Bodge]]></category>
		<category><![CDATA[Rear Disc Brake]]></category>
		<category><![CDATA[Removing stuck bolts]]></category>
		<category><![CDATA[Triumph Tiger]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://luckylarry.co.uk/?p=708</guid>
		<description><![CDATA[Also serves as a handy guide on what to do if the head of a hex bolt etc&#8230; is worn away. Hopefully this is pretty similar for changing the rear discs for most bikes.

First of all the tools you will need to do the job will be a decent ratchet handle/ socket set, with standard [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;"><strong>Also serves as a handy guide on what to do if the head of a hex bolt etc&#8230; is worn away. Hopefully this is pretty similar for changing the rear discs for most bikes.<br />
</strong></p>
<p style="text-align: justify;">First of all the tools you will need to do the job will be a decent ratchet handle/ socket set, with standard metric (maybe imperial depending on bike) square, hex and 6 spline torque sockets. You&#8217;ll need sizes ranging from 6 to 12mm  generally along with a couple of larger ones for the rear wheel spindle. You&#8217;ll also need a couple of breaker bars &#8211; a small one, say 8 inch, and a larger one, either 18 or 24 inch. to go with these you&#8217;ll also probably need a couple of converters for the sockets: 1/2 inch to 1/4 inch probably. You&#8217;ll need the larger bar for the rear wheel and the smaller is in case of stiff bolts. Finally you&#8217;ll need a rubber headed mallet &#8211; just in case you&#8217;re reading this and the bolt head is worn, more explained later on. You may also need a flat headed screwdriver or something to open the brake calipers up a bit to fit the new disc &#8211; or you can take the caliper apart to do this.</p>
<p style="text-align: justify;">Parts wise, well you&#8217;ll need a replacement disc and some blue Loctite Threadlocker (or something similar) and thats it.</p>
<p style="text-align: justify;">I&#8217;d also recommend doing this in a nice cosy garage and not out in the icy streets of London because what was meant to be a 30 minute job took longer than anticipated and it was really fucking cold! Also having 2 people doing this is much easier &#8211; especially for when you want to refit the wheel.</p>
<p style="text-align: justify;">Here&#8217;s my step by step guide:</p>
<p style="text-align: justify;"><strong>Stage One: Remove the rear brake caliper</strong><br />
Firstly get your bike on the centre stand or if on paddock stands if your bike doesnt have one. You can see why the disc needs refitting, its rusty and warped, if you look close enough you can see just how worn it it. To remove the caliper just undo the bolts holding it in place and you can leave the caliper to dangle off the swingarm. You may need to wiggle and tease it a bit to get it off of the disc.
</p>
<p><img class="aligncenter" src="http://farm5.static.flickr.com/4058/4245579418_56bd9de727_b.jpg" alt="" width="630" height="943" /></p>
<p style="text-align: justify;"><strong>Stage Two: Remove the rear axle</strong><br />
You&#8217;ll need a 18-24 inch breaker bar probably to get enough leverage to loosen the bolt and its handy having a second person to hold the nut in place on the other side and to support the rear wheel.
</p>
<p><img class="aligncenter" src="http://farm5.static.flickr.com/4010/4245575056_d730fefe1d_b.jpg" alt="" width="630" height="941" /></p>
<p style="text-align: justify;"><strong>Stage Three: Remove the rear wheel</strong><br />
With the axle remove you can  begin to ease the rear wheel out, look out for the spacers either side of the wheel that may drop off. They&#8217;ll be different sizes so remember their position &#8211; take a photo to remind you if unsure. The caliper plate/ holder will also probably fall out as well as depending on how its fixed. In the case of this bike its held in place by the same bolts that hold the caliper on which also bolt it to the swingarm. Remove the sprocket from the chain and sit the wheel down on an old blanket with the disc brake facing up.
</p>
<p><img class="aligncenter" src="http://farm3.static.flickr.com/2780/4245565374_fbb4b6872f_b.jpg" alt="" width="630" height="942" /></p>
<p style="text-align: justify;"><strong>Stage Four: Remove the disc</strong><br />
Slacken off the bolts holding the rear disc in place and remove them.
</p>
<p><img class="aligncenter" src="http://farm3.static.flickr.com/2756/4245607348_35d5eff769_b.jpg" alt="" width="630" height="942" /></p>
<p style="text-align: justify;"><strong>Stage Four still: Oh shit this one wont come out</strong><br />
The bolt head has worn away too much to get a good grip to loosen the bolt. To get around this using a rubber headed mallet, get a slightly larger socket and hammer this in to the socket. Rotate the wheel around periodically to ensure the socket is hammered in equally to avoid it being wonky. The bolts on this brake are hex, so using a 6 splined socket works well, hammering it in won&#8217;t damage the socket as the bolt is a softer metal. It will take at least 20 minutes to hammer it in well enough for it to get a grip, if you don&#8217;t hammer it in enough you&#8217;ll wreck the bolt and cause more hassle. Tap it in all the way to the depth of the original hole to be sure.
</p>
<p><img class="aligncenter" src="http://farm5.static.flickr.com/4024/4244828955_1f3fb4a271_b.jpg" alt="" width="630" height="942" /></p>
<p style="text-align: justify;"><strong>Stage Four: The socket hammered in</strong>
</p>
<p><img class="aligncenter" src="http://farm3.static.flickr.com/2638/4245599502_248e9db3fb_b.jpg" alt="" width="630" height="942" /></p>
<p style="text-align: justify;"><strong>Stage Four: Remove the pesky bolt</strong><br />
Using a smaller breaker bar try to ease the bolt out, you should find that it will shift now that the socket has grip. If you use a large bar, it&#8217;ll probably wreck the bolt head.
</p>
<p><img class="aligncenter" src="http://farm5.static.flickr.com/4043/4245595516_f99845c827_b.jpg" alt="" width="630" height="942" /></p>
<p style="text-align: justify;"><strong>Stage Five: Fit the new disc</strong><br />
Place on the new disc and apply Loctite blue Threadlock to the threads of the bolts &#8211; not the base, just the thread. tighten the bolts until you feel resistance. Then work around each bolt as per your manual to tighten them to the correct setting &#8211; or just until it feels right I guess.
</p>
<p><img class="aligncenter" src="http://farm3.static.flickr.com/2745/4245591360_42450e08d5_b.jpg" alt="" width="630" height="942" /></p>
<p style="text-align: justify;"><strong>Stage Six: Refit the rear wheel</strong><br />
Now fit the rear wheel, its really handy having a second person to help support the wheel. First fit the chain on the sprocket, then attach the spacers and the caliper holder. The next trick is to get everything inline as you push the rear axle through and it may take a while!</p>
<p>After this then you&#8217;ll need to refit the caliper, this may be a struggle as was in this case as the disc had worn away so the caliper needed to be opened up more accommodate a thicker disc. You can take the caliper apart or force the plates apart using something flat.
</p>
<p><img class="aligncenter" src="http://farm3.static.flickr.com/2789/4245587404_d2f5d0af2b_b.jpg" alt="" width="630" height="942" /></p>
<p style="text-align: justify;"><strong>The old disc</strong><br />
Check it out, no wonder the rear brake didn&#8217;t work to well. You can&#8217;t see it but the brake disc is also warped as well as heavily worn away.
</p>
<p><img class="aligncenter" src="http://farm3.static.flickr.com/2527/4245582050_106ea1c5d4_b.jpg" alt="" width="630" height="942" /></p>
<p style="text-align: justify;">
<hr /><small>Copyright &copy; 2009<br /> This feed is for personal, non-commercial use only. <br /> The use of this feed on other websites breaches copyright. If this content is not in your news reader, it makes the page you are viewing an infringement of the copyright. (Digital Fingerprint:<br /> 0f170a4373044c85a96d646f719885c6)</small>

<p>No related posts.</p>
<p><a href="http://feedads.g.doubleclick.net/~a/-Vpl6enLTQX6I8nRZ7n3-ocgHbk/0/da"><img src="http://feedads.g.doubleclick.net/~a/-Vpl6enLTQX6I8nRZ7n3-ocgHbk/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/-Vpl6enLTQX6I8nRZ7n3-ocgHbk/1/da"><img src="http://feedads.g.doubleclick.net/~a/-Vpl6enLTQX6I8nRZ7n3-ocgHbk/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/LuckyLarry/~4/zZG6BaJQkdQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://luckylarry.co.uk/2010/01/fitting-new-rear-disc-brake-for-triumph-tiger/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://luckylarry.co.uk/2010/01/fitting-new-rear-disc-brake-for-triumph-tiger/</feedburner:origLink></item>
		<item>
		<title>Using Processing to Send Values to Arduino</title>
		<link>http://feedproxy.google.com/~r/LuckyLarry/~3/PGmIV3CfsL8/</link>
		<comments>http://luckylarry.co.uk/2009/12/using-processing-to-send-values-to-arduino/#comments</comments>
		<pubDate>Thu, 24 Dec 2009 16:48:45 +0000</pubDate>
		<dc:creator>larry</dc:creator>
				<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Arduino C/C++]]></category>
		<category><![CDATA[Electronics]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Collision Detection]]></category>
		<category><![CDATA[Control Arduino using Processing]]></category>
		<category><![CDATA[LED]]></category>
		<category><![CDATA[Polygons]]></category>
		<category><![CDATA[Processing]]></category>
		<category><![CDATA[PVector]]></category>
		<category><![CDATA[PWM]]></category>
		<category><![CDATA[RGB LED]]></category>
		<category><![CDATA[RGBL]]></category>
		<category><![CDATA[Serial port]]></category>
		<category><![CDATA[Setting values via Processing]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://luckylarry.co.uk/?p=677</guid>
		<description><![CDATA[In this write-up, I&#8217;ll show how to create a value in Processing and then send this value to the Arduino. In the example I&#8217;m setting values of LEDs making them brighter or dimmed but this example can be extended to control other items &#8211; which I plan to do later!
Basically I&#8217;m going to set a [...]


Related posts:<ol><li><a href='http://luckylarry.co.uk/2010/02/arduino-modifying-a-robot-arm-part-2/' rel='bookmark' title='Permanent Link: Arduino: Controlling the Robot Arm'>Arduino: Controlling the Robot Arm</li><li><a href='http://luckylarry.co.uk/2009/06/3-led-crossfade-with-pwm-and-arduino/' rel='bookmark' title='Permanent Link: 3 LED Crossfade with PWM and Arduino'>3 LED Crossfade with PWM and Arduino</li><li><a href='http://luckylarry.co.uk/2009/08/arduino-processing-getting-values-from-srf05-ultrasound-sensor-serial-port/' rel='bookmark' title='Permanent Link: Arduino + Processing: Getting values from SRF05 ultrasound sensor &#038; serial port'>Arduino + Processing: Getting values from SRF05 ultrasound sensor &#038; serial port</li></ol>]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;"><strong>In this write-up, I&#8217;ll show how to create a value in Processing and then send this value to the Arduino. In the example I&#8217;m setting values of LEDs making them brighter or dimmed but this example can be extended to control other items &#8211; which I plan to do later!</strong></p>
<p style="text-align: justify;">Basically I&#8217;m going to set a value between 0 and 255 and then send this value to Arduino which will then use the analogWrite() function to alter the brightness of the LED using PWM (Pulse Width Modulation). I&#8217;ve already done a bit of work with LEDs and PWM <a href="http://luckylarry.co.uk/2009/06/3-led-crossfade-with-pwm-and-arduino/">here</a>.</p>
<p style="text-align: justify;">For the communication between Processing and Arduino I&#8217;ll be using the serial port &#8211; in other work previously I&#8217;ve sent information from Arduino to Processing so this is how to do it the other way around. There are a couple of things to note though. Firstly when using Arduino to read a string from the serial port we have to look at it at a byte level, in my example it&#8217;s just easier to ignore using strings and send 1 character at a time and then store it in an array. Secondly when debugging your code you can&#8217;t read the serial values in Arduinos serial monitor as you&#8217;ll already be using the port in Processing so sometimes this can be trial and error although you can at least preview the values your sending in Processing.</p>
<p style="text-align: justify;">Of course you can also extend this code to write values from Arduino back to Processing. There are already plenty of examples online of how to do serial port communication between Arduino and Processing and vice versa and setting an LED to on or off but I&#8217;ve done a few extra things to show some basic work with interaction and user interfaces to set the LEDs.</p>
<p style="text-align: justify;">We&#8217;re going to set 3 LED&#8217;s &#8211; Red, Green and Blue and rather than just on or off we&#8217;ll be setting the PWM/ levels of brightness. Also the sketches deal with setting an RGB LED (RGBL) with the combined values.</p>
<p style="text-align: justify;">I&#8217;ve written 2 visualisations to achive the above.</p>
<p style="text-align: justify;">The first is a set of sliders like a mixing desk &#8211; when sliding a slider it will set the value of the LED it&#8217;s assigned to and the combined value will set the RGB LED. The second is a triangle shape that you can move around to create the colours, so where ever you drag each point of the triangle it will set the brightness of the LED accordingly.</p>
<p style="text-align: justify;">The Arduino circuit and sketch is very simple and remains the same no matter which visualisation is used. So starting with the circuit&#8230;</p>
<p style="text-align: justify;"><strong>Shopping List<br />
</strong>Arduino Deumilanova w/ ATMEGA328<br />
Breadboard/ Prototyping board<br />
Jumper/ Connector wires<br />
3x LED (Red, Green, Blue)<br />
1x RGB LED<br />
6x 270 Ohm resistors</p>
<p style="text-align: justify;"><strong>The Circuit</strong><br />
Very simple: 3 LEDs each with a common ground back to the Arduino board, the positive pins (the longer pin) has a 270 Ohm resistor between it and a connection to a digital pin. The RGB LED has 4 pins &#8211; 1 is for the power supply &#8211; some RGB LEDs instead may connect to GND so check before doing so. The other 3 pins each connect to a digital pin on the Arduino board.</p>
<p><a href="http://luckylarry.co.uk/wp-content/uploads/2009/12/LEDs.png"><img src="http://luckylarry.co.uk/wp-content/uploads/2009/12/LEDs.png" alt="LEDs" title="LEDs" width="630" height="545" class="aligncenter size-full wp-image-706" /></a></p>
<p style="text-align: justify;"><strong>The Sketch</strong><br />
The Arduino code is very simple as well &#8211; we set the the digital pins all as outputs, we setup the serial port we wish to use and then we read the values from the serial port and store them in an array, each item in the array corresponds to a value for an LED. There is a small catch however &#8211; it seems my RGB LED sees the value 255 as off and 0 as on so I have had to write some code to take this into account.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">/* Sets LED values based on values sent on the serial port from Processing application.
   luckylarry.co.uk
&nbsp;
*/</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// create an array of LED pins - need to be the PWM digital pins</span>
<span style="color: #000066; font-weight: bold;">int</span> ledPin<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">9</span>,<span style="color: #cc66cc;">10</span>,<span style="color: #cc66cc;">11</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span> 
<span style="color: #666666; font-style: italic;">// an array to store the pins for the RGB LED</span>
<span style="color: #000066; font-weight: bold;">int</span> RGBLpins<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">3</span>,<span style="color: #cc66cc;">5</span>,<span style="color: #cc66cc;">6</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// array to store the 3 values from the serial port</span>
<span style="color: #000066; font-weight: bold;">int</span> incomingByte<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> 
&nbsp;
<span style="color: #000066; font-weight: bold;">void</span> setup<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;">// initialize serial communication - make sure its the same as expected in the processing code</span>
  Serial.<span style="color: #006633;">begin</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">9600</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #666666; font-style: italic;">// loop through and set the pins as outputs</span>
  <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i<span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span><span style="color: #cc66cc;">3</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    pinMode<span style="color: #009900;">&#40;</span>ledPin<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>, OUTPUT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    pinMode<span style="color: #009900;">&#40;</span>RGBLpins<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>, OUTPUT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/*  3 pins are stored in an array, 3 values from the serial buffer
are stored in an array, by looping through both we can light up the LEDs
using the values sent from the Processing sketch. NOTE: the values sent over
the serial port didn't seem to be in order, rather than RGB I got GBR so it
looks like it misses the first byte - so its just trial and error matching
the correct pin to the correct value.
*/</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">void</span> loop<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;">// check to make sure there's 3 bytes of data waiting</span>
  <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>Serial.<span style="color: #006633;">available</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;=</span> <span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// read the oldest byte in the serial buffer:</span>
    <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i<span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span><span style="color: #cc66cc;">3</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #666666; font-style: italic;">// read each byte</span>
      incomingByte<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> Serial.<span style="color: #006633;">read</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #666666; font-style: italic;">// pass the value to each pin</span>
      <span style="color: #666666; font-style: italic;">// analogWrite is used to write a value between 0 and 255 to the PWM pin.</span>
      <span style="color: #666666; font-style: italic;">// lightup the separate LED's</span>
      analogWrite<span style="color: #009900;">&#40;</span>ledPin<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>, incomingByte<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #666666; font-style: italic;">// seems that my RGB LED sees the values differently - it sees 255 as nothing and 0 as full colour!</span>
      <span style="color: #000066; font-weight: bold;">int</span> val <span style="color: #339933;">=</span> <span style="color: #cc66cc;">255</span> <span style="color: #339933;">-</span> <span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#40;</span>incomingByte<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      analogWrite<span style="color: #009900;">&#40;</span>RGBLpins<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>, val<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p style="text-align: justify;"><strong>The Processing Sketches</strong><br />
Whilst both sketches visually look different they use pretty much the same methods. The main thing is that for each point, shape or item we wish to click and drag we rely on detecting where the mouse is,  if its been clicked and if we&#8217;re dragging the mouse. We can use Processings inbuilt functions mousePressed() and mouseDragged() but we still need to write conditional statements depending on where the mouse is.</p>
<p style="text-align: justify;">To do this we can get the X and Y co-ordinates of the mouse using mouseX and mouseY and to compare these values we need to store the X and Y co-ordinates of any shape as variables &#8211; the easiest way is to use the PVector variable type which in its simplest use is an array that stores an X and Y value. Now we can mathematically compare the values and limit the movement of our shapes only moving when the mouse is in the correct area.</p>
<p style="text-align: justify;">In the second sketch, the RGB triangle, I also wanted to test to make sure that the triangles points/vertices  we&#8217;re dragging remain inside a triangular area, to do this there is no Processing code as such its much easier to extend a class and use Javas polygon class (<a href="http://java.sun.com/j2se/1.4.2/docs/api/java/awt/Polygon.html">java.awt.Polygon</a>) which will do all the work for us. In order to set the values we have to work out the distance we are from the original points, for which we can use the dist() method which allows us to draw a radius from a point and check to see how far our second point is from the original &#8211; we can also use this to create a circular detection area.</p>
<p style="text-align: justify;">When getting the X, Y values from the mouse position we need to make sure these are converted to integers, for which we first use the round()  method to convert our float to 1 decimal place and then use the int() method to cast the value as an integer. We also need integer values as it makes it much easier to send ints over the serial port as the libraries allow for these values.</p>
<p style="text-align: justify;">The rest of the processing code is fairly straight forward we use text(), rect(), ellipse(), line(), fill() and stroke() functions to create our visualisation.</p>
<p style="text-align: justify;">The only other thing to note is that in draw() method we always write the values to the serial port.</p>
<p style="text-align: justify;"><strong>Visualisation One: RGB Sliders/ Mixing Desk</strong><br />
We have 3 sliders which each can set a value between 0 and 255, the Processing sketch writes each value separately to the serial port and displays the current mixed colour along with each slider value. You can download the sketch You can download the sketch here and try out the application below <a href="http://luckylarry.co.uk/code/RGB_Sliders/larrys_RGB_sliders.pde">here</a> and try out the application below. If you download the code please quickly do a find and replace to change //myPort to myPort &#8211; it&#8217;s done just so you can see the app running in this webpage.</p>
<div align="center"><object classid="java:larrys_RGB_sliders.class" type="application/x-java-applet" archive="http://luckylarry.co.uk/code/RGB_Sliders/larrys_RGB_sliders.jar,http://luckylarry.co.uk/code/RGB_Sliders/RXTXcomm.jar,http://luckylarry.co.uk/code/RGB_Sliders/serial.jar,http://luckylarry.co.uk/code/RGB_Sliders/core.jar" width="300" height="315" standby="Loading Processing software..." ><param name="archive" value="http://luckylarry.co.uk/code/RGB_Sliders/larrys_RGB_sliders.jar,http://luckylarry.co.uk/code/RGB_Sliders/RXTXcomm.jar,http://luckylarry.co.uk/code/RGB_Sliders/serial.jar,http://luckylarry.co.uk/code/RGB_Sliders/core.jar" /><param name="mayscript" value="true" /><param name="scriptable" value="true" /><param name="image" value="http://luckylarry.co.uk/code/RGB_Sliders/loading.gif" /><param name="boxmessage" value="Loading Processing software..." /><param name="boxbgcolor" value="#FFFFFF" /><param name="test_string" value="outer" /></object></div>
<p style="text-align: justify;">

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">/*
    Code by Lucky Larry: www.luckylarry.co.uk
&nbsp;
    RGB visualisation to control LED's by dragging sliders to define colour
    Copyright (C) 2009 Pete Dainty aka 'Lucky Larry'
&nbsp;
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.
&nbsp;
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
&nbsp;
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see &lt;http://www.gnu.org/licenses/&gt;.
&nbsp;
    Also makes use of gradient drawing code found at: http://processing.org/learning/basics/lineargradient.html
&nbsp;
*/</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// import the serial library to allow us to send data via the serial ports (USB in this case)</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">processing.serial.*</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// create a new instance of the serial classes and assign it to 'myPort'</span>
Serial myPort<span style="color: #339933;">;</span> 
<span style="color: #666666; font-style: italic;">// create set of variables to store vector infomation (X nd Y co-oordinates)</span>
PVector redSlider,greenSlider,blueSlider,whichSlider,lockSliders<span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// create an arry to store the vectors of each slider</span>
PVector sliders<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// boolean value (true or false) to store if lock sliders button has been clicked</span>
<span style="color: #000066; font-weight: bold;">boolean</span> locked<span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// values needed for gradient code</span>
<span style="color: #000066; font-weight: bold;">int</span> Y_AXIS <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">int</span> X_AXIS <span style="color: #339933;">=</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span> 
<span style="color: #666666; font-style: italic;">// setup our font</span>
PFont myFont<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">void</span> setup<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;">// screen size</span>
  size<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">300</span>,<span style="color: #cc66cc;">315</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #666666; font-style: italic;">// setup my font type and size </span>
  myFont <span style="color: #339933;">=</span> createFont<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;verdana&quot;</span>, <span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  textFont<span style="color: #009900;">&#40;</span>myFont<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #666666; font-style: italic;">// specifiy the co-ordinates for each slider, the lock sliders button</span>
  redSlider <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> PVector<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">50</span>,<span style="color: #cc66cc;">150</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  greenSlider <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> PVector<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">110</span>,<span style="color: #cc66cc;">150</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  blueSlider <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> PVector<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">170</span>,<span style="color: #cc66cc;">150</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  lockSliders <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> PVector<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">12</span>,<span style="color: #cc66cc;">27</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #666666; font-style: italic;">// setup an array to store the values of each slider</span>
  sliders <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> PVector<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span>redSlider,greenSlider,blueSlider<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
  <span style="color: #666666; font-style: italic;">// smooth shapes</span>
  smooth<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">/* define which port to use mine is COM10 and is 2nd in the array list.
       you can print out to the screen which ports are accessible by using this code line below
       set the baud rate to the same as in your Arduino code so mine is 9600
    */</span>
    <span style="color: #666666; font-style: italic;">// println(Serial.list()); </span>
    myPort <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Serial<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>, Serial.<span style="color: #006633;">list</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span>, <span style="color: #cc66cc;">9600</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// end setup</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">void</span> draw<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;">// set background colour to grey in case the setGradient code fails</span>
  background<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">50</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #666666; font-style: italic;">// set outlines of shapes to be black</span>
  stroke<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #666666; font-style: italic;">/* creates a rectangle shape based up on X and Y co-ords,
     width and height, 2 RGB values to the colours to mix and which
     axis to apply the gradient.
  */</span>
  color b1 <span style="color: #339933;">=</span> color<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">130</span>, <span style="color: #cc66cc;">130</span>, <span style="color: #cc66cc;">130</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  color b2 <span style="color: #339933;">=</span> color<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">70</span>, <span style="color: #cc66cc;">70</span>, <span style="color: #cc66cc;">70</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  setGradient<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">0</span>, width, height, b1, b2, Y_AXIS<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #666666; font-style: italic;">// set the backgrounds of our slider columns</span>
  color sliderGrad1 <span style="color: #339933;">=</span> color<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">120</span>, <span style="color: #cc66cc;">120</span>, <span style="color: #cc66cc;">120</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  color sliderGrad2 <span style="color: #339933;">=</span> color<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">50</span>, <span style="color: #cc66cc;">50</span>, <span style="color: #cc66cc;">50</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  setGradient<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">25</span>, <span style="color: #cc66cc;">20</span>, <span style="color: #cc66cc;">50</span>, <span style="color: #cc66cc;">275</span>, sliderGrad1, sliderGrad2, Y_AXIS<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  setGradient<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">85</span>, <span style="color: #cc66cc;">20</span>, <span style="color: #cc66cc;">50</span>, <span style="color: #cc66cc;">275</span>, sliderGrad1, sliderGrad2, Y_AXIS<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  setGradient<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">145</span>, <span style="color: #cc66cc;">20</span>, <span style="color: #cc66cc;">50</span>, <span style="color: #cc66cc;">275</span>, sliderGrad1, sliderGrad2, Y_AXIS<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  noFill<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  rectMode<span style="color: #009900;">&#40;</span>CENTER<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #666666; font-style: italic;">// draw the outlines of each column and a guide line in the center</span>
  rect<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">50</span>,<span style="color: #cc66cc;">160</span>,<span style="color: #cc66cc;">50</span>,<span style="color: #cc66cc;">275</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  rect<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">110</span>,<span style="color: #cc66cc;">160</span>,<span style="color: #cc66cc;">50</span>,<span style="color: #cc66cc;">275</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  rect<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">170</span>,<span style="color: #cc66cc;">160</span>,<span style="color: #cc66cc;">50</span>,<span style="color: #cc66cc;">275</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  line<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">50</span>,<span style="color: #cc66cc;">30</span>,<span style="color: #cc66cc;">50</span>,<span style="color: #cc66cc;">285</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  line<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">110</span>,<span style="color: #cc66cc;">30</span>,<span style="color: #cc66cc;">110</span>,<span style="color: #cc66cc;">285</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  line<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">170</span>,<span style="color: #cc66cc;">30</span>,<span style="color: #cc66cc;">170</span>,<span style="color: #cc66cc;">285</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #666666; font-style: italic;">// loop through 25 times to produce 25 measurement lines and measurements</span>
  <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i<span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;=</span><span style="color: #cc66cc;">25</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    stroke<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">30</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// first column</span>
    line<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">46</span>,<span style="color: #cc66cc;">30</span><span style="color: #339933;">+</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">*</span><span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span>,<span style="color: #cc66cc;">54</span>,<span style="color: #cc66cc;">30</span><span style="color: #339933;">+</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">*</span><span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// second column</span>
    line<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">106</span>,<span style="color: #cc66cc;">30</span><span style="color: #339933;">+</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">*</span><span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span>,<span style="color: #cc66cc;">114</span>,<span style="color: #cc66cc;">30</span><span style="color: #339933;">+</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">*</span><span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// third column</span>
    line<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">166</span>,<span style="color: #cc66cc;">30</span><span style="color: #339933;">+</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">*</span><span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span>,<span style="color: #cc66cc;">174</span>,<span style="color: #cc66cc;">30</span><span style="color: #339933;">+</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">*</span><span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// right hand gauge and measurement numbers</span>
    fill<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">40</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    stroke<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">40</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    line<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">196</span>,<span style="color: #cc66cc;">30</span><span style="color: #339933;">+</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">*</span><span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span>,<span style="color: #cc66cc;">201</span>,<span style="color: #cc66cc;">30</span><span style="color: #339933;">+</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">*</span><span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    text<span style="color: #009900;">&#40;</span><span style="color: #003399;">Integer</span>.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">*</span><span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span>,<span style="color: #cc66cc;">216</span>,<span style="color: #cc66cc;">35</span><span style="color: #339933;">+</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">*</span><span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span>,<span style="color: #cc66cc;">25</span>,<span style="color: #cc66cc;">25</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #666666; font-style: italic;">// draw the sliders - one for each item in the sliders array</span>
  <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i<span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span>sliders.<span style="color: #006633;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    fill<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">50</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    stroke<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    rect<span style="color: #009900;">&#40;</span>sliders<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #006633;">x</span>,sliders<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #006633;">y</span>,<span style="color: #cc66cc;">40</span>,<span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
  <span style="color: #009900;">&#125;</span>
  <span style="color: #666666; font-style: italic;">// display text at top of columns.</span>
  text<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;RED&quot;</span>,<span style="color: #cc66cc;">50</span>,<span style="color: #cc66cc;">20</span>,<span style="color: #cc66cc;">50</span>,<span style="color: #cc66cc;">25</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  text<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;GREEN&quot;</span>,<span style="color: #cc66cc;">110</span>,<span style="color: #cc66cc;">20</span>,<span style="color: #cc66cc;">50</span>,<span style="color: #cc66cc;">25</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  text<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;BLUE&quot;</span>,<span style="color: #cc66cc;">170</span>,<span style="color: #cc66cc;">20</span>,<span style="color: #cc66cc;">50</span>,<span style="color: #cc66cc;">25</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  text<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;COLOUR&quot;</span>,<span style="color: #cc66cc;">260</span>,<span style="color: #cc66cc;">20</span>,<span style="color: #cc66cc;">50</span>,<span style="color: #cc66cc;">25</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #666666; font-style: italic;">// rotate the lock sliders text using pushMatrix and opMatrix to isolate the transformation</span>
  <span style="color: #666666; font-style: italic;">// so that it doesn't affect everything else</span>
  pushMatrix<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    translate<span style="color: #009900;">&#40;</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">33</span>,<span style="color: #cc66cc;">155</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    rotate<span style="color: #009900;">&#40;</span>radians<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">270</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    text<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Lock Sliders&quot;</span>,<span style="color: #cc66cc;">100</span>,<span style="color: #cc66cc;">50</span>,<span style="color: #cc66cc;">100</span>,<span style="color: #cc66cc;">25</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  popMatrix<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #666666; font-style: italic;">// draw the rectangle button for locking sliders</span>
  fill<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  rect<span style="color: #009900;">&#40;</span>lockSliders.<span style="color: #006633;">x</span>,lockSliders.<span style="color: #006633;">y</span>,<span style="color: #cc66cc;">10</span>,<span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  fill<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #666666; font-style: italic;">// if locked is true then change the button to show its active.</span>
  <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>locked<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    text<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;X&quot;</span>,<span style="color: #cc66cc;">19</span>,<span style="color: #cc66cc;">30</span>,<span style="color: #cc66cc;">20</span>,<span style="color: #cc66cc;">20</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #666666; font-style: italic;">// create 3 circles for each colour which will change depending on the slider</span>
  fill<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#40;</span>redSlider.<span style="color: #006633;">y</span><span style="color: #009900;">&#41;</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  ellipse<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">70</span>,<span style="color: #cc66cc;">15</span>,<span style="color: #cc66cc;">10</span>,<span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  fill<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span>,<span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#40;</span>greenSlider.<span style="color: #006633;">y</span><span style="color: #009900;">&#41;</span>,<span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  ellipse<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">130</span>,<span style="color: #cc66cc;">15</span>,<span style="color: #cc66cc;">10</span>,<span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  fill<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#40;</span>blueSlider.<span style="color: #006633;">y</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  ellipse<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">190</span>,<span style="color: #cc66cc;">15</span>,<span style="color: #cc66cc;">10</span>,<span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #666666; font-style: italic;">// create a colour square to show the current mixed colour</span>
  fill<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#40;</span>redSlider.<span style="color: #006633;">y</span><span style="color: #009900;">&#41;</span>,<span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#40;</span>greenSlider.<span style="color: #006633;">y</span><span style="color: #009900;">&#41;</span>,<span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#40;</span>blueSlider.<span style="color: #006633;">y</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  rect<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">260</span>,<span style="color: #cc66cc;">32</span>,<span style="color: #cc66cc;">50</span>,<span style="color: #cc66cc;">20</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #666666; font-style: italic;">// display text at bottom of each column to show slider value (0-255)</span>
  fill<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">40</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  text<span style="color: #009900;">&#40;</span><span style="color: #003399;">Integer</span>.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#40;</span>round<span style="color: #009900;">&#40;</span>redSlider.<span style="color: #006633;">y</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">31</span><span style="color: #009900;">&#41;</span>,<span style="color: #cc66cc;">65</span>,<span style="color: #cc66cc;">310</span>,<span style="color: #cc66cc;">50</span>,<span style="color: #cc66cc;">25</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  text<span style="color: #009900;">&#40;</span><span style="color: #003399;">Integer</span>.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#40;</span>round<span style="color: #009900;">&#40;</span>greenSlider.<span style="color: #006633;">y</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">31</span><span style="color: #009900;">&#41;</span>,<span style="color: #cc66cc;">125</span>,<span style="color: #cc66cc;">310</span>,<span style="color: #cc66cc;">50</span>,<span style="color: #cc66cc;">25</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  text<span style="color: #009900;">&#40;</span><span style="color: #003399;">Integer</span>.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#40;</span>round<span style="color: #009900;">&#40;</span>blueSlider.<span style="color: #006633;">y</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">31</span><span style="color: #009900;">&#41;</span>,<span style="color: #cc66cc;">185</span>,<span style="color: #cc66cc;">310</span>,<span style="color: #cc66cc;">50</span>,<span style="color: #cc66cc;">25</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #666666; font-style: italic;">/* we need to send this fill value to the Arduino to light up the LED's accordingly
     we do this by writing a value to the serial port
     You can write values to the serial port using bytes, integers and chars.
     I'm going to send the 3 values separately and store them in an array on the Arduino
  */</span>
  myPort.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#40;</span>round<span style="color: #009900;">&#40;</span>redSlider.<span style="color: #006633;">y</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">31</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  myPort.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#40;</span>round<span style="color: #009900;">&#40;</span>greenSlider.<span style="color: #006633;">y</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">31</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  myPort.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#40;</span>round<span style="color: #009900;">&#40;</span>blueSlider.<span style="color: #006633;">y</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">31</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/* when the mouse is pressed check if its within the slider area (40x20)
   If the mouse is in/on a slider then set the Y value of PVector whichSlider to this value
   So we know when dragging the mouse which slider to move.
*/</span>
<span style="color: #000066; font-weight: bold;">void</span> mousePressed<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// always set to null unless the mouse is inside the  handle area</span>
    whichSlider <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span> 
    <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i<span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span>sliders.<span style="color: #006633;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>  
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>sliders<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #006633;">x</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">20</span> <span style="color: #339933;">&lt;</span> mouseX <span style="color: #339933;">&amp;&amp;</span>
            sliders<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #006633;">x</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">20</span> <span style="color: #339933;">&gt;</span> mouseX <span style="color: #339933;">&amp;&amp;</span>
            sliders<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #006633;">y</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">10</span> <span style="color: #339933;">&lt;</span> mouseY <span style="color: #339933;">&amp;&amp;</span>
            sliders<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #006633;">y</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">10</span> <span style="color: #339933;">&gt;</span> mouseY<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
              whichSlider <span style="color: #339933;">=</span> sliders<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> 
            <span style="color: #009900;">&#125;</span> 
    <span style="color: #009900;">&#125;</span>
    <span style="color: #666666; font-style: italic;">// check to see if the mouse is clicked inside the lock sliders button</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>lockSliders.<span style="color: #006633;">x</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">5</span> <span style="color: #339933;">&lt;</span> mouseX <span style="color: #339933;">&amp;&amp;</span>
        lockSliders.<span style="color: #006633;">x</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">5</span> <span style="color: #339933;">&gt;</span> mouseX <span style="color: #339933;">&amp;&amp;</span>
        lockSliders.<span style="color: #006633;">y</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">5</span> <span style="color: #339933;">&lt;</span> mouseY <span style="color: #339933;">&amp;&amp;</span>
        lockSliders.<span style="color: #006633;">y</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">5</span> <span style="color: #339933;">&gt;</span> mouseY<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
          <span style="color: #666666; font-style: italic;">// if so then check the current state and set our boolean to the opposite value</span>
          <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>locked<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
          locked <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span> 
          <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
          locked <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span>
          <span style="color: #009900;">&#125;</span>
       <span style="color: #009900;">&#125;</span> 
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/* If the mouse is pressed and the value of whichSlider is not null - it will be null if the mouse is outside the slider area.
   Then look to see if the mouseY is in range, so we dont want it to exceed a scale of 255
   Then look to see if the sliders are locked, if they are then set all sliders to the mouse Y
*/</span>
<span style="color: #000066; font-weight: bold;">void</span> mouseDragged<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>whichSlider <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> 
    <span style="color: #009900;">&#123;</span> 
        <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>mouseY <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">30</span> <span style="color: #339933;">&amp;&amp;</span> mouseY <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">287</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
          <span style="color: #666666; font-style: italic;">// set the Y value of the slider</span>
          <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>locked<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            whichSlider.<span style="color: #006633;">y</span> <span style="color: #339933;">=</span> mouseY<span style="color: #339933;">;</span> 
          <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i<span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span><span style="color: #cc66cc;">3</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
              sliders<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #006633;">y</span> <span style="color: #339933;">=</span> mouseY<span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
          <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>   
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/* following gradient code taken from:
   http://processing.org/learning/basics/lineargradient.html
*/</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">void</span> setGradient<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> x, <span style="color: #000066; font-weight: bold;">int</span> y, <span style="color: #000066; font-weight: bold;">float</span> w, <span style="color: #000066; font-weight: bold;">float</span> h, color c1, color c2, <span style="color: #000066; font-weight: bold;">int</span> axis <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;">// calculate differences between color components </span>
  <span style="color: #000066; font-weight: bold;">float</span> deltaR <span style="color: #339933;">=</span> red<span style="color: #009900;">&#40;</span>c2<span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span>red<span style="color: #009900;">&#40;</span>c1<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">float</span> deltaG <span style="color: #339933;">=</span> green<span style="color: #009900;">&#40;</span>c2<span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span>green<span style="color: #009900;">&#40;</span>c1<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">float</span> deltaB <span style="color: #339933;">=</span> blue<span style="color: #009900;">&#40;</span>c2<span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span>blue<span style="color: #009900;">&#40;</span>c1<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// choose axis</span>
  <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>axis <span style="color: #339933;">==</span> Y_AXIS<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">/*nested for loops set pixels
     in a basic table structure */</span>
    <span style="color: #666666; font-style: italic;">// column</span>
    <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i<span style="color: #339933;">=</span>x<span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;=</span><span style="color: #009900;">&#40;</span>x<span style="color: #339933;">+</span>w<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      <span style="color: #666666; font-style: italic;">// row</span>
      <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> j <span style="color: #339933;">=</span> y<span style="color: #339933;">;</span> j<span style="color: #339933;">&lt;=</span><span style="color: #009900;">&#40;</span>y<span style="color: #339933;">+</span>h<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> j<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        color c <span style="color: #339933;">=</span> color<span style="color: #009900;">&#40;</span>
        <span style="color: #009900;">&#40;</span>red<span style="color: #009900;">&#40;</span>c1<span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #009900;">&#40;</span>j<span style="color: #339933;">-</span>y<span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #009900;">&#40;</span>deltaR<span style="color: #339933;">/</span>h<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>,
        <span style="color: #009900;">&#40;</span>green<span style="color: #009900;">&#40;</span>c1<span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #009900;">&#40;</span>j<span style="color: #339933;">-</span>y<span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #009900;">&#40;</span>deltaG<span style="color: #339933;">/</span>h<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>,
        <span style="color: #009900;">&#40;</span>blue<span style="color: #009900;">&#40;</span>c1<span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #009900;">&#40;</span>j<span style="color: #339933;">-</span>y<span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #009900;">&#40;</span>deltaB<span style="color: #339933;">/</span>h<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> 
          <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        set<span style="color: #009900;">&#40;</span>i, j, c<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>  
  <span style="color: #009900;">&#125;</span>  
  <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>axis <span style="color: #339933;">==</span> X_AXIS<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// column </span>
    <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i<span style="color: #339933;">=</span>y<span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;=</span><span style="color: #009900;">&#40;</span>y<span style="color: #339933;">+</span>h<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      <span style="color: #666666; font-style: italic;">// row</span>
      <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> j <span style="color: #339933;">=</span> x<span style="color: #339933;">;</span> j<span style="color: #339933;">&lt;=</span><span style="color: #009900;">&#40;</span>x<span style="color: #339933;">+</span>w<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> j<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        color c <span style="color: #339933;">=</span> color<span style="color: #009900;">&#40;</span>
        <span style="color: #009900;">&#40;</span>red<span style="color: #009900;">&#40;</span>c1<span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #009900;">&#40;</span>j<span style="color: #339933;">-</span>x<span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #009900;">&#40;</span>deltaR<span style="color: #339933;">/</span>h<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>,
        <span style="color: #009900;">&#40;</span>green<span style="color: #009900;">&#40;</span>c1<span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #009900;">&#40;</span>j<span style="color: #339933;">-</span>x<span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #009900;">&#40;</span>deltaG<span style="color: #339933;">/</span>h<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>,
        <span style="color: #009900;">&#40;</span>blue<span style="color: #009900;">&#40;</span>c1<span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #009900;">&#40;</span>j<span style="color: #339933;">-</span>x<span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #009900;">&#40;</span>deltaB<span style="color: #339933;">/</span>h<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> 
          <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        set<span style="color: #009900;">&#40;</span>j, i, c<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>  
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><object type="application/x-shockwave-flash" width="400" height="300" data="http://www.flickr.com/apps/video/stewart.swf?v=71377" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"><param name="flashvars" value="intl_lang=en-us&#038;photo_secret=7813ce9a2b&#038;photo_id=4211433970"></param><param name="movie" value="http://www.flickr.com/apps/video/stewart.swf?v=71377"></param><param name="bgcolor" value="#000000"></param><param name="allowFullScreen" value="true"></param><embed type="application/x-shockwave-flash" src="http://www.flickr.com/apps/video/stewart.swf?v=71377" bgcolor="#000000" allowfullscreen="true" flashvars="intl_lang=en-us&#038;photo_secret=7813ce9a2b&#038;photo_id=4211433970" height="300" width="400"></embed></object><br/><br/></p>
<p style="text-align: justify;"><strong>Visualisation Two: RGB Triangle</strong><br />
A bit more complex we have  triangle this time to control the mixing of colours/ setting of values &#8211; it works the same way pretty much as the first one. The only real difference is how the mouse is detected and movement is limited to a triangle. You can download the sketch <a href="http://luckylarry.co.uk/code/RGB_Triangle/larrys_RGB_triangle.pde">here</a> and try out the application below. Like the previous sketch the downloadable version has the serial port code commented out so it will work in this webpage. Do a find and replace to change //myPort to myPort and that should sort it out.</p>
<div align="center"><object classid="java:larrys_RGB_triangle.class" type="application/x-java-applet" archive="http://luckylarry.co.uk/code/RGB_Triangle/larrys_RGB_triangle.jar,http://luckylarry.co.uk/code/RGB_Triangle/RXTXcomm.jar,http://luckylarry.co.uk/code/RGB_Triangle/serial.jar,http://luckylarry.co.uk/code/RGB_Triangle/core.jar" width="305" height="271" standby="Loading Processing software..." ><param name="archive" value="http://luckylarry.co.uk/code/RGB_Triangle/larrys_RGB_triangle.jar,http://luckylarry.co.uk/code/RGB_Triangle/RXTXcomm.jar,http://luckylarry.co.uk/code/RGB_Triangle/serial.jar,http://luckylarry.co.uk/code/RGB_Triangle/core.jar" />param name=&#8221;mayscript&#8221; value=&#8221;true&#8221; /><param name="scriptable" value="true" /><param name="image" value="http://luckylarry.co.uk/code/RGB_Triangle/loading.gif" /><param name="boxmessage" value="Loading Processing software..." /><param name="boxbgcolor" value="#FFFFFF" /><param name="test_string" value="outer" /></object></div>
<p style="text-align: justify;">

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">/*
    Code by Lucky Larry: www.luckylarry.co.uk
&nbsp;
    RGB visualisation to control LED's by dragging shapes to define colour
    Copyright (C) 2009 Pete Dainty aka 'Lucky Larry'
&nbsp;
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.
&nbsp;
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
&nbsp;
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see &lt;http://www.gnu.org/licenses/&gt;.
*/</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// import the serial library to allow us to send data via the serial ports (USB in this case)</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">processing.serial.*</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// create a new instance of the serial classes and assign it to 'myPort'</span>
Serial myPort<span style="color: #339933;">;</span> 
<span style="color: #666666; font-style: italic;">// create set of variables to store vector infomation (X nd Y co-oordinates)</span>
PVector areaPointA,areaPointB,areaPointC,pointA,pointB,pointC,pointDrag<span style="color: #339933;">;</span> 
<span style="color: #666666; font-style: italic;">// create an arry to store the vectors of each point of our shape in this case a triangle</span>
PVector<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> rgbTriangle<span style="color: #339933;">;</span> 
<span style="color: #666666; font-style: italic;">/* the next 3 lines uses a custom class at the bottom of this code.
   the class extends java.awt.polygon which means I can use this to create a triangle to test if the
   mouse is in side the shape. */</span>
<span style="color: #666666; font-style: italic;">// new instance of our class</span>
DragArea area<span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// these lines specify the X value and Y value for each point of our triangle {xpoint1, xpoint2, xpoint3} etc..</span>
<span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span>xpoints<span style="color: #339933;">=</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">152</span>,<span style="color: #cc66cc;">23</span>,<span style="color: #cc66cc;">284</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span> 
<span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span>ypoints<span style="color: #339933;">=</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">23</span>,<span style="color: #cc66cc;">248</span>,<span style="color: #cc66cc;">248</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// set 3 variables to store the colour values.</span>
<span style="color: #000066; font-weight: bold;">int</span> R, G, B<span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// setup our font</span>
PFont myFont<span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">/* setup our background and variables */</span>
<span style="color: #000066; font-weight: bold;">void</span> setup <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
    <span style="color: #666666; font-style: italic;">// screen size</span>
    size<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">305</span>,<span style="color: #cc66cc;">271</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>     
    <span style="color: #666666; font-style: italic;">// setup my font type and size </span>
    myFont <span style="color: #339933;">=</span> createFont<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;verdana&quot;</span>, <span style="color: #cc66cc;">12</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    textFont<span style="color: #009900;">&#40;</span>myFont<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// define our new instance of the custom class. (X points, Y points, Number of points in the shape) more info below by the class</span>
    area <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> DragArea<span style="color: #009900;">&#40;</span>xpoints,ypoints,<span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// define the area vectors - we use these to see how far our point is from its original source, needed to calculate the value between 0 and 255</span>
    areaPointA <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> PVector<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">152</span>,<span style="color: #cc66cc;">25</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
    areaPointB <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> PVector<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">25</span>,<span style="color: #cc66cc;">246</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
    areaPointC <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> PVector<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">280</span>,<span style="color: #cc66cc;">246</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
    <span style="color: #666666; font-style: italic;">// specifiy the starting co-ordinates for the triangle that we can move</span>
    pointA <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> PVector<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">152</span>,<span style="color: #cc66cc;">40</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
    pointB <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> PVector<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">40</span>,<span style="color: #cc66cc;">230</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
    pointC <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> PVector<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">265</span>,<span style="color: #cc66cc;">230</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
    <span style="color: #666666; font-style: italic;">// set the array with the new points.</span>
    rgbTriangle <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> PVector<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#123;</span>pointA,pointB,pointC<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span> 
    <span style="color: #666666; font-style: italic;">// center our shapes</span>
    ellipseMode<span style="color: #009900;">&#40;</span>CENTER<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    rectMode<span style="color: #009900;">&#40;</span>CENTER<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
    <span style="color: #666666; font-style: italic;">// set smoothing for our shapes edges</span>
    smooth<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
    <span style="color: #666666; font-style: italic;">/* define which port to use mine is COM10 and is 2nd in the array list.
       you can print out to the screen which ports are accessible by using this code line below
       set the baud rate to the same as in your Arduino code so mine is 9600
    */</span>
    <span style="color: #666666; font-style: italic;">// println(Serial.list()); </span>
    myPort <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Serial<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>, Serial.<span style="color: #006633;">list</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span>, <span style="color: #cc66cc;">9600</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// end setup</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/* begin our animation/ interaction */</span>
<span style="color: #000066; font-weight: bold;">void</span> draw <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
    <span style="color: #666666; font-style: italic;">// set background to black</span>
    background<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">50</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// set the colours and positions of the large colour circles to indentify where red is 100% etc...</span>
    <span style="color: #666666; font-style: italic;">// fill(R, G, B);</span>
    fill<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">255</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// ellipse(X co-ordinate, Y co-ordinate,width, height)</span>
    ellipse<span style="color: #009900;">&#40;</span>areaPointA.<span style="color: #006633;">x</span>, areaPointA.<span style="color: #006633;">y</span>, <span style="color: #cc66cc;">15</span>,<span style="color: #cc66cc;">15</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    fill<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">255</span>,<span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    ellipse<span style="color: #009900;">&#40;</span>areaPointB.<span style="color: #006633;">x</span>, areaPointB.<span style="color: #006633;">y</span>, <span style="color: #cc66cc;">15</span>,<span style="color: #cc66cc;">15</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    fill<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">255</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    ellipse<span style="color: #009900;">&#40;</span>areaPointC.<span style="color: #006633;">x</span>, areaPointC.<span style="color: #006633;">y</span>, <span style="color: #cc66cc;">15</span>,<span style="color: #cc66cc;">15</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
    <span style="color: #666666; font-style: italic;">// create our background triangle to show the area in which we can move.</span>
    fill<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">100</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    beginShape<span style="color: #009900;">&#40;</span>TRIANGLES<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
      vertex<span style="color: #009900;">&#40;</span>areaPointA.<span style="color: #006633;">x</span>,areaPointA.<span style="color: #006633;">y</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
      vertex<span style="color: #009900;">&#40;</span>areaPointB.<span style="color: #006633;">x</span>,areaPointB.<span style="color: #006633;">y</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
      vertex<span style="color: #009900;">&#40;</span>areaPointC.<span style="color: #006633;">x</span>,areaPointC.<span style="color: #006633;">y</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
    endShape<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
    <span style="color: #666666; font-style: italic;">/* set the fill of our coloured triangle we work out the values by
       getting the current points co-ordinates and working out the distance
       from the original point. These distances are actually calculated on a 
       circular area so it draws an elliptical area from the origin point from 
       the 2 adjacent sides of the triangle. First set the values to our variables  
       R, G, B and round them so that they'll be integers and parse them using the int() method
    */</span>
    R <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#40;</span>round<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #339933;">-</span>dist<span style="color: #009900;">&#40;</span>areaPointA.<span style="color: #006633;">x</span>,areaPointA.<span style="color: #006633;">y</span>,pointA.<span style="color: #006633;">x</span>,pointA.<span style="color: #006633;">y</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    G <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#40;</span>round<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #339933;">-</span>dist<span style="color: #009900;">&#40;</span>areaPointB.<span style="color: #006633;">x</span>,areaPointB.<span style="color: #006633;">y</span>,pointB.<span style="color: #006633;">x</span>,pointB.<span style="color: #006633;">y</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    B <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#40;</span>round<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #339933;">-</span>dist<span style="color: #009900;">&#40;</span>areaPointC.<span style="color: #006633;">x</span>,areaPointC.<span style="color: #006633;">y</span>,pointC.<span style="color: #006633;">x</span>,pointC.<span style="color: #006633;">y</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    fill<span style="color: #009900;">&#40;</span>R,G,B<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">/* we need to send this fill value to the Arduino to light up the LED's accordingly
       we do this by writing a value to the serial port.
       You can write values to the serial port using bytes, integers and chars.
       I'm going to send the 3 values separately and store them in an array on the Arduino
    */</span>
    myPort.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span>R<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    myPort.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span>G<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    myPort.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span>B<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
    <span style="color: #666666; font-style: italic;">// create our RGB triangle from the draggable points</span>
    beginShape<span style="color: #009900;">&#40;</span>TRIANGLES<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
      vertex<span style="color: #009900;">&#40;</span>pointA.<span style="color: #006633;">x</span>,pointA.<span style="color: #006633;">y</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
      vertex<span style="color: #009900;">&#40;</span>pointB.<span style="color: #006633;">x</span>,pointB.<span style="color: #006633;">y</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
      vertex<span style="color: #009900;">&#40;</span>pointC.<span style="color: #006633;">x</span>,pointC.<span style="color: #006633;">y</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
    endShape<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
    <span style="color: #666666; font-style: italic;">// create the drag handles for each point in the draggable shape.</span>
    <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i<span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span>rgbTriangle.<span style="color: #006633;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #666666; font-style: italic;">// switch on the for loop iterator to change the fill colour depending on the point</span>
      <span style="color: #000000; font-weight: bold;">switch</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">case</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">:</span> 
          fill<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">255</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">case</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">:</span> 
          fill<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">255</span>,<span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">case</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">:</span> 
          fill<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">255</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
      <span style="color: #666666; font-style: italic;">// draw our handle at the point of each triangle</span>
      ellipse<span style="color: #009900;">&#40;</span>rgbTriangle<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #006633;">x</span>,rgbTriangle<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #006633;">y</span>,<span style="color: #cc66cc;">5</span>,<span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>  
    <span style="color: #666666; font-style: italic;">// create our text to show the value of the colour inside the triangle</span>
    fill<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">150</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    text<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Red: &quot;</span><span style="color: #339933;">+</span><span style="color: #003399;">Integer</span>.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span>R<span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span>
    <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>Green: &quot;</span><span style="color: #339933;">+</span><span style="color: #003399;">Integer</span>.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span>G<span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span>
    <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>Blue: &quot;</span><span style="color: #339933;">+</span><span style="color: #003399;">Integer</span>.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span>B<span style="color: #009900;">&#41;</span>, 
    <span style="color: #cc66cc;">120</span>, <span style="color: #cc66cc;">50</span>, <span style="color: #cc66cc;">200</span>, <span style="color: #cc66cc;">75</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
<span style="color: #009900;">&#125;</span> 
&nbsp;
<span style="color: #666666; font-style: italic;">/* when the mouse is pressed check if its within the drag handle give or take 5 pixels either way
   If the mouse is in/on a handle then set the X and Y value of PVector pointDrag to these values
   So we know when dragging the mouse which point to set.
*/</span>
<span style="color: #000066; font-weight: bold;">void</span> mousePressed <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
    <span style="color: #666666; font-style: italic;">// always set to null unless the mouse is inside the  handle area</span>
    pointDrag <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span> 
    <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i<span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span>rgbTriangle.<span style="color: #006633;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>  
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>rgbTriangle<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #006633;">x</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">5</span> <span style="color: #339933;">&lt;</span> mouseX <span style="color: #339933;">&amp;&amp;</span>
            rgbTriangle<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #006633;">x</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">5</span> <span style="color: #339933;">&gt;</span> mouseX <span style="color: #339933;">&amp;&amp;</span>
            rgbTriangle<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #006633;">y</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">5</span> <span style="color: #339933;">&lt;</span> mouseY <span style="color: #339933;">&amp;&amp;</span>
            rgbTriangle<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #006633;">y</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">5</span> <span style="color: #339933;">&gt;</span> mouseY<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
              pointDrag <span style="color: #339933;">=</span> rgbTriangle<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> 
            <span style="color: #009900;">&#125;</span> 
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span> 
&nbsp;
<span style="color: #666666; font-style: italic;">/* If the mouse is pressed and the value of pointDrag is not null - it will be null if the mouse is outside the handle area.
   We then do another check to see if our mouse pointer is inside our polygon area. In Processing we can use the .contains() method
   that we get from the custom class at the bottom to check if an XY value is inside the polygons area.
*/</span>
<span style="color: #000066; font-weight: bold;">void</span> mouseDragged<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> pointDrag <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #009900;">&#41;</span> 
    <span style="color: #009900;">&#123;</span> 
      <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>area.<span style="color: #006633;">contains</span><span style="color: #009900;">&#40;</span>mouseX,mouseY<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// set the XY values of the point we're dragging to the values of the mouse</span>
        pointDrag.<span style="color: #006633;">x</span> <span style="color: #339933;">=</span> mouseX<span style="color: #339933;">;</span> 
        pointDrag.<span style="color: #006633;">y</span> <span style="color: #339933;">=</span> mouseY<span style="color: #339933;">;</span> 
      <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span> 
<span style="color: #009900;">&#125;</span> 
&nbsp;
<span style="color: #666666; font-style: italic;">/* This doesnt look like much code but what we're doing is extending a class with another class.
   By extending our class with java.awt.Polygon we then inherit that classes methods to use as our own.
   Since Processing is based upon Java there are many classes that we can import to extend Processing.
   The functions of java.awt.Polygon can be found here: http://java.sun.com/j2se/1.4.2/docs/api/java/awt/Polygon.html
   This makes it much easier to do collision detection with shapes - Processing can handle rectangles and circles fine
   but for triangles this saves alot of effort.
*/</span>
<span style="color: #000000; font-weight: bold;">class</span> DragArea <span style="color: #000000; font-weight: bold;">extends</span> java.<span style="color: #006633;">awt</span>.<span style="color: #003399;">Polygon</span> <span style="color: #009900;">&#123;</span> 
  <span style="color: #666666; font-style: italic;">/* our DragArea class is basically an instance of java.awt.Polygons and this class expects and array of X points, Y points and the number of 
     points in our shape. The variable names also have to be direct references to what this class expects, so xpoints, ypoints and npoints are all
     set/defined in the java class.
  */</span>
  <span style="color: #000000; font-weight: bold;">public</span> DragArea<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> xpoints,<span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> ypoints, <span style="color: #000066; font-weight: bold;">int</span> npoints<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// super invokes the java.awt.Polygon class</span>
    <span style="color: #000000; font-weight: bold;">super</span><span style="color: #009900;">&#40;</span>xpoints,ypoints,npoints<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span> 
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><object type="application/x-shockwave-flash" width="400" height="300" data="http://www.flickr.com/apps/video/stewart.swf?v=71377" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"><param name="flashvars" value="intl_lang=en-us&#038;photo_secret=802c042b3c&#038;photo_id=4211404646"></param><param name="movie" value="http://www.flickr.com/apps/video/stewart.swf?v=71377"></param><param name="bgcolor" value="#000000"></param><param name="allowFullScreen" value="true"></param><embed type="application/x-shockwave-flash" src="http://www.flickr.com/apps/video/stewart.swf?v=71377" bgcolor="#000000" allowfullscreen="true" flashvars="intl_lang=en-us&#038;photo_secret=802c042b3c&#038;photo_id=4211404646" height="300" width="400"></embed></object></p>
<hr /><small>Copyright &copy; 2009<br /> This feed is for personal, non-commercial use only. <br /> The use of this feed on other websites breaches copyright. If this content is not in your news reader, it makes the page you are viewing an infringement of the copyright. (Digital Fingerprint:<br /> 0f170a4373044c85a96d646f719885c6)</small>

<p>Related posts:<ol><li><a href='http://luckylarry.co.uk/2010/02/arduino-modifying-a-robot-arm-part-2/' rel='bookmark' title='Permanent Link: Arduino: Controlling the Robot Arm'>Arduino: Controlling the Robot Arm</li><li><a href='http://luckylarry.co.uk/2009/06/3-led-crossfade-with-pwm-and-arduino/' rel='bookmark' title='Permanent Link: 3 LED Crossfade with PWM and Arduino'>3 LED Crossfade with PWM and Arduino</li><li><a href='http://luckylarry.co.uk/2009/08/arduino-processing-getting-values-from-srf05-ultrasound-sensor-serial-port/' rel='bookmark' title='Permanent Link: Arduino + Processing: Getting values from SRF05 ultrasound sensor &#038; serial port'>Arduino + Processing: Getting values from SRF05 ultrasound sensor &#038; serial port</li></ol></p>
<p><a href="http://feedads.g.doubleclick.net/~a/U0z_WvrVl4h-DYDofPhMKrWYmf8/0/da"><img src="http://feedads.g.doubleclick.net/~a/U0z_WvrVl4h-DYDofPhMKrWYmf8/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/U0z_WvrVl4h-DYDofPhMKrWYmf8/1/da"><img src="http://feedads.g.doubleclick.net/~a/U0z_WvrVl4h-DYDofPhMKrWYmf8/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/LuckyLarry/~4/PGmIV3CfsL8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://luckylarry.co.uk/2009/12/using-processing-to-send-values-to-arduino/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		<feedburner:origLink>http://luckylarry.co.uk/2009/12/using-processing-to-send-values-to-arduino/</feedburner:origLink></item>
	</channel>
</rss>
