<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>C on Bald Engineer</title><link>https://www.baldengineer.com/tag/c</link><description>Recent content in C on Bald Engineer</description><generator>Hugo</generator><language>en-US</language><lastBuildDate>Mon, 09 Jul 2018 01:31:47 +0000</lastBuildDate><atom:link href="https://www.baldengineer.com/tag/c/index.xml" rel="self" type="application/rss+xml"/><item><title>Five Arduino math fixes for when it is wrong</title><link>https://www.baldengineer.com/arduino-math-fixes.html</link><pubDate>Wed, 04 Jul 2018 13:16:52 +0000</pubDate><guid isPermaLink="false">https://www.baldengineer.com/?p=7463</guid><description>While the Arduino library does an excellent job of hiding some of C/C++’s warts, at the end of the day, it is still just C/C++. This fact causes a few non-intuitive issues for inexperienced programmers. When it looks like Arduino math is wrong, it is probably one of these reasons.&#10;When people ask me for help with their programming, I check each of these Arduino math mistakes. If your code seems to be hitting a bug, check to make sure it is not how the compiler handles math.<p><img src="https://www.baldengineer.com/wp-content/uploads/2018/07/Arduino-Math-Chalkboard-1960px-v2.jpg" alt="Five Arduino math fixes for when it is wrong"/></p></description></item><item><title>5 Common Arduino Programming Mistakes</title><link>https://www.baldengineer.com/5-common-arduino-programming-mistakes.html</link><pubDate>Wed, 17 Aug 2016 13:39:41 +0000</pubDate><guid isPermaLink="false">https://www.baldengineer.com/?p=6145</guid><description>Whenever someone sends me some code that doesn’t work, there are a few common Arduino programming mistakes that I check. Some of these mistakes I make myself. In most cases my code will compile just fine. Sometimes, these mistakes won’t generate any compiler error.&#10;When my Arduino code is acting up, these are the first things I check. Here are my 5 common Arduino programming mistakes, I use to debug non-working code.<p><img src="https://www.baldengineer.com/wp-content/uploads/2016/08/5-common-arduino-programming-mistakes.jpg" alt="5 Common Arduino Programming Mistakes"/></p></description></item><item><title>Microcontroller state machine with enum tutorial</title><link>https://www.baldengineer.com/state-machine-with-enum-tutorial.html</link><pubDate>Wed, 29 Jul 2015 13:00:07 +0000</pubDate><guid isPermaLink="false">https://www.baldengineer.com/?p=5251</guid><description>Flag variables are great, and totally not evil, when you just have two states: ON or OFF. What about when you have multiple states? Is there an option better than creating multiple flag variables?&#10;The C-language has a declaration type just for this purpose. It is called an enumeration, or enum.&#10;Setting up a state machine with enum is a surprisingly simple. Arduino and embedded programmers should use them!&#10;All you need to do is create descriptive tag names, and let the compiler assign them an integer value. Unlike a #define which is just a macro replacement, the compiler treats an enum as your personal variable type.<p><img src="https://www.baldengineer.com/wp-content/uploads/2015/07/state-machines-with-enum-tutorial.jpg" alt="Microcontroller state machine with enum tutorial"/></p></description></item><item><title>"Post your code" to the style of "Let it Be"</title><link>https://www.baldengineer.com/post-your-code-to-the-style-of-let-it-be.html</link><pubDate>Mon, 09 Jun 2014 15:00:06 +0000</pubDate><guid isPermaLink="false">https://www.baldengineer.com/?p=2480</guid><description>A friendly reminder video to everyone asking for help in a programming forum.&#10;Lately I’ve been looking for ways to expand on the content in the AddOhms YouTube channel. One of the thoughts I had were taking some of the hard engineering lessons and turning them into a “Public Service Announcement”. You know, like those short films that would run on TV after school or NBC’s famous " The More You Know." Not something so dry, but something at least a little entertaining.<p><img src="https://www.baldengineer.com/wp-content/uploads/2012/09/post-your-code-banner.png" alt="&amp;#34;Post your code&amp;#34; to the style of &amp;#34;Let it Be&amp;#34;"/></p></description></item><item><title>Well formatted Arduino code in one click</title><link>https://www.baldengineer.com/one-click-clean-arduino-code.html</link><pubDate>Fri, 16 May 2014 15:00:06 +0000</pubDate><guid isPermaLink="false">https://www.baldengineer.com/?p=2416</guid><description>Warning, the title of this post is a little bit misleading. It isn’t just one-click to get cleanly formatted code, it’s actually two.&#10;There are two things seasoned programmers will tell new programmers, that they don’t understand (at first):&#10;Always comment your code Properly indent code The problem? As a new programmer, you might not know how to do #2 until you get some experience.&#10;How indenting helps The reason you indent code is to make it easier for a reader to understand the code’s flow. A compiler (well except in Python) doesn’t care if two lines line up or not. T he recent issues around Apple’s “goto fail;” are a great example of how indentation is meaningless to a C compiler.<p><img src="https://www.baldengineer.com/wp-content/uploads/2012/09/autoformat-banner.png" alt="Well formatted Arduino code in one click"/></p></description></item><item><title>Arduino: Assignments != Comparisons</title><link>https://www.baldengineer.com/arduino-assignments-do-not-equal-comparisons.html</link><pubDate>Thu, 03 Apr 2014 15:00:59 +0000</pubDate><guid isPermaLink="false">https://www.baldengineer.com/?p=2321</guid><description>There is one mistake that all C programmers make, regardless of experience. You’ll do it often when you get started, but never completely stop. The mistake? Confusing the “assignment” operator with the “comparison” operator. Take a look at this line of code:&#10;if (something = 0) { Notice the problem? If not, then you might fall into this common trap. The most annoying part? A C-Compiler won’t give an error. That code is legal C. Legal code doesn’t mean you’ll get the results you expect. In fact, this is probably not even close to what you wanted. This simple mistake and why it “works” is explained below.<p><img src="https://www.baldengineer.com/wp-content/uploads/2012/09/assignment-comparison-banner.png" alt="Arduino:  Assignments != Comparisons"/></p></description></item><item><title>Const vs #define - When do you use them and why?</title><link>https://www.baldengineer.com/const-vs-define-when-do-you-them-and-why.html</link><pubDate>Thu, 14 Nov 2013 11:13:40 +0000</pubDate><guid isPermaLink="false">https://www.baldengineer.com/?p=1944</guid><description>Arduino boards have microcontrollers with notoriously small amounts of RAM. The Uno only has 2,048 bytes of static RAM available for your program to store variables. So when you need to keep non-changing variables out of RAM which is best to use const or #define?&#10;What is #define #define is often misunderstood because it isn’t a programming statement. Instead, it sets up a macro which causes a text replace to occur before code is compiled. For example in this code:</description></item></channel></rss>