Arduino Structure, Functions and Variables

In one of our previous tutorials, Arduino tutorial for beginners, we discussed programmable electronics where we introduced the Arduino development board. The use of arduino to design electronic devices requires a good knowledge of both the hardware and software parts. We covered reasonably the hardware part in the previous tutorial. this time, we are going to delve into understanding the programming features of the arduino microcontroller.

In this Arduino tutorial, we shall discuss and learn the following:

  • Parts of the Arduino programming language
  • Various sections of the Arduino IDE text editor
  • Comments in the Arduino sketch
  • Understanding and writing arduino codes

Parts of the Arduino Programming Language

The arduino programming language can be divided into 3 parts:

  1. Structure
  2. Function
  3. Variables

Arduino Structure:

This has to do with the elements of Arduino code. The figure below shows the content of arduino structure.

Arduino Structure content
Figure 1: Structure content (courtesy of arduino.cc)

Arduino Function:

This is used for controlling the arduino board and carrying out computations. The image below shows lists of various arduino functions.

Lists of Various Arduino Functions
Figure 2: List of arduino functions ( courtesy of arduino.cc)

Arduino Variables:

These include the arduino data types and constants. The figure below shows the various arduino variables and data types used in arduino programming language.

Various arduino variables and data types used in arduino programming language.
Figure 3: Arduino variables and data types (courtesy of arduino.cc)

Various Parts of The Arduino IDE Text Editor

It is assumed the reader has read the previous tutorial titled “Arduino tutorial for beginners”. If you have not, please read it. In that tutorial, we introduced the Arduino development board and set up the programming platform. We also wrote a sketch, (Arduino code is called sketch), implemented a simple circuit and however.

Parts of arduino IDE text editor
Figure 4: Various parts of the Arduino IDE sketch editor

Figure 4 above shows and explains the various parts of the arduino IDE text editor, which include:

  • Quick action buttons’ bar
  • Sketch file tabs
  • Sketch writing area
  • Status bar
  • Program notification area

Quick action buttons’ bar: 

The quick action buttons’ bar contains various buttons that are used in the text editor for editing, settings, etc. a lot can be done using the buttons in this bar.

Sketch file tabs: 

This tab gives you information about the name of the sketch.

Sketch writing area: 

This is the main area where you write the arduino codes or sketch for your design.

Status bar: 

This bar tells you the condition of the sketch you wrote, it gives you information whether the sketch is compiling, has compiled, uploading, done uploading, did not compile, did not upload, had problem while compiling or uploading, etc.

Program notification area: 

This area gives you more information about the status bar, error messages, how to fix them, etc

Comments In Arduino Sketches

Before we discuss the Arduino sketch comments, let’s first note something about the IDE. The texts in the Arduino IDE sketch editor in figure 5 below have various colours and shades; this mix of colours helps in reading and understanding the sketch. Comments in the arduino IDE text editor comes in two forms, the “block and line comment lines

Figure 5: Arduino IDE sketch editor

BLOCK COMMENT

The section of the sketch that started with /* and ended with */ (lines 1 and 13) contains a write-up. This write-up that is written within this enclosure is not seen or noticed by the Arduino. The write-up is called a “Block Comment”. It is a text that is not used by the Arduino at all. It is there as a comment to help humans understand the microcontroller executable code lines of the sketch. Just note that anything between the /* and */ is ignored by the Arduino completely.

LINE COMMENT

The line comment is made after two division slashes //. The comment made after the double strokes is often a short comment. Example of a line comment can be seen on lines 14, 16, 19. Just like the block comment, the texts following the two strokes are not recognised by the microcontroller as data to be processed or executed. The arduino board does nothing to the texts.

In lines 21 – 24, the microcontroller will only recognise and execute everything written in the code except texts written after //

Understanding And Writing Arduino Code

Programming arduino board requires a good knowledge of the arduino programming language parts listed below which we mentioned earlier:

  1. Arduino Structure
  2. Arduino Function
  3. Arduino Variables

To be good at writing arduino codes, one needs to get acquainted with the three parts of the arduino programming language. Programming arduino board to realise an electronic design requires logic and algorithm like any other programming language. Logic and algorithm are the step-by-step procedures that can be followed to solve a problem. It should be noted that there are several logical and algorithmic ways to solve a coding problem in arduino, however, the arduino programming language syntax and semantics must be unchanged.

Take for example, if I want to boil yam. I may decide to peel off the back before I cook it, another person may decide not to peel off the back. The point there is my algorithm and the other person’s algorithm (i.e. step-by-step procedures) are not the same, but we must use the same syntax, which can be likened to saying we must put the yam in a pot of water and boil on fire. The difference in our results could be how long it took for each person’s yam to cook. But as long as the basic rules were obeyed, irrespective of our different algorithms, expected results will be realised. In the next tutorial we will delve into explaining and utilising the arduino programming language tools and features to write sketches and design circuits.

You should also read Arduino Sketch Structure, Statement and Function.

Summary:

In this tutorial we were able to:

  • List and explain the various parts of the arduino programming language.
    1. Arduino Structure
    2. Arduino Function
    3. Arduino Variables
  • List and explain the various parts of the arduino IDE text editor
  • Explain comments in arduino sketch
  • Understood the underlying factor behind writing arduino sketch

Leave a Reply

Your email address will not be published. Required fields are marked *