Marker detection
Besides detecting a ball, Wheelson can also detect markers. So, let’s program him to detect a carrot marker and write out the word “carrot” on the marker’s location and make him do a 360° turn after detecting the 360° marker.
As always, the first steps are the same - click on “New Sketch” in CircuitBlocks, choose “Wheelson” as your device, and “Block” as the Sketch type. After clicking “Create” the drawing board will open.
The next steps are the same as with the program we just created for detecting a ball.
This program will write out some text on the screen let’s set the font size, type, and color. From the “Display” function grab the “set font size to”, “set font type”, and “set font colour to” blocks one at a time and place them right below the “Arduino run first:” text.


Let’s set the font size to “1”, font type to “2”, and let’s leave the font color “green”. Just like this:

From the “Vision” section on the left side of the screen, grab the “fetch camera frame” block and drop it below the “Arduino loop forever:” text.


The camera frame is now in Wheelson’s memory so we have to add a block that will draw this on the screen. So, let’s add the “draw camera frame” block from the “vision” section.


Now, let’s give Wheelson an instruction to detect markers. From the “Vision” section drag the “detect markers” block and drop it right below the “draw camera frame” block.


The same thing as before, this marker detection is now in Wheelson’s memory so we have to add a block that will draw this out to the screen.
To do that, let’s take the “draw sprite to display” block from the “Display” section and add it below the “detect markers” block.

Now, let’s add the “when marker is detected” block from the “Vision” section on the left.


Here we’ll add blocks that will instruct Wheelson to write out the word “CARROT” on the marker’s location on the screen.
To do that, take the “print x, y” block from the “Display” section and place it inside the “when marker is detected” block.


Let’s give Wheelson the order to write out the word “CARROT” now.
You’ll see an empty while block right next to the word print in the “print” block.
Type the word “CARROT” here. Just like this:

We want Wheelson to type out this word when he detects the carrot marker so select the carrot marker from the drop-down menu.

Next, you’ll see that there are two red blocks on the bottom of the “when marker is detected” block. We’ll add those blocks to the x and y values of the “print” block.
First, take the “marker.projected[0].x” block and drag and drop it in the x value.
Then, take the “marker.projected[0].y” block and drop it in place of the y value.


Ok, Wheelson is now ready to detect the Carrot marker and write out the word “CARROT” on the screen. We’re halfway there.
Let’s instruct Wheelson to detect the 360° marker and do a 360° turn when he detects it.
Grab the “when marker is detected” block from the “Vision” section again and drop it to the drawing board. Choose the 360° marker from the drop-down menu.

Then, from the “Display” section select the “clear the display with” block and place it in the empty space of the “when marker is detected” block. Let’s keep the screen color Black.


Grab the “print x, y” block from the “Display” section and put it right underneath the “clear the display with” block.
Let’s also add some values to the print block. Let’s tell Wheelson to print “360” to the screen and let’s give x a coordinate 75, and y a coordinate 50. This is the location on the screen where “360” will be written.

Of course, these instructions are still only in Wheelson’s memory so we have to add a block that will bring this to the screen. That’s why you’ll take the “draw sprite to display” block and add it below the “print x, y” block.

Ok, now comes the fun part - making Wheelson spin. For this, we’ll need the “set motor speed” block from “I/O” section. Place the block underneath the “draw sprite to display” block


Wheelson’s speed goes up to 127 so let’s set the speed value to “120” to make it go quite fast.

Let’s repeat this step for the remaining three wheels.
To make Wheelson do a 360° turn we’ll instruct the wheels on Wheelson’s left side to turn forward and instruct the wheels on the right side to turn backward.
We’ll do this by using negative and positive values. Positive values will turn the wheels forward, and negative values will turn them backward.
Bear in mind that Wheelson’s speed goes from -127 to +127. Negative values will turn Wheelson’s wheels backward, and positive values will turn them forward. To stop the wheels from turning use value “0”.

Good job! Now we’ll add some blocks to make Wheelson stop turning after 1.5 seconds.
For that, go to the “Time” section and find the “wait milliseconds” block. Drop it right below the “set motor speed” blocks and change the value to “1500” milliseconds to make it stop turning after 1.5 seconds.


To make Wheelson’s wheels stop turning we have to set the speed to “0”. Let’s grab the “set motor speed” blocks again and set the speed to “0” for each of the four wheels. Just like this:

Woo hoo! Another sketch finished. This is how the sketch looks like in the end:

Don’t forget to save and name your sketch. Then, click the “run” button and grab the Carrot and 360°markers.
Place the markers in front of Wheelson’s camera and watch it write out the word “CARROT” on the Carrot marker’s location when he detects the Carrot marker, and do a 360° spin when he detects the 360° marker.
It might take a few moments for your sketch to compile, so please be patient.
If the project doesn't work when you try to Run it, go through the sketch one more time.