<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-9137329968204240224</id><updated>2024-08-28T21:09:13.948-03:00</updated><category term="lego"/><category term="nxc"/><category term="robot"/><title type='text'>CompSpot</title><subtitle type='html'>This is my geek spot where I, André Oriani, share my new discoveries on Computing, Software Development, Android, Photography, Philosophy  and whatever comes to my mind.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://aoriani.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9137329968204240224/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://aoriani.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/08214765587656957936</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>10</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-9137329968204240224.post-2274712937368552164</id><published>2015-12-28T02:22:00.001-02:00</published><updated>2015-12-28T02:34:09.321-02:00</updated><title type='text'>Is this blog dead ? </title><content type='html'>Well... &amp;nbsp;Kinda.&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEimlIU2NTxs3tj5MsDP7lPQ_ixLS4jW5VycaigWJooSGHdpuQl2J4SfzSYwZwryiBbzSGa4yEU2vYQoVEtdPCS0wGNgn5-4ctS1ryJqSIbJoQ4cs-y3THmoaZekavwb_RQlQZVxW6wM7zQ/s1600/DSC00712.JPG&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;240&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEimlIU2NTxs3tj5MsDP7lPQ_ixLS4jW5VycaigWJooSGHdpuQl2J4SfzSYwZwryiBbzSGa4yEU2vYQoVEtdPCS0wGNgn5-4ctS1ryJqSIbJoQ4cs-y3THmoaZekavwb_RQlQZVxW6wM7zQ/s320/DSC00712.JPG&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;My last post is dated from more than 2 years. A lot had happened since it. One week later I was spending three weeks on San Bruno, CA, because I have just joined the Android team from @WalmartLabs. Three weeks in which I had to learn as much as I could because I would have to work remotely from Brazil until they figure out my visa. &amp;nbsp;The timezone difference was 6 hours and they picked me to work on the implementation of the new Pharmacy section of the Walmart app. &amp;nbsp;A very high heat project which last 6 months. In the beginning the web services were very unreliable. I could easily waste many working hours because the service would crash after the fifth request and I would have to wait until someone in San Bruno was awake to restart the machine. Summing up, I worked 24x7, including weekends to compensate the fact that I was remote.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh5Dei9OB6J5xyeuLhQAZy3W3BPiXq5s6xLcx39qk9xatBoBNg-Tz9hWi4n_y68hYvWhEahvgcluWTi9-oJmrqhU52zH381b279Q9yLchL4Cd7innRYTqzhxYRVOFImHYcQpTMpSchJKzo/s1600/IMG_20150527_105539.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: right; float: right; margin-bottom: 1em; margin-left: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;300&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh5Dei9OB6J5xyeuLhQAZy3W3BPiXq5s6xLcx39qk9xatBoBNg-Tz9hWi4n_y68hYvWhEahvgcluWTi9-oJmrqhU52zH381b279Q9yLchL4Cd7innRYTqzhxYRVOFImHYcQpTMpSchJKzo/s400/IMG_20150527_105539.jpg&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
Then on November 1st I moved to California. Mixed emotions so far : fulfilled my dream of working on Silicon Valley, &amp;nbsp;Sunny California is a nice place to live, gadgets at reasonable prices, but at the same time struggling to find a place to rent at somewhat comfortable price, buying furniture and a car, taking the Californian drive license and getting used to drive a car around, &amp;nbsp;dealing with loneliness, a huge life cost, and constant reorgs. &amp;nbsp;A &amp;nbsp;lot of stress and anxiety that prevent me from really enjoying the opportunity. With 2016 in the proximities, I hope to change that, put my face back on the bookies, developing my side projects and post more here. &lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjBkGlyuUOmaATLjIBnLe6fktoZh9-emb4oIRaP2ZPQFkNriwGZyEnUK0oi8nckqxtt6UzRAzTK7vk57qGz_Sjqx_mJRBqVwhb04ETQ_Yxon6_TKXpoqXmCwEiHbx1YHTKyk78GTMNTBEg/s1600/IMG_20150919_194921.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjBkGlyuUOmaATLjIBnLe6fktoZh9-emb4oIRaP2ZPQFkNriwGZyEnUK0oi8nckqxtt6UzRAzTK7vk57qGz_Sjqx_mJRBqVwhb04ETQ_Yxon6_TKXpoqXmCwEiHbx1YHTKyk78GTMNTBEg/s320/IMG_20150919_194921.jpg&quot; width=&quot;240&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
Although I didn&#39;t post in this blog, I post anything that I found interesting on my Google Plus profile. So check &lt;a href=&quot;https://plus.google.com/+AndreOriani&quot;&gt;https://plus.google.com/+AndreOriani&lt;/a&gt; and if you are interested on Android follow my &lt;a href=&quot;https://plus.google.com/collection/4cybW&quot;&gt;Android Collection&lt;/a&gt;. &lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://aoriani.blogspot.com/feeds/2274712937368552164/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aoriani.blogspot.com/2015/12/is-this-blog-dead.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9137329968204240224/posts/default/2274712937368552164'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9137329968204240224/posts/default/2274712937368552164'/><link rel='alternate' type='text/html' href='http://aoriani.blogspot.com/2015/12/is-this-blog-dead.html' title='Is this blog dead ? '/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/08214765587656957936</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEimlIU2NTxs3tj5MsDP7lPQ_ixLS4jW5VycaigWJooSGHdpuQl2J4SfzSYwZwryiBbzSGa4yEU2vYQoVEtdPCS0wGNgn5-4ctS1ryJqSIbJoQ4cs-y3THmoaZekavwb_RQlQZVxW6wM7zQ/s72-c/DSC00712.JPG" height="72" width="72"/><thr:total>0</thr:total><georss:featurename>San Bruno, CA, USA</georss:featurename><georss:point>37.6304904 -122.41108350000002</georss:point><georss:box>37.5801839 -122.49176450000002 37.6807969 -122.33040250000002</georss:box></entry><entry><id>tag:blogger.com,1999:blog-9137329968204240224.post-497438828112138074</id><published>2013-08-03T23:46:00.000-03:00</published><updated>2013-08-06T15:45:20.020-03:00</updated><title type='text'>So you think you can program?</title><content type='html'>&lt;div style=&quot;text-align: justify;&quot;&gt;
A big mistake that I did when I began my internship a long time ago was to think that knowing a programming language, its syntax, and its standard libraries were suffice. How ingenious I was! &amp;nbsp;As soon as start talking to experienced programmers that something else was needed to grasp the &lt;i&gt;&quot;The Art of Computer Programming&quot; &lt;/i&gt;(after all those years I cannot help to agree more with Donald Knuth that programming is an art).&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
A graduation course on Computing is focused in teaching on how to solve problems in&amp;nbsp; effectively and efficiently way. &amp;nbsp;It is going to teach you one or more programming languages in order to illustrate &amp;nbsp;the concepts and only for that reason. In my case Pascal was used to introduce Algorithms, C++ for OOP and Operating System Concepts, SQL for Databases, and Lisp and Prolog for functional and logic programming respectively.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
But Programming in way that is readable to others, maintainable, efficiently and less prone to bugs is something that you learn in your&amp;nbsp; daily practice by failing&amp;nbsp; or by listening to more experienced programmers. Here is a list of books that I recommend reading. Most of them are on my pending list, but I hope to mend it soon as I finish my Masters.&amp;nbsp; &lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;
&lt;h2&gt;







Programming Style and Attitude&lt;/h2&gt;
&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEghX4ofm6W-TxmyaVyh33MNC2SM_Oef71-DBUG0et6obQDFm91bp1WAxPahpUtxF5Rz7LAb92G9gCcmc5NXcolBwCZBFgLDbUMzpSEIE_sjn9Pa2JcBtdFFfuQ3ReE4FFDj0nsmjzLpHfE/s1600/cc2e-cover-small.gif&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEghX4ofm6W-TxmyaVyh33MNC2SM_Oef71-DBUG0et6obQDFm91bp1WAxPahpUtxF5Rz7LAb92G9gCcmc5NXcolBwCZBFgLDbUMzpSEIE_sjn9Pa2JcBtdFFfuQ3ReE4FFDj0nsmjzLpHfE/s1600/cc2e-cover-small.gif&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;b&gt;&lt;a href=&quot;http://www.amazon.com/Code-Complete-Practical-Handbook-Construction/dp/0735619670&quot; target=&quot;_blank&quot;&gt;Code Complete&lt;/a&gt; &lt;i&gt;by&amp;nbsp;Steve Mcconnell&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
During graduation I was presented to the Software Engineering text books written by Pressman and Somerville. That make thought&amp;nbsp; that doing good software was a simple task. It was just a matter of having a good, well documented and dogmatic process and everything would be fine. This book showed me the light.&amp;nbsp; The success for a software project depend on the quality and attitude of the developer team. This books teaches about good code style and practices, truths about software development and programmer ethics.&lt;br /&gt;
This a mandatory reading&amp;nbsp; for sure!&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px; text-align: left;&quot;&gt;
&lt;b&gt;&lt;a href=&quot;http://www.amazon.com/Clean-Code-Handbook-Software-Craftsmanship/dp/0132350882&quot; target=&quot;_blank&quot;&gt;Clean Code&lt;/a&gt; &lt;i&gt;by Robert C Martin&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiVNhrHLZswl-doaJ9LwzEfx1UwjOqcHu4gIKGKd4yJaDwjDiRL63qQB2Z4Hz0UoFi7x1f96s758T0nU_w9ScsqhA_XKESE0b_qEzbLCRtODpMPKQsdvak659zR1gyt_pq5wBY8kidIavo/s1600/cleancode.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;200&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiVNhrHLZswl-doaJ9LwzEfx1UwjOqcHu4gIKGKd4yJaDwjDiRL63qQB2Z4Hz0UoFi7x1f96s758T0nU_w9ScsqhA_XKESE0b_qEzbLCRtODpMPKQsdvak659zR1gyt_pq5wBY8kidIavo/s200/cleancode.jpg&quot; width=&quot;150&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
It is on my queue. I&#39;ve just read until the beginning of the 2nd chapter. But it is clearly a good book about coding style. It comes &amp;nbsp;with tons of code to be read. The author presents why it is wrong&amp;nbsp;&amp;nbsp;and how would it be better rewritten.&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h2&gt;



Object Oriented Programming&lt;/h2&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://kelsoncm.com/tic/wp-content/uploads/2010/10/design-patterns-book-cover.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;200&quot; src=&quot;http://kelsoncm.com/tic/wp-content/uploads/2010/10/design-patterns-book-cover.png&quot; width=&quot;152&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;b&gt;&lt;a href=&quot;http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612/ref=sr_1_1?s=books&amp;amp;ie=UTF8&amp;amp;qid=1333773630&amp;amp;sr=1-1&quot; target=&quot;_blank&quot;&gt;Design Patterns&lt;/a&gt; &lt;i&gt;by GoF&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
If you think OOP is just about inheritance, polymorphism and composition, you are very mistaken. &amp;nbsp;Design Patterns are clever solutions to common problems that appear during design. However, they are more than just recipes or how-to&#39;s. Learning the patterns really teaches you to efficiently use the power of OOP. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://martinfowler.com/refactoringBook.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;200&quot; src=&quot;http://martinfowler.com/refactoringBook.jpg&quot; width=&quot;156&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;b&gt;&lt;a href=&quot;http://www.amazon.com/Refactoring-Improving-Design-Existing-Code/dp/0201485672/ref=sr_1_1?s=books&amp;amp;ie=UTF8&amp;amp;qid=1333774542&amp;amp;sr=1-1&quot; target=&quot;_blank&quot;&gt;Refactoring&lt;/a&gt; &lt;i&gt;by Martin Fowler&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
You create some good design. Then you code. It is wonderful. Then you see a bug, and fix it. Then you add one more feature. Then another bug fix. You code start deteriorating, &quot;smelling&quot; &amp;nbsp;Martin Fowler would say. &amp;nbsp;This book is about reverting the game.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;



Design of Algorithms&lt;/h2&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://www.vafaeijahan.com/en/wp-content/uploads/2012/03/Book-Jeld.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;200&quot; src=&quot;http://www.vafaeijahan.com/en/wp-content/uploads/2012/03/Book-Jeld.jpg&quot; width=&quot;176&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;a href=&quot;http://www.blogger.com/&quot;&gt;&lt;span id=&quot;goog_301592627&quot;&gt;&lt;/span&gt;Introduction to Algorithms&lt;span id=&quot;goog_301592628&quot;&gt;&lt;/span&gt;&lt;/a&gt; &lt;i&gt;by Cormen et al.&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/b&gt;
&lt;b&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/b&gt;
This is the book about algorithms. If you had done any serious CS course you have already heard of it.&lt;br /&gt;
&lt;br /&gt;
By the way, &amp;nbsp;Professor Leiserson&#39;s lectures, one of authors of the book are available on the &lt;a href=&quot;http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-046j-introduction-to-algorithms-sma-5503-fall-2005/&quot; target=&quot;_blank&quot;&gt;MIT OpenCourseWare&amp;nbsp;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;


Effective Series&lt;/h2&gt;
&lt;/div&gt;
&lt;div&gt;
You must be able to solve a problem independently of the programming language. You must also be able to choose the language according to the problem. If you are doing kernel programming you are probably gonna use C. But you are gonna use Python or &amp;nbsp;Java for an user application. &amp;nbsp;Anyway, once you choose the language you ought to know how to use it efficiently&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://www.amazon.com/Effective-Specific-Improve-Programs-Designs/dp/0321334876/ref=sr_1_1?s=books&amp;amp;ie=UTF8&amp;amp;qid=1333852476&amp;amp;sr=1-1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot; target=&quot;_blank&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;200&quot; src=&quot;http://photo.goodreads.com/books/1171537538l/105125.jpg&quot; width=&quot;158&quot; /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;-webkit-text-decorations-in-effect: none; color: black;&quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;a href=&quot;http://www.amazon.com/Effective-Java-Edition-Joshua-Bloch/dp/0321356683/ref=sr_1_1?s=books&amp;amp;ie=UTF8&amp;amp;qid=1333852691&amp;amp;sr=1-1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot; target=&quot;_blank&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;200&quot; src=&quot;http://www.informit.com/ShowCover.aspx?isbn=020163371X&quot; width=&quot;158&quot; /&gt;&lt;/a&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;-webkit-text-decorations-in-effect: none; color: black;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;200&quot; src=&quot;http://www.informit.com/ShowCover.aspx?isbn=0321356683&quot; width=&quot;158&quot; /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://aoriani.blogspot.com/feeds/497438828112138074/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aoriani.blogspot.com/2012/04/so-you-think-you-can-program.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9137329968204240224/posts/default/497438828112138074'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9137329968204240224/posts/default/497438828112138074'/><link rel='alternate' type='text/html' href='http://aoriani.blogspot.com/2012/04/so-you-think-you-can-program.html' title='So you think you can program?'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/08214765587656957936</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEghX4ofm6W-TxmyaVyh33MNC2SM_Oef71-DBUG0et6obQDFm91bp1WAxPahpUtxF5Rz7LAb92G9gCcmc5NXcolBwCZBFgLDbUMzpSEIE_sjn9Pa2JcBtdFFfuQ3ReE4FFDj0nsmjzLpHfE/s72-c/cc2e-cover-small.gif" height="72" width="72"/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9137329968204240224.post-5274637813311034480</id><published>2013-04-13T00:13:00.001-03:00</published><updated>2013-04-13T00:23:30.216-03:00</updated><title type='text'>Simple way to access GPIO on Raspberry PI</title><content type='html'>&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhhrhZLieku-EeifCgmYkADMtx4q4LXRRHxf_llO2Vuoso8PxKW-P790zH6Y7wXmUHmB10j7io6IsnbL6Yb13kbvez7lCeyDh6q3cgzJlFRNZyZDS1k7MjEW9dFz8OPxv427ieMjR3IraI/s1600/Raspberry_Pi_Logo.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;150&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhhrhZLieku-EeifCgmYkADMtx4q4LXRRHxf_llO2Vuoso8PxKW-P790zH6Y7wXmUHmB10j7io6IsnbL6Yb13kbvez7lCeyDh6q3cgzJlFRNZyZDS1k7MjEW9dFz8OPxv427ieMjR3IraI/s200/Raspberry_Pi_Logo.png&quot; width=&quot;200&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
Got yourself a &lt;a href=&quot;http://www.raspberrypi.org/&quot; target=&quot;_blank&quot;&gt;Raspberry Pi&lt;/a&gt;&amp;nbsp;and you are using it as a cheap Linux box or &lt;a href=&quot;http://www.raspbmc.com/&quot; target=&quot;_blank&quot;&gt;Multimedia Center&lt;/a&gt;? Wanna play with electronics and interface your Pi with Arduino shields? So you have to learn how to control the GPIO (General Purpose Input Output) port of your Pi.&lt;br /&gt;
&lt;br /&gt;
If you programming in C/C++ there is &lt;a href=&quot;https://projects.drogon.net/raspberry-pi/wiringpi/&quot; target=&quot;_blank&quot;&gt;WiringPI&lt;/a&gt;. It is a library that provides an Arduino-like API. If you are using Python you can use &lt;a href=&quot;http://learn.adafruit.com/playing-sounds-and-using-buttons-with-raspberry-pi/install-python-module-rpi-dot-gpio&quot; target=&quot;_blank&quot;&gt;Adafruit&#39;s library&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
But if you do not want to install any library or if you are using another language besides C or Python? Fortunately the RPi kernel exports the GPIO pins to sysfs.&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://en.wikipedia.org/wiki/Sysfs&quot; target=&quot;_blank&quot;&gt;Sysfs&lt;/a&gt;, like the procfs, is a Linux pseudo-filesystem. It looks like regular files and directories. You can read them, write to them... But if you do a &lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;ls -l&lt;/span&gt;&amp;nbsp; you are going to see that they have zero size. When you read or write to a file, the calls are intercepted by the Linux Virtual File System layer which delivers the calls to the proper implementation of file system. So if the file is in a ext3 partition, the ext3 file system drive is called. In our case the calls are passed to the sysfs implementation which will configure the GPIO ports.&lt;br /&gt;
&lt;br /&gt;
Before telling you how to use&amp;nbsp; the GPIO pins from sysfs, let me show you a simple schematic to test the GPIO:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhaxvIzD3lsHvU3cXYnnkGBgtbLgk8W9YgmI9k0AXE1q60C63PlWN_AD8rAHg-xvJSARg-nEiS1Q8TlJ4DFTZ72QSzq5JiS_SIlzOocl4WeaoZiw0GyF9Ksh_otmbV1xpZawsT8VS7fgKA/s1600/simpleGPIO.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;504&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhaxvIzD3lsHvU3cXYnnkGBgtbLgk8W9YgmI9k0AXE1q60C63PlWN_AD8rAHg-xvJSARg-nEiS1Q8TlJ4DFTZ72QSzq5JiS_SIlzOocl4WeaoZiw0GyF9Ksh_otmbV1xpZawsT8VS7fgKA/s640/simpleGPIO.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
The pin 24 (GPIO8) is connect to the LED. The LED is connect to an 1 kilo ohms pull down resistor that will protect our LED and Pi. The resistor is connected to pin 25 (GND). I want to control whether the LED will be lit. So I need the GPIO8 to output 1 ( or 5 volts) to lit the LED.&lt;br /&gt;
&lt;br /&gt;
First we need to set GPIO8 to be a output pin. I am going to use shell script for that.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush:bash&quot;&gt;#We need to be the super user to use the gpio
sudo -i

#Set GPIO 8 to output 
echo &quot;8&quot; &amp;gt; /sys/class/gpio/export
echo &quot;out&quot; &amp;gt; /sys/class/gpio/gpio8/direction
&lt;/pre&gt;
&lt;br /&gt;
To blink the LED we just need to write ones and zeros to the GPIO8:&lt;br /&gt;
&lt;pre class=&quot;brush:bash&quot;&gt;while :
do 
    echo &quot;1&quot; &amp;gt;  /sys/class/gpio/gpio8/value
    sleep 1
    echo &quot;0&quot; &amp;gt; /sys/class/gpio/gpio8/value
    sleep 1
done
&lt;/pre&gt;
&lt;br /&gt;
One you are done you must free the pin&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush:bash&quot;&gt;echo &quot;8&quot; &amp;gt; /sys/class/gpio/unexport
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
Here is a video of how it works on real life:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;iframe allowfullscreen=&#39;allowfullscreen&#39; webkitallowfullscreen=&#39;webkitallowfullscreen&#39; mozallowfullscreen=&#39;mozallowfullscreen&#39; width=&#39;320&#39; height=&#39;266&#39; src=&#39;https://www.youtube.com/embed/sr-JmAZLvCk?feature=player_embedded&#39; frameborder=&#39;0&#39;&gt;&lt;/iframe&gt;&lt;/div&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://aoriani.blogspot.com/feeds/5274637813311034480/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aoriani.blogspot.com/2013/04/simple-way-to-access-gpio-on-raspberry.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9137329968204240224/posts/default/5274637813311034480'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9137329968204240224/posts/default/5274637813311034480'/><link rel='alternate' type='text/html' href='http://aoriani.blogspot.com/2013/04/simple-way-to-access-gpio-on-raspberry.html' title='Simple way to access GPIO on Raspberry PI'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/08214765587656957936</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhhrhZLieku-EeifCgmYkADMtx4q4LXRRHxf_llO2Vuoso8PxKW-P790zH6Y7wXmUHmB10j7io6IsnbL6Yb13kbvez7lCeyDh6q3cgzJlFRNZyZDS1k7MjEW9dFz8OPxv427ieMjR3IraI/s72-c/Raspberry_Pi_Logo.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9137329968204240224.post-2378065522372856260</id><published>2012-09-23T00:17:00.001-03:00</published><updated>2012-09-23T00:17:25.032-03:00</updated><title type='text'>Film Photography: Visita ao Zoo</title><content type='html'>&lt;br /&gt;
Filme é coisa do passado, certo? Mais ou menos. Algumas pessoas ainda insistem no filme. Não é tão fácil como antigamente, mas em Piracicaba, minha cidade natal, conheço dois lugares que ainda revelam filmes coloridos. É possível comprar filmes nas lojas de fotografia, mas comprar no Ebay sai muito mais barato. Há também&amp;nbsp; a moda da Lomografia, mas não vou falar dela aqui.&lt;br /&gt;
&lt;br /&gt;
Film photography&amp;nbsp; is dead, right. I would not be so sure. Some people still prefer analogic photograpy. It is not so easy to find photo shops which are still&amp;nbsp; processing film. However I know two places at Piracicaba, my hometown, that process coloured film. You&amp;nbsp; still can buy very cheap film st at Ebay.&amp;nbsp; There is a new trend called Lomography, but I am not going to discuss it here.&lt;br /&gt;
&lt;br /&gt;
O Zoológica Municipal de Piracicaba fica no meu bairro. Faz mais de dez anos que eu não ia lá. Como a entrada é gratuita, resolver tirar algumas fotos lá&lt;br /&gt;
&lt;br /&gt;
The Piracicaba&#39;s Zoo is located on my neighborhood. It has beem more than a decaded that I do not visit it. As the entrance is free, I decided to go there and take some shoot.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
Equipamento/Equipment &lt;/h3&gt;
Eu usei a Canon 3000N Date que comprei no Mercado Livre por R$200.&lt;br /&gt;
I used Canon 3000N Date that I bought from Mercado Livre, an &quot;Ebay&quot; for Argentine and Brazil &lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhW0ELTtel1lG8VpGKAIUWgTpmlUuO0AJKLAO7qEFfZKCaaQZNljWXMthqFeEcUT1Ff__kRAQiKtmNmIg8aQRrnp6oTDl11q1hsJumP2tXNuBc9CpNaSQQ0YB3K6nbPkzdSSimvhm7_eWg/s1600/canon-eos-3000n.11149168.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;173&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhW0ELTtel1lG8VpGKAIUWgTpmlUuO0AJKLAO7qEFfZKCaaQZNljWXMthqFeEcUT1Ff__kRAQiKtmNmIg8aQRrnp6oTDl11q1hsJumP2tXNuBc9CpNaSQQ0YB3K6nbPkzdSSimvhm7_eWg/s200/canon-eos-3000n.11149168.jpg&quot; width=&quot;200&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
O filme é um Ilford XP2, um filme britânico que, embora seja preto e branco, pode ser revelado como se fosse colorido, ou seja, ele é cromogênico. Comprei no Ebay.&lt;br /&gt;
The filme is the british Ilford XP2. It is a cromogenic film. The final result is black&#39;n&#39;white, but is processed like a color film. Bought at Ebay.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhaozCn4Xc8HUaamAMhd1zKtQVkcM_wlsywyoATH54doTIWHi0yrZRUP-OyDEMrxAVUaQPOxd-d0KUHR4pMmeZim3jfBdDuQoAdY50dwHNRgxxE3Kj07dUU1ibguvUUjzd7ZlNzCh3GW6M/s1600/35mm_Ilford_XP2_400.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;213&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhaozCn4Xc8HUaamAMhd1zKtQVkcM_wlsywyoATH54doTIWHi0yrZRUP-OyDEMrxAVUaQPOxd-d0KUHR4pMmeZim3jfBdDuQoAdY50dwHNRgxxE3Kj07dUU1ibguvUUjzd7ZlNzCh3GW6M/s320/35mm_Ilford_XP2_400.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
Algumas Fotos/ Some Shots&lt;/h3&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhtWw-dhwOwNixUfHMSZliPgKf1k7X1Azt4Wnv64OXyT2hZ1HRNkRmANcyw95twTvjoMxKrncIJTI4dtrnH-5MmzWtth5n7PdjQzi6spUmE6lsnAmqP8n05w-lSvHzsA8qcAZgBjvO2oRk/s1600/arara.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhtWw-dhwOwNixUfHMSZliPgKf1k7X1Azt4Wnv64OXyT2hZ1HRNkRmANcyw95twTvjoMxKrncIJTI4dtrnH-5MmzWtth5n7PdjQzi6spUmE6lsnAmqP8n05w-lSvHzsA8qcAZgBjvO2oRk/s1600/arara.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
Arara/Macaw &lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiXGIs-qR0SZh9xknaKGTKDtWbHh9le-dm5jbVW4cWU2t37NQ59Hgbtf6E83HUz59ugdQ_83FSFz3p4-E_VgOfmJmpgLs3DRjUSyjJb4_-xD0TXPMp2oBEVnrtEYvjX87-BhZSm9UjKZQY/s1600/avestruz.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiXGIs-qR0SZh9xknaKGTKDtWbHh9le-dm5jbVW4cWU2t37NQ59Hgbtf6E83HUz59ugdQ_83FSFz3p4-E_VgOfmJmpgLs3DRjUSyjJb4_-xD0TXPMp2oBEVnrtEYvjX87-BhZSm9UjKZQY/s1600/avestruz.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
Avestruz/Ostrich &lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgU5RIKHrCEHlRjfm4USUyJisPQgatbNhprbVDy70RktnJzF5UpeRVRr4hGHluufqvUo9MvvTlBImqEWWohHkYzJ7SrSFxkifmBf583kCX6fEAFYbPOmkCvUi6yBYmxaiSzNJJBxjgi6AY/s1600/iguana.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgU5RIKHrCEHlRjfm4USUyJisPQgatbNhprbVDy70RktnJzF5UpeRVRr4hGHluufqvUo9MvvTlBImqEWWohHkYzJ7SrSFxkifmBf583kCX6fEAFYbPOmkCvUi6yBYmxaiSzNJJBxjgi6AY/s1600/iguana.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
Iguana &lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhYT0jgJJNBhdhGfXKKpq8csK4M79F0RuymhoJRsY44J8jQXlCG7a57ZmNX8apakAbqxxSijp9SR9_c-UJ9eMxmM9KsOvEmm98pPlfVCtP03MYlnOUZ3T72W5_bLIeSTsIc9ekL7A8h9fc/s1600/ilha.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhYT0jgJJNBhdhGfXKKpq8csK4M79F0RuymhoJRsY44J8jQXlCG7a57ZmNX8apakAbqxxSijp9SR9_c-UJ9eMxmM9KsOvEmm98pPlfVCtP03MYlnOUZ3T72W5_bLIeSTsIc9ekL7A8h9fc/s1600/ilha.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
Ilha dos Macacos Pregos/Robust capuchin monkey&#39;s island &lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgCvFt8EcsVvAvWcbDgedeJZMKLpCX0vE84CZWp1HxG7UcEQkED6hHk-ih3NFLTpU3Hbo9q4eaMqnPNufiqEHPgUlCB8eLpKZzYsJQICFLO2K_jn6x7BGsoF4kycQaz_JetNjztC6QIkgg/s1600/jabuti.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgCvFt8EcsVvAvWcbDgedeJZMKLpCX0vE84CZWp1HxG7UcEQkED6hHk-ih3NFLTpU3Hbo9q4eaMqnPNufiqEHPgUlCB8eLpKZzYsJQICFLO2K_jn6x7BGsoF4kycQaz_JetNjztC6QIkgg/s1600/jabuti.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
Jabuti/Tortoise &lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhEvDOa-9F4Bcw1NjguGF6CH4UewtvLzQrrbWCvj-ukn8KaVcfll_vg2f6OQzCvB_Ah8oePC8zsoDyagEXw00mArla6joyxX8F5UL5eNX9mduBsd0gPS6GYzysENDMtJh2iIYLRVOBp0qo/s1600/jaguatirica.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhEvDOa-9F4Bcw1NjguGF6CH4UewtvLzQrrbWCvj-ukn8KaVcfll_vg2f6OQzCvB_Ah8oePC8zsoDyagEXw00mArla6joyxX8F5UL5eNX9mduBsd0gPS6GYzysENDMtJh2iIYLRVOBp0qo/s1600/jaguatirica.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
Jaguatirica/Ocelot &lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgyBDRvh143WkvuFE4hYe4szJY6KWMx-X9qxXAF9MogdQZUqvb-UbHaLWFZPlnC63AtjdVZwCEt5TyunA7QPSYKrRu9UUaKqmRRCSQHii_2qwjdDK85WVnfgTSvHa9IfqWwMDeW5GpSmvg/s1600/mico.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgyBDRvh143WkvuFE4hYe4szJY6KWMx-X9qxXAF9MogdQZUqvb-UbHaLWFZPlnC63AtjdVZwCEt5TyunA7QPSYKrRu9UUaKqmRRCSQHii_2qwjdDK85WVnfgTSvHa9IfqWwMDeW5GpSmvg/s1600/mico.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg6LbMOK2OxnctMYATPUTSTzeyQZlX2gxxgnE1Ffji9S7Cv3OAo37XOmEmPsphFA78mj58WLmvzJC6fQDucG8_VgZIMIfcQZgEyWtELSt7lm2691UuJZpyhjfBTbRE8SdAgCsQWs7Uy6WA/s1600/pavao.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg6LbMOK2OxnctMYATPUTSTzeyQZlX2gxxgnE1Ffji9S7Cv3OAo37XOmEmPsphFA78mj58WLmvzJC6fQDucG8_VgZIMIfcQZgEyWtELSt7lm2691UuJZpyhjfBTbRE8SdAgCsQWs7Uy6WA/s1600/pavao.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&amp;nbsp;Pavão/Peacock&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhFhrpE-shilRtiAYGusBpcENPC3zqOCpAw17eK16x4xII58Fd8B2CUlKfA2tuj5A8eCbFp6Rtfxf79k4zN3ww9hs6EDdVK_h-X6ekjQYvGFDizfBicMFED57a1608N6LkbsZpsaPE7S5M/s1600/tucano.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhFhrpE-shilRtiAYGusBpcENPC3zqOCpAw17eK16x4xII58Fd8B2CUlKfA2tuj5A8eCbFp6Rtfxf79k4zN3ww9hs6EDdVK_h-X6ekjQYvGFDizfBicMFED57a1608N6LkbsZpsaPE7S5M/s1600/tucano.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
Tucano/Toucan&lt;/div&gt;
&lt;h3&gt;
&lt;br /&gt;&lt;/h3&gt;
&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://aoriani.blogspot.com/feeds/2378065522372856260/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aoriani.blogspot.com/2012/09/film-photography-visita-ao-zoo.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9137329968204240224/posts/default/2378065522372856260'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9137329968204240224/posts/default/2378065522372856260'/><link rel='alternate' type='text/html' href='http://aoriani.blogspot.com/2012/09/film-photography-visita-ao-zoo.html' title='Film Photography: Visita ao Zoo'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/08214765587656957936</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhW0ELTtel1lG8VpGKAIUWgTpmlUuO0AJKLAO7qEFfZKCaaQZNljWXMthqFeEcUT1Ff__kRAQiKtmNmIg8aQRrnp6oTDl11q1hsJumP2tXNuBc9CpNaSQQ0YB3K6nbPkzdSSimvhm7_eWg/s72-c/canon-eos-3000n.11149168.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9137329968204240224.post-4356834279031720760</id><published>2012-09-11T22:53:00.002-03:00</published><updated>2012-09-11T23:36:56.620-03:00</updated><title type='text'>Learn, Develop, Package and Ship!</title><content type='html'>&lt;br /&gt;
After more than 6 years writing code that would anyway end up &amp;nbsp;in a mobile phone, I finally wrote one that people can opt out :-)&lt;br /&gt;
&lt;br /&gt;
I am in pretty busy stage of my life trying to finish my Master before the end of the year. But I found a couple of hours to learn something about &lt;a href=&quot;http://www.andengine.org/&quot; target=&quot;_blank&quot;&gt;AndEgine&lt;/a&gt;. It is a Game Engine for Android. that I learned about in the StackOverflow site. You certainly should give it a try. It makes the thing pretty easy.&lt;br /&gt;
&lt;br /&gt;
So I tried to implement something simple and silly: the classical bouncing ball example. I used the Physical Extension of AndEngine to make the ball react to shaking and gravity. The physics are not perfect : how can it be if you are using 2D vectors for a 3D world? Here is the result:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;iframe allowfullscreen=&#39;allowfullscreen&#39; webkitallowfullscreen=&#39;webkitallowfullscreen&#39; mozallowfullscreen=&#39;mozallowfullscreen&#39; width=&#39;320&#39; height=&#39;266&#39; src=&#39;https://www.youtube.com/embed/Pxvwa1OkqAo?feature=player_embedded&#39; frameborder=&#39;0&#39;&gt;&lt;/iframe&gt;&lt;/div&gt;
&lt;br /&gt;
And then I thought: &quot;Why not turning this knowledge I&#39;ve just acquired into a product?&quot;. So I put this lovely Live Wallpaper &amp;nbsp;in the Google Play. Click on the badge bellow to get it :&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://play.google.com/store/apps/details?id=orion.tennisbounce&quot;&gt;
  &lt;img alt=&quot;Android app on Google Play&quot; src=&quot;http://www.android.com/images/brand/android_app_on_play_logo_large.png&quot; /&gt;
&lt;/a&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Some stats from the first week:&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;35 installs&lt;/li&gt;
&lt;li&gt;20 of them are active&lt;/li&gt;
&lt;li&gt;Users from US, Italy, Spain, Egypt, India, Chile, Panamá, Croatia.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;Mostly Android 2.3&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
Those numbers give some insights to those wondering whether to enter or no in the mobile market. &amp;nbsp;The app is simple, I haven&#39;t done any announcement about it so far, and yet it got pretty decent download numbers. Of course, it&#39;s a free app, so people are more willing to download it. &amp;nbsp;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://aoriani.blogspot.com/feeds/4356834279031720760/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aoriani.blogspot.com/2012/09/learn-develop-package-and-ship.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9137329968204240224/posts/default/4356834279031720760'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9137329968204240224/posts/default/4356834279031720760'/><link rel='alternate' type='text/html' href='http://aoriani.blogspot.com/2012/09/learn-develop-package-and-ship.html' title='Learn, Develop, Package and Ship!'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/08214765587656957936</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9137329968204240224.post-7205872438005314543</id><published>2012-08-26T18:11:00.004-03:00</published><updated>2012-08-26T18:11:59.434-03:00</updated><title type='text'>Swapping two variables without using a temp variable</title><content type='html'>That is something I learned yesterday and I found it very cool. Thus it is something I must share.&lt;br /&gt;
&lt;br /&gt;
I remember the &lt;i&gt;swap algorithm &lt;/i&gt;was taught &amp;nbsp;in the very first days of college. It is very basic algorithm, but it is used in the foundations of several other algorithms. Until now, &amp;nbsp;it seemed &amp;nbsp;to me pretty obvious that its implementation would be inevitably (in C++03):&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush:cpp&quot;&gt;template&amp;lt;typename T&amp;gt;
void swap(T&amp;amp; x, T&amp;amp; y){
        T temp = x;
        x = y;
        y = temp;
}
&lt;/pre&gt;
&lt;br /&gt;
In other words, it would always require at least 3 registers for the exchange.&lt;br /&gt;
&lt;br /&gt;
If you are working in a pretty limited environment, a micro-controller for instance, you may not have 3 registers available for use.&lt;i&gt; Therefore you cannot do the swap. 

&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
Well, that was I thought until yesterday. Then, I found I should review some material from my old &quot;reduction of logical circuits&quot; class &amp;nbsp;instead of playing Doom3 (It&#39;s kind of old game now, but it is only 10 bucks at iTunes!). &lt;br /&gt;
&lt;br /&gt;
If your data is suitable for bitwise operations then you can do the follow (in &lt;a href=&quot;http://ideone.com/tK0Qj&quot; target=&quot;_blank&quot;&gt;C&lt;/a&gt;):&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush:c&quot;&gt;void swap(int* x, int* y){
    *x ^= *y;
    *y ^= *x;
    *x ^= *y;
}   
&lt;/pre&gt;
&lt;br /&gt;
&lt;h3&gt;
Why does it work ?&lt;/h3&gt;
&lt;div&gt;
Explanation can be found at &lt;a href=&quot;http://en.wikipedia.org/wiki/XOR_swap_algorithm&quot; target=&quot;_blank&quot;&gt;Wikipedia&lt;/a&gt;, but I intend to be more didactic here. Firstly, we need to remember some properties of the exclusive-or (xor) operation:&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;ul style=&quot;background: #dddddd;&quot;&gt;
&lt;li&gt;&lt;b&gt;P1 - Commutativity &amp;nbsp;&lt;/b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;x^y = y^x&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;b&gt;P2 - Associativity &amp;nbsp; &amp;nbsp; &amp;nbsp;(&lt;/b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;x^y)^z = x^(y^z)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Times;&quot;&gt;&lt;b&gt;P3 -&amp;nbsp;&lt;/b&gt;&lt;/span&gt;x^x = 0&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Times;&quot;&gt;&lt;b&gt;P4 -&amp;nbsp;&lt;/b&gt;&lt;/span&gt;x^0 = x&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
So let&#39;s step through the algorithm. We are going to use two registers: &lt;b&gt;A &lt;/b&gt;which initially will hold the value for &lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;x&lt;/span&gt;, and &lt;b&gt;B&lt;/b&gt; which will hold for &lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;y&lt;/span&gt;. Thus, we have before the call to &lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;swap&lt;/span&gt;:&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;background: #dddddd;&quot;&gt;
&lt;b&gt;A&lt;/b&gt; &lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;x&lt;/span&gt;&lt;br /&gt;
&lt;b&gt;B&amp;nbsp;&lt;/b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;y&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
Then we execute &lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;*x ^= *y&lt;/span&gt; &amp;nbsp;or, to be clearer &lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;*x = *x ^ *y&lt;/span&gt; :&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;background: #dddddd;&quot;&gt;
&lt;b&gt;A&lt;/b&gt; &lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;x^y&lt;/span&gt;&lt;br /&gt;
&lt;b&gt;B&lt;/b&gt; &lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;y&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
Okay, we still cannot apply any of the properties above. So let&#39;s move to the next line *y = *y ^ *x . But remember that x in the code does not refer to the value &amp;nbsp;that variable x hold before swap was called.&amp;nbsp;It in fact points to our register &lt;b&gt;A&lt;/b&gt;.&amp;nbsp;So that line really means &amp;nbsp;&lt;b&gt;B &amp;lt;-- B xor A&lt;/b&gt;. So the registers are now modified to :&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;background: #dddddd;&quot;&gt;
&lt;b&gt;A&lt;/b&gt; &lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;x^y&lt;/span&gt;&lt;br /&gt;
&lt;b&gt;B&lt;/b&gt; &lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;y^(x^y)&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
Now we have something interesting. Let&#39;s apply the properties to the register &lt;b&gt;B&lt;/b&gt;:&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;background: #dddddd;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;y^(x^y)&lt;/span&gt;&lt;b&gt; --P1--&amp;gt;&lt;/b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt; y^(y^x)&lt;/span&gt; &lt;b&gt;--P2--&amp;gt;&lt;/b&gt; &lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;(y^y)^x &lt;/span&gt;&lt;b&gt;--P3--&amp;gt;&lt;/b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt; 0^x&lt;/span&gt; &lt;b&gt;--P1--&amp;gt;&lt;/b&gt; &lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;x^0&lt;/span&gt; &lt;b&gt;--P4--&amp;gt;&lt;/b&gt; &lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;x&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
Wow! So at this point we have :&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;background: #dddddd;&quot;&gt;
&lt;b&gt;A&lt;/b&gt; &lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;x^y&lt;/span&gt;&lt;br /&gt;
&lt;b&gt;B&lt;/b&gt; &lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;x&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
We are closer to our goal. Now we execute the last line &amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;*x = *x ^ *y&lt;/span&gt; which in fact mean to us, using our register definitions,&amp;nbsp;&lt;b&gt;A &amp;lt;-- A xor B&lt;/b&gt; :&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;background: #dddddd;&quot;&gt;
&lt;b&gt;A&lt;/b&gt; &lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;(x^y)^x&lt;/span&gt;&lt;br /&gt;
&lt;b&gt;B&lt;/b&gt; &amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;x&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
Applying similar reasoning to register &lt;b&gt;A&lt;/b&gt;:&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;background: #dddddd;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;(x^y)^x = (y^x)^x = y^(x^x) = y^0 = y&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
That means that now we have:&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;background: #dddddd;&quot;&gt;
&lt;b&gt;A&lt;/b&gt; &lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;y&lt;/span&gt;&lt;br /&gt;
&lt;b&gt;B&lt;/b&gt; &lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;x&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
Voilá! We achieved what we wanted! Registers&amp;nbsp;&lt;b&gt;A&lt;/b&gt; and &lt;b&gt;B&lt;/b&gt; were swapped &amp;nbsp;only &amp;nbsp;with the &amp;nbsp;help of exclusive-or operations. No extra temporary register was needed.&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://aoriani.blogspot.com/feeds/7205872438005314543/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aoriani.blogspot.com/2012/08/swapping-two-variables-without-using.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9137329968204240224/posts/default/7205872438005314543'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9137329968204240224/posts/default/7205872438005314543'/><link rel='alternate' type='text/html' href='http://aoriani.blogspot.com/2012/08/swapping-two-variables-without-using.html' title='Swapping two variables without using a temp variable'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/08214765587656957936</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9137329968204240224.post-7514080074938178532</id><published>2012-08-17T23:42:00.002-03:00</published><updated>2012-08-17T23:42:50.743-03:00</updated><title type='text'>Using Native Code (JNI) on Android Apps</title><content type='html'>Android is written in Java and period. You must be able to do everything you need in Java. &amp;nbsp;But some applications like games using OpenGL will need some extra performance, and therefore they will go native. &amp;nbsp;As someone who had C++ as the &lt;i&gt;lingua franca&lt;/i&gt;&amp;nbsp; at college, I took special interest on how the Java Native Interface (JNI) works on Android. Thus, I made a small Android app that requests the native layer to sum two integers. In its turn, the native layer displays the result on a &lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;TextView.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;h3&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;What do you need:&lt;/span&gt;&lt;/h3&gt;
&lt;div&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://developer.android.com/sdk/index.html&quot; target=&quot;_blank&quot;&gt;Android Software Development Kit&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.google.com.br/url?sa=t&amp;amp;rct=j&amp;amp;q=android%20ndk&amp;amp;source=web&amp;amp;cd=1&amp;amp;cad=rja&amp;amp;ved=0CEoQFjAA&amp;amp;url=http%3A%2F%2Fdeveloper.android.com%2Ftools%2Fsdk%2Fndk%2Findex.html&amp;amp;ei=iX4tUL_rDcH1ygG6pYHIBw&amp;amp;usg=AFQjCNEwVSx09Hgmfvhy2wvixQtDtpQh1g&quot; target=&quot;_blank&quot;&gt;Android Native Development Kit&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;h3&gt;
&lt;/h3&gt;
&lt;h3&gt;
&lt;/h3&gt;
&lt;h3&gt;
Preparing the field&lt;/h3&gt;
&lt;div&gt;
First we create a simple activity that has a method with the &lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;native&lt;/span&gt; qualifier. That tells the JVM &amp;nbsp;that that method is not implemented in Java but by the native layer on C or C++. With Eclipse and &lt;a href=&quot;http://www.google.com.br/url?sa=t&amp;amp;rct=j&amp;amp;q=adt&amp;amp;source=web&amp;amp;cd=1&amp;amp;cad=rja&amp;amp;ved=0CHgQFjAA&amp;amp;url=http%3A%2F%2Fdeveloper.android.com%2Ftools%2Fsdk%2Feclipse-adt.html&amp;amp;ei=cIAtUJ2WIY6m8ATxioHwAg&amp;amp;usg=AFQjCNG9WF5ut8XcwF82pYCVkt-CKA6qyw&quot; target=&quot;_blank&quot;&gt;ADT&lt;/a&gt;&amp;nbsp;20 that is pretty easy.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;pre class=&quot;brush:java&quot;&gt;package com.example.testjni;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.TextView;

public class MainActivity extends Activity {

    static {
        System.loadLibrary(&quot;teste&quot;);
    }
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        sum(3,5);
        
    }

    public void setTextView(String text) {
        TextView tv = (TextView)findViewById(R.id.text);
        tv.setText(text);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
    
    public native int sum(int a, int b);
}
&lt;/pre&gt;
&lt;br /&gt;
The code above creates a simple activity with a&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt; TextView.&lt;/span&gt; Line 11 instructs the Dalvik VM to load the shared library&lt;i&gt; teste.so&lt;/i&gt;. You will see later that this the name of the library that will be generated to hold the native implementation of the method &lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;sum(int,int)&lt;/span&gt;. &amp;nbsp;This is done inside a static block so it is executed when the class &lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;MainActivity&lt;/span&gt; is loaded and therefore before any instance of it is created; so Dalvik can execute the native method when requested. &lt;br /&gt;
&lt;br /&gt;
My intention is that the activity after creating the views will call the native method to calculate the sum of 3 and 5, and then set the&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt; TextView&lt;/span&gt; with the result.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
Generating the Header file&lt;/h3&gt;
I created a &lt;i&gt;jni&lt;/i&gt; folder in the&amp;nbsp;project&#39;s&amp;nbsp;directory &amp;nbsp;to hold all the native code. Now we need to implement the native method. When the native method is called, the JVM will look for C function with a &amp;nbsp;particular signature. The easiest way to know which signature you should use for your implementation is to use the javah tool from the JDK.&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;/pre&gt;
&lt;pre class=&quot;brush:bash;&quot;&gt;#javah -classpath ./bin/classes:~/Downloads/android-sdk-macosx/platforms/android-16/android.jar -d ./jni com.example.testjni.MainActivity
&lt;/pre&gt;
&lt;br /&gt;
I ran the command above in the project&#39;s folder as above. &lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;javah&lt;/span&gt; needs the definition of all classes in your program. Thus I set the classpath &amp;nbsp;to the folder where the class files for my project are put (bin/classes) and I also added the path to the &lt;i&gt;android.jar&lt;/i&gt;. &amp;nbsp;In my case I am using the API level 16, so I picked the right &lt;i&gt;android.jar&lt;/i&gt; for it. &amp;nbsp;the &lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;-d &lt;/span&gt;parameter tells to output the header file to folder &lt;i&gt;jni&lt;/i&gt;. &amp;nbsp;You need to pass the full qualified name ( i.e., including package name) of the class with the native method. &amp;nbsp;That command generated the follow header:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush:c;&quot;&gt;/* DO NOT EDIT THIS FILE - it is machine generated */
#include &amp;lt;jni.h&amp;gt;
/* Header for class com_example_testjni_MainActivity */

#ifndef _Included_com_example_testjni_MainActivity
#define _Included_com_example_testjni_MainActivity
#ifdef __cplusplus
extern &quot;C&quot; {
#endif

/*
 * Class:     com_example_testjni_MainActivity
 * Method:    sum
 * Signature: (II)I
 */
JNIEXPORT jint JNICALL Java_com_example_testjni_MainActivity_sum
  (JNIEnv *, jobject, jint, jint);

#ifdef __cplusplus
}
#endif
#endif

&lt;/pre&gt;
&lt;br /&gt;
Note that even if the code gets compile on C++, the C-linkage is forced for the function, so the JVM can find the method without had to deal with the C++ mangling . C++ supports overloading function and mangles function signatures (embeds &amp;nbsp;parameters type, class and namespace scopes in the name) in order to support it.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
&lt;b&gt;Implementing the native method&lt;/b&gt;&lt;/h3&gt;
&lt;div&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: normal;&quot;&gt;I will show the implementation in C and C++. &amp;nbsp;The reason behind that is &amp;nbsp;that although the two languages are very similar ( you can compile C code with a C++ compiler), &amp;nbsp;the JNI &amp;nbsp;for C++ offer some inline methods to make it more object oriented.&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: normal;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;h4&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot;&gt;The C code&lt;/span&gt;&lt;/b&gt;&lt;/h4&gt;
&lt;pre class=&quot;brush:c;&quot;&gt;#include &amp;lt;stdio.h&amp;gt;
#include stdlib.h&amp;gt;
#include &amp;lt;jni.h&amp;gt;
#include &amp;lt;android/log.h&amp;gt;
#include &quot;com_example_testjni_MainActivity.h&quot;


#define LOG_TAG &quot;TesteNativeC&quot;
#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__))

static char* buildString(jint a, jint b, jint sum){
    const char* fmt_string = &quot;The sum of %d and %d is %d&quot;;
    const int buffer_size = snprintf(NULL,0,fmt_string,a,b,sum);
    LOGI(&quot;Buffer size is %d&quot;,buffer_size);
    char* buffer = (char*) malloc((buffer_size+1) * sizeof(char));
    if( buffer != NULL){
        snprintf(buffer,(buffer_size+1),fmt_string,a,b,sum);
    }
        return buffer;
}


JNIEXPORT jint JNICALL Java_com_example_testjni_MainActivity_sum
  (JNIEnv * env, jobject obj, jint a, jint b){
    jint result =  a+b;
    jclass cls = (*env)-&amp;gt;GetObjectClass(env, obj);
    jmethodID mid = (*env)-&amp;gt;GetMethodID(env, cls, &quot;setTextView&quot;, &quot;(Ljava/lang/String;)V&quot;);
    if(mid == 0) return 0;
    char* text = buildString(a,b,result);
    if(text != NULL){
        LOGI(&quot;At this point string is &amp;lt;&amp;lt;%s&amp;gt;&amp;gt;&quot;,text);
        jstring textToDisplay = (*env)-&amp;gt;NewStringUTF(env,text);
        (*env)-&amp;gt;CallVoidMethod(env, obj, mid, textToDisplay); 
        free(text);
    }
    
    return result;
  }
&lt;/pre&gt;
&lt;br /&gt;
Function &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;buildString&lt;/span&gt; is declared static because it is not intended to be exported, used outside of the library. Its objective is to build the string &lt;i&gt;&quot;The sum of 3 and 5 is 8&quot;&lt;/i&gt;. &amp;nbsp;For that, we call function &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;snprintf&lt;/span&gt; from the standard C library. Note that I am using &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;snprintf&lt;/span&gt; , the &lt;i&gt;&quot;safe-version&quot;&lt;/i&gt; of &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;sprintf&lt;/span&gt;. The reason for that is to prevent buffer overrun, &amp;nbsp;a common technique used by&amp;nbsp;attackers&amp;nbsp;to inject malicious . &amp;nbsp;In our case we don&#39;t need to do that because input does not come from external source. However, best practices should always be enforced. &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;snprintf&lt;/span&gt; is used twice: first with a&amp;nbsp;&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;NULL&lt;/span&gt; parameter &amp;nbsp;to calculate the size of the necessary buffer to hold the string, and a second time to build the string.&lt;br /&gt;
&lt;br /&gt;
The implementation of the native method follow conventional JNI idioms and it is very similar to using reflection in Java. So I just calculated the sum, retrieved the reference to the &lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;setTextView(String)&lt;/span&gt; method of the activity, build the string and called the method. &amp;nbsp;And, this is very important, I &amp;nbsp;released the allocated char array. &lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;NewStringUTF&lt;/span&gt;&amp;nbsp;does a copy of the passed char array, so you need to free the buffer to not get a memory leak. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;The C++ code

&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush:cpp;&quot;&gt;#include &amp;lt;jni.h&amp;gt;
#include &amp;lt;sstream&amp;gt;
#include &amp;lt;string&amp;gt;
#include &amp;lt;android/log.h&amp;gt;
#include &quot;com_example_testjni_MainActivity.h&quot;

#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__))

using std::stringstream;
using std::string;

const char* LOG_TAG = &quot;TesteNativeCpp&quot;;

static string buildString(jint a, jint b, jint sum){
    stringstream buffer;
    buffer&amp;lt;&amp;lt;&quot;The sum of &quot;&amp;lt;&amp;lt;a&amp;lt;&amp;lt;&quot; and &quot;&amp;lt;&amp;lt;b&amp;lt;&amp;lt;&quot; is &quot;&amp;lt;&amp;lt;sum;
    return buffer.str();
}

JNIEXPORT jint JNICALL Java_com_example_testjni_MainActivity_sum
  (JNIEnv * env, jobject obj, jint a, jint b){
    jint result =  a+b;
    jclass cls = env-&amp;gt;GetObjectClass(obj);
    
    jmethodID mid = env-&amp;gt;GetMethodID(cls, &quot;setTextView&quot;, &quot;(Ljava/lang/String;)V&quot;);
    if(mid == 0) return 0;
    
    string text = buildString(a,b,result);
    LOGI(&quot;At this point string is &amp;lt;&amp;lt;%s&amp;gt;&amp;gt;&quot;,text.c_str());
    jstring textToDisplay = env-&amp;gt;NewStringUTF(text.c_str());
    env-&amp;gt;CallVoidMethod(obj, mid,textToDisplay); 

    return result;
  }
  &lt;/pre&gt;
&lt;br /&gt;
The C++ code is not much different. I could have used the same code &amp;nbsp;as of the C version&amp;nbsp;for the function buildString, but I decided to do a code that is closer to latest C++ standards ( Not C++11 yet :-) ). Besides this uses STL containers. Using STL requires extra build config to compile. So I have the chance to show you how to setup the build for that case.&lt;br /&gt;
&lt;br /&gt;
Note that for C++, &lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;env&lt;/span&gt; works more like an object : if in C we have&amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;(*env)-&amp;gt;function(env,parameters)&lt;/span&gt;,&amp;nbsp;in C++ we have &lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;env-&amp;gt;method(parameters)&lt;/span&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
Building&lt;/h3&gt;
&lt;br /&gt;
Now we need a Makefile for the job. I created the file &lt;i&gt;Android.mk&lt;/i&gt; under the &lt;i&gt;jni&lt;/i&gt; folder&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush:bash;&quot;&gt;LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE    := teste
LOCAL_SRC_FILES := teste.cpp
LOCAL_LDLIBS    := -llog

include $(BUILD_SHARED_LIBRARY)
&lt;/pre&gt;
&lt;pre&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;/pre&gt;
&lt;br /&gt;
This makefile is based on the one use for the &lt;i&gt;&quot;hello word&quot;&lt;/i&gt; sample of the NDK. &lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;LOCAL_MODULE &lt;/span&gt;will tell to generate the shared object&lt;i&gt; teste.so&lt;/i&gt;. &lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;LOCAL_SRC_FILES&lt;/span&gt; lists the files to be compiled. &lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;cpp&lt;/span&gt; extension is required for C++ files.&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt; LOCAL_LDLIDS&lt;/span&gt; tells to link against the library that allows our native code to output log to logcat.
&lt;br /&gt;
Remember I said we need extra config to use STL containers. This means to create an &lt;i&gt;Application.mk&lt;/i&gt; file besides the &lt;i&gt;Android.mk&lt;/i&gt; in the jni folder
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush:bash;&quot;&gt;APP_STL := stlport_static&lt;/pre&gt;
&lt;br /&gt;
This single line sets the &amp;nbsp;STL library to be linked static.
&lt;br /&gt;
&lt;br /&gt;
Now we can build . You just &amp;nbsp;need to invoke &lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;lt;ndk_folder&amp;gt;/ndk-build&lt;/span&gt; on you project folder. This will generate the shared library that will be packaged on you APK. After you have built the library, you just need to build your APK as you would normally do (Eclipse or ant).&lt;br /&gt;
&lt;br /&gt;
And that is the final result :&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgj8HWwC1xPqDETtVXxEG3I_nqd49TXG2i8pR0NwCErpX_TFIMQo5ONSOVaptc6BOTFKjtJGFK33S3I0MjtDrw9OGeiDE6XfNWtiBi9kU_RBz8TSPn9nWemZFm5lbL5LDhV-_s5DzXc5Iw/s1600/device-2012-08-17-230306.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgj8HWwC1xPqDETtVXxEG3I_nqd49TXG2i8pR0NwCErpX_TFIMQo5ONSOVaptc6BOTFKjtJGFK33S3I0MjtDrw9OGeiDE6XfNWtiBi9kU_RBz8TSPn9nWemZFm5lbL5LDhV-_s5DzXc5Iw/s320/device-2012-08-17-230306.png&quot; width=&quot;180&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://aoriani.blogspot.com/feeds/7514080074938178532/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aoriani.blogspot.com/2012/08/using-native-code-jni-on-android-apps.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9137329968204240224/posts/default/7514080074938178532'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9137329968204240224/posts/default/7514080074938178532'/><link rel='alternate' type='text/html' href='http://aoriani.blogspot.com/2012/08/using-native-code-jni-on-android-apps.html' title='Using Native Code (JNI) on Android Apps'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/08214765587656957936</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgj8HWwC1xPqDETtVXxEG3I_nqd49TXG2i8pR0NwCErpX_TFIMQo5ONSOVaptc6BOTFKjtJGFK33S3I0MjtDrw9OGeiDE6XfNWtiBi9kU_RBz8TSPn9nWemZFm5lbL5LDhV-_s5DzXc5Iw/s72-c/device-2012-08-17-230306.png" height="72" width="72"/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9137329968204240224.post-5201192330735879443</id><published>2012-08-06T20:15:00.000-03:00</published><updated>2012-08-06T20:20:55.254-03:00</updated><title type='text'>Why Computer Science is not an Exact Science?</title><content type='html'>I had a simple task today. Write a comparator for integers. My attempt was:

&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush:java&quot;&gt;int compare(int a, int b){
    return a - b;
}
&lt;/pre&gt;
&lt;pre&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;/pre&gt;
As you know this function must return a negative number if a&amp;lt;b, a positive number if a&amp;gt;b, and zero if both numbers are equal. As in any Exact Science, to show that something is correct you must conduct a proof.&lt;br /&gt;
&lt;br /&gt;
There are three claims to prove:&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;background: #dddddd; border: 2px #000000; padding: 2px;&quot;&gt;
&lt;ul&gt;
&lt;li&gt;&lt;i&gt;If a &amp;lt; b, the algorithm returns a negative number&lt;/i&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
In fact if a&amp;lt;b, then b=a+c, where c is a positive number. Thus a&amp;lt;a+c and &amp;nbsp;a-b = a-(a+c) = -c, a negative number&lt;/div&gt;
&lt;div&gt;
&lt;ul&gt;
&lt;li&gt;&lt;i&gt;if a&amp;gt;b, the algorithm returns a positive number&lt;/i&gt;. &amp;nbsp;&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
Using the same reasoning, a&amp;gt;b =&amp;gt; a=b+c =&amp;gt; a-b = b+c-b = c, a positive number&lt;/div&gt;
&lt;div&gt;
&lt;ul&gt;
&lt;li&gt;&lt;i&gt;if a=b, the algorithm returns zero&lt;/i&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
Trivially : a=b =&amp;gt; a-b = a-a = 0.&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;b&gt;But yet, the algorithm is incorrect.&lt;/b&gt;&lt;br /&gt;
&lt;i&gt;&quot;How come? Didn&#39;t you just prove it correct with mathematical rigor?&quot;&lt;/i&gt;&lt;br /&gt;
Yes, I did. Your professor from the Algorithm Analysis course would like this proof. But as I said, it is completely wrong. &amp;nbsp;Guess why? Just an small tip : 2&lt;sup&gt;31&lt;/sup&gt;-1&lt;br /&gt;
&lt;br /&gt;
Yes! Integer overflow! My biggest mistake here was to assume a,b ∈ ℤ. Actually, they are restricted to (considering VM Java and 32bits for C/C++) &amp;nbsp;the interval [-2&lt;sup&gt;31&lt;/sup&gt;,2&lt;sup&gt;31&lt;/sup&gt;-1] . And the math is pretty weird for outsiders: the &amp;nbsp;sum of two very small negative integers may resulting in a positive number, and the sum of two very big positive numbers may yield a negative number.&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&quot;So let us account for the overflows. Let&#39;s put a check on your code. If ...&quot;&lt;/i&gt;&lt;br /&gt;
Hey! Wait! Before complicating the code I want to show you how the Java Library implements the comparison:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush:java&quot;&gt; public static int compare(int x, int y) {
     return (x &amp;lt; y) ? -1 : ((x == y) ? 0 : 1);
 }
&lt;/pre&gt;
&lt;br /&gt;
Imagine my &lt;em&gt;duh!&lt;/em&gt; face when I read that.
&lt;br /&gt;
&lt;br /&gt;
Two lessons I learned here:&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;Theory is good, but practice is always better. &lt;/b&gt;&amp;nbsp;In theory integers are infinite. In practice they are limited by the word size, and they came in signed and unsigned flavors. &amp;nbsp;That also applies to more complicated data structures. Your perfect hash function may not be perfect when you consider &amp;nbsp;the hardware &amp;nbsp;and software constraints.&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Do not pre-optimize code, &amp;nbsp;focus first in making it the most readable as possible. &lt;/b&gt;&amp;nbsp;By trying to making the comparison with a single operation I made it not readable&amp;nbsp;by others&amp;nbsp;at first sight. And worst: instead of saving &quot;microseconds&quot;, I introduced a bug.&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aoriani.blogspot.com/feeds/5201192330735879443/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aoriani.blogspot.com/2012/08/why-computer-science-is-not-exact.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9137329968204240224/posts/default/5201192330735879443'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9137329968204240224/posts/default/5201192330735879443'/><link rel='alternate' type='text/html' href='http://aoriani.blogspot.com/2012/08/why-computer-science-is-not-exact.html' title='Why Computer Science is not an Exact Science?'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/08214765587656957936</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9137329968204240224.post-8662998911201763423</id><published>2012-07-08T01:02:00.000-03:00</published><updated>2012-07-17T15:53:01.390-03:00</updated><title type='text'>Does megapixel count matter when taking photos?</title><content type='html'>&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
One of the features a point-and-shoot camera will brag about is its megapixel count. Most people will only care about that when buying a new camera. They simply forget or are not aware of the other little details that impact on the image quality.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
In order to verify if megapixel count really matters, I did a simple test in extreme low light conditions and saw how the two cameras perform.&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;




Canon Powershot A2200&lt;/h3&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://imagens.extra.com.br/html/conteudo-produto/Cinefoto/307403/images/Canon_A2200_principal.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;133&quot; src=&quot;http://imagens.extra.com.br/html/conteudo-produto/Cinefoto/307403/images/Canon_A2200_principal.jpg&quot; width=&quot;200&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
This is one the cheapest point-and-shoot camera from Canon. &amp;nbsp;A Q1 2011 camera costing only US$ 99 at Amazon.I managed to pay only R$200 ( I live at Brazil) on Kabum.com.br. I wanted a compact that I could carry with me for every I would go. This was the cheapest camera I found that met the criteria. &amp;nbsp;It features a 14.1 megapixel sensor, Digic 4 processor and Canon Zoom Lens 5-20mm 1:2.8-5.9 capable of 4x zoom. &amp;nbsp;Being a cheap camera, it lacks image stabilization, a very important feature for night and zoom shots. Although it is a Canon lens, we cannot expect quality from such tiny lens. And it is made on China, not Japan.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
This is photo that I took at night from my bathroom window leaning on the windowsill to prevent shake. &amp;nbsp;The photo has 4320x3240 pixels, focal length 6.36mm, &amp;nbsp;F/3.2 8s ISO 80. I wish I could tell the camera to use a smaller aperture, but there is not way of doing that.&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhNb5mGkF1dGxwtV_-As7NX4u3dE-pKJ_H0DWA6W1uuoCoN5Qr38Guzz8CLphJbTY_8BgybFx_4UAOKvLlVh9fj7wfII7oTCG3Dx7AaK_obf_gVJb5S2FKMeKilUOANaB7A0Xwu1Zsbr_U/s1600/canon.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;480&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhNb5mGkF1dGxwtV_-As7NX4u3dE-pKJ_H0DWA6W1uuoCoN5Qr38Guzz8CLphJbTY_8BgybFx_4UAOKvLlVh9fj7wfII7oTCG3Dx7AaK_obf_gVJb5S2FKMeKilUOANaB7A0Xwu1Zsbr_U/s640/canon.JPG&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;/div&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 19px; font-weight: bold;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;h3&gt;


&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 19px; font-weight: bold;&quot;&gt;Sony Cyber-Shot DSC-H5&lt;/span&gt;&lt;/h3&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://www.engadget.com/media/2006/07/cybershotdsc5.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;170&quot; src=&quot;http://www.engadget.com/media/2006/07/cybershotdsc5.jpg&quot; width=&quot;200&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Cyber-shot is certainly most popular brand for consumer cameras. But popularity does not necessary reflects good image quality. But in case of this Q1 2006 &amp;nbsp;7.2 megapixels camera it does. Mostly because it features &amp;nbsp;a Carl Zeiss Vario-Tessar 2.8-3.7/6-72mm lens instead of the common Sony G lens that is used on most of the Cyber-shot lineup. That detail really makes that camera special. &amp;nbsp;This japanese made camera also has image stabilization.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&amp;nbsp;A shot taken with the DSC-H5 from the same point: 3072 × 2304, focal length 6mm, F/8, 30s ISO 80&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgaGbKtLPdrfy3Io3PYLiXnaY40rTVhuR-VdZdfexuVqCKoP_5h7Pa1DPNf_HsHY8AkDIfiNlgTS1sWUvwodWtwcidnuXKYOUzD1Niq45mCYB9i_GfQCChYY5nUeEBVTOgTA6ycp0u-HcM/s1600/sony.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;480&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgaGbKtLPdrfy3Io3PYLiXnaY40rTVhuR-VdZdfexuVqCKoP_5h7Pa1DPNf_HsHY8AkDIfiNlgTS1sWUvwodWtwcidnuXKYOUzD1Niq45mCYB9i_GfQCChYY5nUeEBVTOgTA6ycp0u-HcM/s640/sony.JPG&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;




The moment of truth&amp;nbsp;&lt;/h3&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Here is a 100% crop for the DSC-H5 (left side) &amp;nbsp;along with a crop for the same area from the image captured by the A2200.&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhAXL77dOfFzGrHQNeqxbiW6XwgWeeb3dYDod_scYW_JCYmQbcIWMNaIXHEY8BuLmqft0wmqa8EQDau3UDtmql44nfbyeOSg4D9ceVzKclp3zTVvbaCOpf-FJOc-ZFa51mwabm_XxmkU6E/s1600/comparison.tiff&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;356&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhAXL77dOfFzGrHQNeqxbiW6XwgWeeb3dYDod_scYW_JCYmQbcIWMNaIXHEY8BuLmqft0wmqa8EQDau3UDtmql44nfbyeOSg4D9ceVzKclp3zTVvbaCOpf-FJOc-ZFa51mwabm_XxmkU6E/s640/comparison.tiff&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
DSC-H5 has a shaper image even though the A2200 has almost the double of pixels. Contrast, &amp;nbsp;exposition and white balance are very similar on both imagse. A2200&#39;s image looks like a blurry version of DSC-H5&#39;s&lt;/div&gt;
&lt;br /&gt;
&lt;h3&gt;




Closing Remarks&lt;/h3&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Megapixel count do matter, but they are not essential. They should be enough to present all the image details in the target format. Agood sensor and quality lens will make the difference.&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aoriani.blogspot.com/feeds/8662998911201763423/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aoriani.blogspot.com/2012/07/does-megapixel-count-matter-when-taking.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9137329968204240224/posts/default/8662998911201763423'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9137329968204240224/posts/default/8662998911201763423'/><link rel='alternate' type='text/html' href='http://aoriani.blogspot.com/2012/07/does-megapixel-count-matter-when-taking.html' title='Does megapixel count matter when taking photos?'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/08214765587656957936</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhNb5mGkF1dGxwtV_-As7NX4u3dE-pKJ_H0DWA6W1uuoCoN5Qr38Guzz8CLphJbTY_8BgybFx_4UAOKvLlVh9fj7wfII7oTCG3Dx7AaK_obf_gVJb5S2FKMeKilUOANaB7A0Xwu1Zsbr_U/s72-c/canon.JPG" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9137329968204240224.post-7998953005488776578</id><published>2012-04-07T00:50:00.001-03:00</published><updated>2012-04-12T01:48:40.352-03:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="lego"/><category scheme="http://www.blogger.com/atom/ns#" term="nxc"/><category scheme="http://www.blogger.com/atom/ns#" term="robot"/><title type='text'>First Attempts with Lego Mindstorms NTX 2.0</title><content type='html'>&lt;div&gt;I knew that Lego have done some robotics kits. You would program a big brick, connect motors and sensors and start the fun. Well, buying the kit at Brazil is pretty expensive: US$ 1000 by today&#39;s exchange rate. I found that if I import directly from &lt;a href=&quot;http://www.amazon.com/LEGO-4544091-Mindstorms-NXT-2-0/dp/B001USHRYI&quot; target=&quot;_blank&quot;&gt;Amazon&lt;/a&gt;&amp;nbsp; &lt;b&gt;I could get it for US$ 600, import taxes included !&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
Okay, here is my first robot. It&#39;s the basic starter model. I program it to avoid bumping into objects.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;iframe allowfullscreen=&#39;allowfullscreen&#39; webkitallowfullscreen=&#39;webkitallowfullscreen&#39; mozallowfullscreen=&#39;mozallowfullscreen&#39; width=&#39;320&#39; height=&#39;266&#39; src=&#39;https://www.youtube.com/embed/REFPELbaguA?feature=player_embedded&#39; frameborder=&#39;0&#39;&gt;&lt;/iframe&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
My second Robot was the ColorSorter. &amp;nbsp;That one also comes with the kit.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;object class=&quot;BLOGGER-youtube-video&quot; classid=&quot;clsid:D27CDB6E-AE6D-11cf-96B8-444553540000&quot; codebase=&quot;http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0&quot; data-thumbnail-src=&quot;http://i.ytimg.com/vi/wFdGM_fxUMU/0.jpg&quot; height=&quot;266&quot; width=&quot;320&quot;&gt;&lt;param name=&quot;movie&quot; value=&quot;http://www.youtube.com/v/wFdGM_fxUMU?version=3&amp;f=user_uploads&amp;c=google-webdrive-0&amp;app=youtube_gdata&quot; /&gt;








&lt;param name=&quot;bgcolor&quot; value=&quot;#FFFFFF&quot; /&gt;








&lt;embed width=&quot;320&quot; height=&quot;266&quot;  src=&quot;http://www.youtube.com/v/wFdGM_fxUMU?version=3&amp;f=user_uploads&amp;c=google-webdrive-0&amp;app=youtube_gdata&quot; type=&quot;application/x-shockwave-flash&quot;&gt;&lt;/embed&gt;&lt;/object&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The kit comes with a NXT-G, a graphical programing environment based on LabView from National Instruments. When I said Graphical, I mean you have to drag blocks and make connection to program. &amp;nbsp;See how hard is only to implement the modulo function :&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://www.brickshelf.com/gallery/brdavis/NXT/NXT-G/modulo.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;278&quot; src=&quot;http://www.brickshelf.com/gallery/brdavis/NXT/NXT-G/modulo.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
It is not only hard to people used to program by &quot;typing code&quot;, but it also generates big and sluggish programs. And program size really matters as memory is scarce. &amp;nbsp;The alternative I found was &lt;a href=&quot;http://bricxcc.sourceforge.net/nbc/&quot; target=&quot;_blank&quot;&gt;Bricxcc&lt;/a&gt;, a Windows IDE for NXC ( Not eXactly C) , a C like language to programming the NXT2.0.&lt;br /&gt;
&lt;br /&gt;
Here is the code for the Color Sorter Robot above. It is a direct translation &amp;nbsp;of the NXT-G code that comes with the kit. I haven&#39;t done any improvements to make the robot smatter.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush:cpp&quot;&gt;/*
  Lego color sorter
  Attempt to convert from NXT-G to NXC
*/

#define COLOR_SENSOR SENSOR_3
#define TOUCH_SENSOR1 SENSOR_2
#define TOUCH_SENSOR2 SENSOR_1


#define PRESSED 1
#define NOT_PRESSED 0
#define UNTIL_BUMPED(x)  until((x) == PRESSED);until((x) == NOT_PRESSED);

enum color_t {
  BLUE = INPUT_BLUECOLOR,
  RED = INPUT_REDCOLOR,
  YELLOW = INPUT_YELLOWCOLOR,
  GREEN = INPUT_GREENCOLOR
};


sub initializeSensors(){
    //Color Sensor
    SetSensorColorFull(IN_3);
    //Touch sensor 1
    SetSensorTouch(IN_2);
    //Touch sensor 2
    SetSensorTouch(IN_1);
}


task main(){
     initializeSensors();
     
     OnFwd(OUT_C,50);
     until(TOUCH_SENSOR1 == PRESSED);
     RotateMotor(OUT_C,50,55);
     while(true){
         color_t color  = COLOR_SENSOR;
         
         switch(color){
                       case BLUE:
                            //PlaySound wait for completion
                            OnFwd(OUT_B,50);
                            UNTIL_BUMPED(TOUCH_SENSOR2);
                            RotateMotor(OUT_B,50,0.8*360);
                            Wait(MS_300);
                       break;
                       
                       case RED:
                            //PlaySound
                            RotateMotor(OUT_C,40,90);
                            OnFwd(OUT_B,50);
                            UNTIL_BUMPED(TOUCH_SENSOR2);
                            RotateMotor(OUT_B,50,0.8*360);
                            RotateMotor(OUT_C,40,270);
                       break;
                       
                       case YELLOW:
                            //PlaySound
                            RotateMotor(OUT_C,40,180);
                            OnFwd(OUT_B,50);
                            UNTIL_BUMPED(TOUCH_SENSOR2);
                            RotateMotor(OUT_B,50,0.8*360);
                            RotateMotor(OUT_C,40,180);
                       break;
                            
                       case GREEN:
                            //PlaySound
                            RotateMotor(OUT_C,40,270);
                            OnFwd(OUT_B,50);
                            UNTIL_BUMPED(TOUCH_SENSOR2);
                            RotateMotor(OUT_B,50,0.8*360);
                            RotateMotor(OUT_C,40,90);
                       break;
                       
                       default:
                           //Play Sound - try again
                            OnFwd(OUT_B,50);
                            UNTIL_BUMPED(TOUCH_SENSOR2);
                            RotateMotor(OUT_B,50,0.8*360);

         }
     }
}
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aoriani.blogspot.com/feeds/7998953005488776578/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aoriani.blogspot.com/2012/04/first-attempts-with-lego-mindstorms-ntx.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9137329968204240224/posts/default/7998953005488776578'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9137329968204240224/posts/default/7998953005488776578'/><link rel='alternate' type='text/html' href='http://aoriani.blogspot.com/2012/04/first-attempts-with-lego-mindstorms-ntx.html' title='First Attempts with Lego Mindstorms NTX 2.0'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/08214765587656957936</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>