Introduction
Because PopPet's brain is powered by an Arduino, we need to use the software meant to program an Arduino to program PopPet's brain. The software to program an Arduino is called the 'Arduino IDE'. All of the sample code provided was written in the Arduino IDE version 1.0.1, which you can download here. It is best to use this version of the IDE to make sure everything works, however, newer versions of the Arduino IDE may be used.
Once you have downloaded, installed and opened the Arduino IDE you can continue on with following instructions.
Once you have downloaded, installed and opened the Arduino IDE you can continue on with following instructions.
Tip: In Arduino, a 'Sketch' is the name of the code file we create. Whenever we refer to a Sketch, we simply mean the code.
The first step in learning how to program PopPet is to understand how an Arduino Sketch works.
In Arduino Sketches there are two core parts, the 'Setup' and the 'Loop.
The Setup part of the Sketch only happens once, when the Arduino first turns on. The Setup is used to configure everything and tell it what it is supposed to do. For example, in the Setup section of the PopPet Sketch, we tell the Arduino that the pins we have the motors connected to are outputs. This lets the Arduino board know that we will be sending a signal out to the motors to get them to spin.
The Loop part of the Sketch happens over and over again for as long as the Arduino board is turned on. For example, in the Loop section of the PopPet Sketch, we constantly check to see if there is an object in front of PopPet and if there is, PopPet must avoid it.
In Arduino Sketches there are two core parts, the 'Setup' and the 'Loop.
The Setup part of the Sketch only happens once, when the Arduino first turns on. The Setup is used to configure everything and tell it what it is supposed to do. For example, in the Setup section of the PopPet Sketch, we tell the Arduino that the pins we have the motors connected to are outputs. This lets the Arduino board know that we will be sending a signal out to the motors to get them to spin.
The Loop part of the Sketch happens over and over again for as long as the Arduino board is turned on. For example, in the Loop section of the PopPet Sketch, we constantly check to see if there is an object in front of PopPet and if there is, PopPet must avoid it.
In Arduino, we tell it where the Setup and Loop sections are by writing:
void setup and loop
The weird looking brackets that you can see are sort of like code holders. They hold code in blocks. The '{' signifies the start of a block and the '}' signifies the end of a block. Everything between the { and the } is part of the thing above. So everything between the first { and } is part of the Setup and everything between the second { and } is part of the Loop.