Skip to content

ARDUINO CODE

  1. Arduino code#

The Arduino programming language is a C like language. You can program in a style that is functionally equivalent to C or you can lean more toward Object-Oriented (OO) software methods.

  1. The main difference between C and Arduino is that Arduino is designed for embedded hardware solutions, while C is a general-purpose application language.
  2. While the Arduino language allows for simple code similar to C, it is, in fact, more similar to C++.
  3. In The Arduino Language, there is a special function called setup() that only runs once when the sketch starts.
  4. Then there is the loop() function, which is similar, but not identical, to the main function in C or C++.

An Arduino programming language example#

// IN Arduino, the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(LED_BUILTIN, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);                       // wait for a second
}

Comparison with C version#

Note that while the example below is C-like, as there are no includes of libraries or macros that would serve to make the code work for pinMode(), delay(), or digitalWrite(). So, the following example serves to show the maincore differences between the C language and the Arduino Language.

/* the main() function does NOT run over and over again forever, so we need another mechanism here. 
This is seen in the while(1){} construct below.
*/
void main() {
  setup();              // Here we must call the setup from within the main() function. 

  while(1){             // This emulates the loop() idea in Arduino
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);                       // wait for a second
  }
}

void setup() {
// initialize digital pin LED_BUILTIN as an output.
  pinMode(LED_BUILTIN, OUTPUT);
}

The Arduino IDE#

Attribution: M0OOZ

Limitations to the IDE#

The IDE supports both C and C++ code. However, attempting to use main() instead of loop() will yield an error.

  1. There are overhead costs associated with using the Arduino language and its integrated development environment.

  2. There is unavoidable software that is placed in your object code after compilation.

  3. Also, some of the built-in functions, like delay(), use AVR clocks, and this may affect how you use the AVR when you write code that uses the same clocks and interrupts.

All of that said, it is possible to produce complex programs (sketches) in Arduino, although the process may be challenging for people unfamiliar with programming.

Furthermore, the IDE is not considered to be professional. It lacks many of the features even a simple IDE such as Geany, ATOM or the MICROSOFT IDE offering which is not open source.