Finch Robot Dance Party¶
Learning Objectives
After today's activity, you should be able to:
- Program a finch robot to move around and change colors.
- Summarize three methods provided by a finch robot object.
- Define a function with no parameters and no return value.
Getting Started¶
The original finch is a robot designed for computer science education. Watch the video below to get an idea of how the finch works. Also take a few minutes to learn about the finch hardware.
To connect to a finch robot from Python, you will need two files:
- The
finch
module (written in Python): - A USB driver for your operating system:
- libhidapi64.so – Linux
- libhidapi.dylib – macOS
- hidapi64.dll – Windows
Warning
These files won't work on Chromebooks and newer Macs (M1, M2). However, you can run the finch module using a web browser. See the finch installation instructions for details.
Example Code¶
dance.py | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
The first line imports the finch module, and the second line imports the built-in time module.
You will use finch
to control the finch robot and time
to control the program's timing.
Line 5 creates a Finch
object and assigns a reference to robot
.
If you have multiple robots, you can call finch.Finch()
multiple times to connect to each robot:
romeo = finch.Finch()
juliet = finch.Finch()
Lines 8–10 turn on the LED, turn on the wheels, and pause the program for 1.5 seconds.
After time.sleep()
returns, Line 13 turns off the LED and both wheels.
Note the following details:
robot.led(red, green, blue)
– values range from 0 to 255; see Google's color picker.robot.wheels(left, right)
– values range from -1.0 to +1.0 and represent percentages.time.sleep(sec)
– controls how long the program will wait before running the next line.