Jewelbots Tutorials Lesson 2: Hello World Explained, Part 1

Laura & Louisa
2 min readDec 30, 2016

--

At the end of the last lesson, we programmed this:

void setup() {
// put your setup code here, to run once:
}void loop() {
// put your main code here, to run repeatedly:
LED led;
led.turn_on_single(NE, BLUE);
}

This program made one LED of your Jewelbot light up in blue.

Why did this happen? In the next few lessons, we’ll go through the program line by line to explain how all of the program’s parts work together.

First, you will have noticed when you opened the Arduino IDE and created a new sketch that the sketch had some things already written in it. It looks like this:

Namely, each new sketch comes with two functions: setup and loop. These functions are denoted in the following way:

  • the word void (we’ll explain why this is here in a later lesson)
  • the name of the function (e.g. setup or loop)
  • an open curly brace like this: {
  • some empty lines (many programmers call this “whitespace”)
  • a closing curly brace like this: }

In between each function’s curly braces, you also will see a helpful comment that begins with two slashes and gives information about the function:

// put your main code here, to run repeatedly

Any time you see something written after two slashes, it means that is a note for the person reading the code, rather than code the computer will execute.

The Jewelbot understands the names of the setup and loop functions, and knows that when it is unplugged it should first run the setup function once, and then should run the loop function over and over again. Any code that you write between the opening and closing curly braces of a function tells the Jewelbot what to do when that function is run.

We won’t be worrying about the setup function for now — we won’t need it to put anything in it to make our Jewelbots do what we want them to do. We will put all of our code in the loop function.

When you unplug your Jewelbot after uploading the code to it, it will run the loop function over and over again until you turn it off or upload different code to it. Since the code we write turns on the LED, and this code is running over and over again, you will see the LED constantly lit in blue.

Awesome! In the next lesson, we’ll talk about exactly what the two lines of code we wrote in the loop function mean.

--

--