# Introduction

Arduino is an open-source electronics platform that allows us to control hardware easily. An Arduino is powered by a microcontroller. That means it does not have full power like a CPU (the brains behind the computer you are using right now), but it has enough power to control hardware electronics by specifying what wire to output a voltage to and which wire to read the voltage from. We control the output and input of the Arduino pins by writing a program using C++ language.

There are many Arduino boards. The simplest board to use and learn with is the Uno board, which you can see above. The Uno board has pins that you can connect wires to easily. Each pin has a label next to it. We will cover later what these labels mean.

# Sketch

A Sketch is an Arduino program that gets compiled and uploaded to the Arduino board. To tell the Arduino how to control the electronics that we connect to it, we need to write a program, a Sketch, that defines what we want the Arduino to do.

//this is a comment
//setup function, runs only once when the Arduino starts
void setup() {

}
//loop function, runs over and over again
void loop() {

}

The above code is the main structure of every Sketch (Arduino program) in C++. We will go through each part separately.

# Comments

The first line of the program is a comment. A comment means that this line will not become part of the program compiled and uploaded to the Arduino board. It is just available for the reader of the programs (humans).

In C++ we can have two types of comments: one-line comment and comment block.

# One-line Comment

The comment needs to start with //. Anything that comes after the // will be ignored by the compiler.

What is a compiler?

The Arduino board does not understand the code that we write directly. Our C++ code will go through another program (known as a compiler) that will read our code, validate that it does not have errors, and then generate machine code that the Arduino can understand. This process is known as compiling the code.

# Block Comment

A block comment can contain multiple line comments. To start the block we use /* and to end the block we use *\. A block comment will be ignored by the compiler of Arduino, but might have useful information for the reader of the program. For example when you submit your solution to your teacher, at the beginning of your program file you can have a block comment that shows your information.

/*
    Student ID: 0123456
    Team Name: Cool Team
    This program does blablabla 

*/

# Arduino Functions

A function is a way to group multiple lines of code and give them a name. Whenever we use that name, the program will call all the lines of code inside of that function. In the next chapters we will learn more about functions and how to write our own.

The Arduino software simplifies writing a program to control the board by defining two functions for us. We will be writing our code inside these functions.

# Setup Function

The setup function in the Sketch program will be called by the Arduino board when we first turn it on ONCE.

This is important to keep in mind. Whatever we want to setup at the very beginning, we will write that code inside the setup function.

void setup() { 
    //write the code that will run ONCE
    //when the Arduino is first turned on
}

# Loop Function

The second function in a Sketch program is the loop function. This function will keep on being called over and over again. Until you turn off the Arduino board. This is where you will write the code that will control your electronics.

When we are controlling electronics, we usually want to keep doing something over and over again.

For example, imagine that you've connected a push-button and an LED to your Arduino board. And you want the LED to turn on whenever the push-button is pressed.

In the loop function, we will write code that will do the following:

void loop() { 
    /*
        IF the push-button is pressed 
            turn on the LED
        IF the push-button is NOT pressed 
            turn off the LED
    */
}

This code will keep on repeating at a high speed. This will be fast enough for the moment we press the push-button, our code will check that it is pressed and will turn on the LED.