Reader small image

You're reading from  Arduino Robotic Projects

Product typeBook
Published inAug 2014
Reading LevelIntermediate
Publisher
ISBN-139781783989829
Edition1st Edition
Languages
Tools
Right arrow
Author (1)
Richard Grimmett
Richard Grimmett
author image
Richard Grimmett

Richard Grimmett has more fun that should be allowed working on robotics projects while teaching Computer Science and Electrical Engineering at Brigham Young University Idaho. He has a Bachelors and Masters degree in Electrical Engineering and a PhD in Leadership Studies. He also has 26 years of experience in the Radar and Telecommunications industries, and even has one of the original brick phones. He has written books on the basics of using the BeagleBone Black for robotics projects, and another for the Raspberry PI and yet another for the Arduino.
Read more about Richard Grimmett

Right arrow

Basic programming constructs on Arduino


Now that you know how to enter and run a simple C program on Arduino, let's look at some additional programming constructs. Specifically, you'll see what to do when you want to decide between two instructions to execute and how to execute a set of instructions a number of times.

The if statement

As you have seen, your programs normally start with the first line of code and then continue executing the next line until your program runs out of code. This is fine, but what if you want to decide between two different courses of action? We can do this in C using an if statement. The following screenshot shows some example code:

You'll need to make several changes this time. The first is to add another global variable, int whichLED = 1; at the top of your program. Then, you'll need to add several statements to your loop() function. The line-by-line details are as follows:

  • if (whichLED == 1): This is the if statement. The if statement evaluates the expression...

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Arduino Robotic Projects
Published in: Aug 2014Publisher: ISBN-13: 9781783989829

Author (1)

author image
Richard Grimmett

Richard Grimmett has more fun that should be allowed working on robotics projects while teaching Computer Science and Electrical Engineering at Brigham Young University Idaho. He has a Bachelors and Masters degree in Electrical Engineering and a PhD in Leadership Studies. He also has 26 years of experience in the Radar and Telecommunications industries, and even has one of the original brick phones. He has written books on the basics of using the BeagleBone Black for robotics projects, and another for the Raspberry PI and yet another for the Arduino.
Read more about Richard Grimmett