I like to start with programming a square as my most basic task for a group in Sphero. You can start with the simple task of rolling each of the 4 sides and then add complexity from there. And most kids are comfortable with 90 degree angles!
This is the simplest way to program a square with Sphero and the most limited. The roll block uses 3 parameters (heading, speed, and duration) and each have to be set individual in this program.
Block Types: Movement
Here we have created two variables, one for Speed (s) and one for duration (d). This allows us to easily change the size of the square by only updated the speed or the duration (or both) rather than updating each roll command. Great opportunity to explore scaling with students and changing only one variable to test a hypothesis.
Block Types: Movement, Variables
Now we are making progress! This program will have a similar outcome as the two previous ones, but has a different flow to it and an extra feature. The first two square programs flowed from top to bottom and then ended. This program sets the three variables and then enters a loop that runs through 4 times, once for each side of the square. On each pass through the loop it does three things:
main LED(random color) sets a new color for the main LED.roll(h, s, d) completes a roll command using the current values for the 3 variables h, s, and d.set(h=h+90) increments the value of h by 90 degrees because that is the change in heading necessary for a square to be programmed. An equilateral triangle would have a different incremented heading (hint: it isn't 60 degrees).If we wanted to change the main LED before each side on what of the previous square programs, we would have needed 4 different main LED blocks. Using one is much better!
Block Types: Movement, Variables, Lights, Operators
Now that you have seen how to program a square using roll, variable, and operator blocks, try some other shapes, like an equilateral triangle or an octagon. Or maybe a pentacontagon (hint: the inside angles for any regular polygon can be determined using the forumula inside angle = ((n - 2) * 180) / n). You can use that formula to write a program to make Sphero roll a regular polygon with n sides.