Lesson 1 – Moving and Turning

Java Concepts

Creating a new program, declaring an object, using object methods

Teacher Materials

Get Access

The Finch is a robot designed specifically for students learning computer science. You can write programs to move and turn the Finch, light up its beak, and collect information with its sensors. As you write programs, you will be able to test your programs with the Finch in the real world!

Finch robot 2.0 with 7 output features highlighted: the wheels, the beak LED, the tail LEDs, the LED array, the buzzer, the marker holder, and the plastic brick adapter.

Importing the Finch Library and Declaring a Finch

First, connect to the Finch in the BlueBird Connector, and then open a new file in Java named FinchMoveTurn.java. Make sure this file is inside the Java project that includes the classes for the Finch (Robot.java, Finch.java, and Microbit.java). Create a main() function inside your new file.

To use the Finch in Java, you must declare an object that represents the Finch. This line of code gives your Finch a name, in this case “bird,” and tells the program that it is Finch.

Moving Forward and Backward

Once you have declared a Finch object, you can use methods to make the Finch do different things. For example, the setMove() method makes the Finch move forward or backward. This method takes three parameters, or pieces of information, that you will put inside the parentheses.

All of these parts are shown together in the sample program below. This sample program will move the Finch forward 10 cm at 50% of maximum speed. You can use the // sign or /* and */  to add comments to your program. Comments do not affect how your program works, but they make it easier for other people to use your code (and for you to remember what it does). The disconnect() method closes the program’s connection to the Finch. You should get in the habit of calling this method at the end of every program.

Exercise 1

Try out the sample code shown above. Try out other values for the distance and speed parameters.

To add more movements to your program, just use setMove() again. In Java this is often referred to as calling the method. This program calls the method setMove() twice to make the robot move forward 25 cm quickly and then back 25 cm slowly.

Exercise 2

Write a program that makes the Finch move forward, then backward, then forward, and then backward again. The robot should end 15 cm behind where it started.

Turning the Finch

Turning the robot is very similar to moving the robot forward or backward. Use the setTurn() method to turn the Finch. 

Exercise 3

Write a program that makes the robot turn left in a full circle and then right in a full circle. The two turns should be at different speeds.

Exercise 4

Write a program that makes the Finch move in a square and return to where it started.

Exercise 5

Draw a simple picture with the Finch. You can place a marker through the hole in the Finch to draw your picture on a large sheet of paper. We highly recommend using a brush tip marker with the Finch. These markers work well. If you use a marker with a harder tip, the friction of the marker may make your drawing less accurate.

Exercise 6

Create a simple maze using cardboard or masking tape. Then program your Finch to move through the maze!

Back to Top