programming: The basics
A program, or sketch, is a set of instructions that the Arno will execute. Computers take the world very literally. They need to be told exactly what to do in a language that they understand. Luckily, programming in Arduino is fairly simple. But you need to know the rules and follow them exactly. Here are a few rules to remember:
To help you follow along, we underline the names of variables and bold programming keywords and other symbols when we’re discussing Arduino code.
- All sketches need to have at least two parts: the setup() and loop() blocks. We’ll explain them below.
- Most lines end with a semicolon ; We normally press the Enter key after the semicolon but Arduino knows that the line ends when it sees a semicolon.
- Arduino is case-sensitive. So the word ‘setup’ is not the same as ‘Setup’. This is true of both Arduino commands and variables that you create.
- When Arduino sees the two character ‘//’ it ignores everything until the end of the line (when the Enter key is pressed). This allows us to add human-readable comments to our sketches. Arduino doesn’t need to know what our comments mean. They’re used to describe to other people what the program does and to remind ourselves what we were thinking when we wrote it. You can also include a block of several lines of comments in a sketch by starting the block with /* and ending it with */.
To help you follow along, we underline the names of variables and bold programming keywords and other symbols when we’re discussing Arduino code.