Universal Robot Extension
Ever noticed how most beginner robots have the same purpose? Why not make a standard for blocks.
It is amazing to have so many robot options to choose from. More choices mean you can find what best suits your needs. Most beginner smart robot cars have 2 motors, same HC_SR04 distance sensor, 2 line sensors on the sides of the front wheel and some type of RGB lighting.
We decided that it would be nice to have a general code block set for these objects. So we went ahead and made it. Any robot we make in the future will follow this format, so let’s break it down.
The motors group consists of two basic functions. Driving the specified motor, going forward or backward and from 0% to 100% speed. 100 is the fastest you can go. Then there is the stop function which stops either left or right motors or both.
The distance sensor is usually located at the front of the car. It has two functions, it sends out a pulse and then takes in that pulse and thanks to some handy math functions, calculates the time it takes to get back to the senor to get the distance. One of the silver “eyes” sends the pulse and the other receives. Keep note of this when you think your robot is acting up but one of the sensors is covered up!
In the extension, the block returns a number. So if we wanted the Micro:bit to display the distance, we would use the Basic “show number” function like in the picture below.
The way the line readers work is that they are constantly reading the pin it is set to and returning either “True” (That it detects a line) or “False” (If no line is detected). This is called a boolean statement. When I went about making the block, I decided it would best be read as a sentence. So we will use an “If statement” block when we use the line reader block like the example below.
Lights and Other
Sometimes, there is no function to control the lights. This is because there is already a handy Neopixel extension. This extension is a requirement in most of the robots but it is still easy to use. Depending on the robot, the blocks look like this…
In this case, I named my variable for the lights “MaqueenLights”. By default, it will say “Strip”. The other two factors are the pin being used and how many LEDs. We can figure out how many LEDs by just counting the LEDs on the car but for what pin is being used, in this case, pin P15, is a little different each time so make sure you read the post about it.
Sometimes, certain cars will have more features than others. In this case, they will be covered in their post while this one is meant to convey the basic, universal ones