Arduino programming is primarily based on **C++**. However, it incorporates elements of both **C** and **C++** to simplify the development of embedded systems.
Here’s a breakdown of how this works:
### 1. **Arduino Language and IDE:**
- The language used in the **Arduino IDE** is essentially **C++**, but it’s a simplified version designed to make programming more accessible to beginners.
- The Arduino environment automatically takes care of some complexities like setting up the `main()` function, managing libraries, and initializing hardware components, so users don't need to worry about them.
### 2. **Simplified C++:**
- Arduino code, also called a **sketch**, typically contains two main functions:
- `setup()`: Runs once when the Arduino starts up. Used to initialize settings.
- `loop()`: Repeatedly runs after the `setup()`. Used for the main logic.
These functions are built into the **Arduino framework**. Behind the scenes, Arduino is handling many low-level tasks in **C++**, including hardware control, managing memory, and other tasks related to embedded systems.
### 3. **C-Like Features:**
- **C** code is fully compatible with Arduino. In fact, much of the low-level code for microcontroller interaction (like managing registers) is written in **C**.
- You can include **C libraries** and write C-style code using functions, data types, and structures common in **C**.
### 4. **C++ Features in Arduino:**
- The Arduino framework uses many **object-oriented programming (OOP)** features from **C++**. For instance:
- Classes and objects are widely used (e.g., the `Serial` object to handle communication).
- Libraries provided for Arduino are written in C++ and use OOP features like encapsulation and inheritance.
### 5. **Preprocessing:**
- The Arduino IDE performs some preprocessing on the code before passing it to the C++ compiler (e.g., it automatically adds function prototypes, which can be confusing for beginners in standard C/C++ environments).
### Conclusion:
- **Arduino programming is mainly C++**, with simplified C-like syntax and additional built-in functions to ease embedded programming tasks. Although C code can also be used directly, most of the core Arduino libraries and features are written in **C++**.