Arduino Tutorial for Beginners – Setup And Loop Blocks + light LEDs right to left

In this post on Arduino Tutorial For Beginners, this topic about syntax in Arduino and do some exercises in order to get used to Arduino IDE.

First, talk about Embedded we have to know about binary a.k.a logic level and some data types.

  • This is the smallest unit of data in computer with single value either 0 or 1. By this digits we can commute with hardware
  • And in our articles series we’ll define logic 0 is LOW level, 1 is HIGH level, it’s also equivalent 0 – 0 Voltage and 1 – 5 voltage.

About programming language, the Arduino compiler accepts C and C++ as is. In fact many of the open sources libraries are written in C++. Much of the underlying system is not object oriented, but it could be. Thus, “The arduino language” is C++ or C. Therefore, we also have syntax, variable, data types ,… as the other programming language. But with Embedded system , we have some new data types because systems can sometimes define integer to be 8 bits, 16 bits or 32 bits long. Ex:

  • Byte <=> unsigned char (8bits)
  • Uint8_t <=> unsigned char (8bits)
  • Uint16_t : (16bits)
  • Uint32_t : (32bits)
  • …..

Second, I will talk about Arduino function in IDE Arduino. In Arduino IDE , when we create a new project, there are 2 default function will be appear as the picture below. IDEThat is “Setup” function and “Loop” function. Pay attention, we don’t have “Main” function in this IDE we just have 2 functions like that. Both of 2 functions use “void”, it mean in this default function, we don’t need to return any variable. But when you create your function, you can put any data types you want to handle your project. And in setup function we usually setup some function to start and run program in loop function.

Your program run forever inside “Loop” function until you disconnect the power of Arduino. Because we need a device run continuously whole time to check devices: sensor, check weather, led, check button ,..etc, that is reason why we have a loop function, we don’t need a device run once and then off forever. Is it right?

Some Attention!!!

  • To use global variables, you need to init above of “Setup” function.
  • To use local variables, you need to init in a certain function you want.
  • User functions must be put above of “Setup” function to avoid errors.

Okay, that are all think we need to know when start with Arduino IDE.

Below is the circuit and code to control led from right to left and i will explain in the code’s comment. First i will give you code without function.

Above is without user function, i will give you an example with user function below:

Partner Sites

Be the first to comment

Leave a Reply

Your email address will not be published.