Once you have the Arduino IDE set up and working, you can progress to the more interesting subject of actually programming your board. If you have not set up the IDE yet, you can follow these tutorials to get everything working properly.
To begin with, you may want to use an Uno, simply because it is the most documented and simple board available. You could also use a Nano.
Once you have plugged in your board using the USB cable, and selected the port the board is connected to, you can start your epic programming journey.
This is the default code editor that will open if you have never opened code before. It is also the same as the "Bare Minimum" code found in the example codes.
This code can actually be uploaded to your board to "wipe" any code that is already on the board, but that isn't really necessary very often.
There are two small LEDs on your board, which when uploading code to your board should flash.
Te basic "Bare Minimum" code is as follows:
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}
This is what is considered a complete code, as it complies and can be uploaded to the Arduino.
It is important to understand this code structure because this is the absolute backbone of the Arduino programming language called C++. Every Arduino sketch will contain these functions even if it is empty. The sketch will not compile without these two functions. These functions help organize the code for both you and the compiler.
void setup()
This is the first function to be executed in a sketch and it is only executed once every time you upload code or reset the board. This is where we initialize variable values, setup communications (i.e. Serial), setup modes for digital pins (input/output), and initialize any hardware components (sensor/actuator) which will be plugged into the Arduino.
The important thing is to remember that the setup() is a statement that runs only once at the beginning of the sketch, so don't put anything that needs to repeat in here.
void loop()
This is the function that loops infinitely until you power off the Arduino. This is where all the rest of the code belongs.
One thing to keep in mind is that you cannot call global variables in either of these two functions. Global variables and libraries are usually added before the setup function.
A very good resource to have easily accessible while programming is the Arduino reference webpage.
Comments