Setting the beak color on the Finch (setLED and sleep commands)
To set the Finch's beak color you must:
- Import the Color class at the very top of your program
- Create a Finch object in your program's main method
- Use the setLED method
Choose a color (
Here are some
colors: )
- Color.RED
- Color.GREEN
- Color.BLUE
- Color.YELLOW
- Color.WHITE
- Give the Finch time to display the color before the program stops.
To give the robot time to complete a task use the sleep method.
The amount of time to wait is measured in milliseconds (1000 = 1 second)
|
- import java.awt.Color;
- Finch robo = new Finch();
- robo.setLED(Color.RED);
- robo.sleep(1000)
|
About colors
- You can look up more colors in the Java API (the official reference for the Java language)
- Color is part of the awt (advanced window technique) library of classes useful for drawing.
You have to import it to use it because it is not part of the standard, basic Java.
- The beak color is made up of red, green and blue LED lights that can be blended to make any of over 16 million different colors by setting the red,green, and blue components separately.
- setLED(red,green,blue) sets the beak to a custom color where red, green and blue are integers (whole numbers) from 0 (off) to 255 (all the way on)
- setLED(255,0,0) sets the beak to red
- setLED(0,0,0) sets the beak to black (all lights off)
- setLED(255,255,255) sets the beak to white (all lights on)
- setLED(0,255,255) sets the beak to turquoise (blue and green together)
About sleep
Sleep is required to ensure that the program's output is visible to the user - e.g., if I set the LED to green and then to blue without giving the Finch time to display the colors, the LED will flash green for an infinitesimally short period.
The Finch needs to be given time to: move, talk, display lights and more.
When your program ends the Finch stops what it is doing, so always give it time to do the commands you tell it to do.