📜 ⬆️ ⬇️

What kind of special programming language is used for Arduino?

I would like to clarify the situation with the so-called “Arduino programming language”, which is “based on Wiring”. Such combinations of words are often found on the pages devoted to Arduino. On the official website, they write: "... is programmed using the Arduino programming language (based on Wiring)". In fact, there is no particular programming language, and in fact programs are written in C / C ++, and compiled and assembled using the well-known avr-gcc.
All the features boil down to the fact that there is a set of libraries that includes some functions (like pinMode) and objects (like Serial), and when you compile your program, the development environment creates a temporary .cpp file, which, in addition to your code, includes a few more lines, and the result is fed to the compiler and then the linker with the necessary parameters.
For example, you can create a small project with any name, add a minimum of code there, for example:
 --- Test.pde ---
 void setup () {
   pinMode (13, OUTPUT);
 }

 void loop ()
 {
   digitalWrite (13, 1);
   delay (500);
   digitalWrite (13, 0);
   delay (500);
 }
 ---

If you now "sew" the resulting program in the Arduino, then in the folder with the project folder will appear "applet", and in it a bunch of files. These are mainly object classes containing compiled standard functions, as well as a ready-made compiled program in various formats (ELF, ROM, HEX). The most interesting is the .cpp file - this is what our code has become:
 --- Test.cpp ---
 #include "WProgram.h" // here definitions of all Arduino f-th, constants, etc.
 void setup ();  // declare fi s setup () and loop () in which our
 void loop ();  // program for Arduino and spelled
 void setup () {// --- and here is our source from this place ---
   pinMode (13, OUTPUT);
 }

 void loop ()
 {
   digitalWrite (13, 1);
   delay (500);
   digitalWrite (13, 0);
   delay (500);
 } // here our code ran out, again "add-ons"

 int main (void) // here, as is customary in c / c ++ function main ()
 {
	 init ();  // it calls its initialization

	 setup ();  // then our setup () is called
    
	 for (;;) // and in an infinite loop our loop () is called
		 loop ();
        
	 return 0;  // and never get here
 }
 ---

In fact, the Arduino environment does some other small transformations of the source code, for example, decorates non-Latin characters, makes all "#include" upwards, some more trifles can, but the idea remains the same.

')

Source: https://habr.com/ru/post/55254/


All Articles