Lesson 14 – Multiple Finches

Java Concepts

Object-oriented Programming

Teacher Materials

Get Access

Throughout these lessons, you have been using an object of type Finch. The Finch is defined in Java as a class, which is a programming structure that includes all the methods and variables that relate to a single object. An object can be something abstract like a database, but in the case of the Finch, it is a physical object!

Encapsulating methods and variables in classes is called object-oriented programming. A class enables the user to use the class’s methods without having to understand how they are implemented. This is an example of abstraction in computer science. This means that the details are handled once in a piece of reusable code. Others can then use that code to solve new problems without worrying about those details. Methods are also an example of abstraction. 

Connecting Multiple Finches

You can connect up to three Finches (or Hummingbird Bits or micro:bits) with the BlueBird Connector, and then use the Finch class to create multiple independent Finch objects! This means that you can program the robots to interact with one another. In this module you will learn to use two Finches together.

The BlueBird Connector will show all the Finches that are available. To connect two Finches, just click on both of them.

Both Finches should show up in the Connected section. One will be labeled with an ‘A’ and one with a ‘B.’

Using Multiple Finches

In all the previous lessons, you have been declaring just one object of type Finch. If you connect two Finches in the BlueBird Connector, you can declare two Finch objects. When you have more than one Finch object, you must declare each one by calling Finch() with a parameter that is the letter (“A”, “B”, or “C”) that identifies that Finch in BlueBird Connector.

Both of the objects that you declare can access all the Finch methods. For example, this code calls the setBeak() method for both objects to make the two beaks blink together.

Exercise 1

Write a program to make two Finches do some synchronized dancing! The robots should move, light up, and make noise.

You can also use the sensors on one Finch to control the other Finch. For example, this code turns the beak of one Finch on and off using the buttons of the second Finch.

Exercise 2

Write a program that uses one Finch to control the movement of the other Finch. This program should use the getOrientation(), setMove(), and setTurn() methods.

  • When Finch #1 is “Beak down”, Finch #2 should move forward.
  • When Finch #1 is “Beak up”, Finch #2 should move backward.
  • When Finch #1 is “Left wing down”, Finch #2 should turn left.
  • When Finch #1 is “Right wing down”, Finch #2 should turn right.

Exercise 3

Write a program to use one Finch’s accelerometer to directly control the speed of the other Finch’s motors. For example, as you tilt one Finch more to the left, the other Finch should turn left faster. When the beak is tilted further down, the Finch should move forward faster. 

Note: Remember, getAcceleration() returns an array, so you can store the acceleration measurements in individual variables, as in Lesson 8, or you can store them in an array named acceleration and access the elements as acceleration[0], acceleration[1], and acceleration[2].

Exercise 4

What can you think to do with two Finches? Use all that you have learned about Java to come up with a creative program that makes two Finches interact in an interesting way!

Back to Top