These methods let you know which way the Finch is facing.
They use the accelerometer built into the Finch.
isBeakDown() This method returns true if the beak is pointed at the floor, false otherwise |
isBeakUp() This method returns true if the beak is up (Finch sitting on its tail), false otherwise |
isFinchLevel() This method returns true if the Finch is on a flat surface |
isFinchUpsideDown() This method returns true if the Finch is upside down, false otherwise |
isLeftWingDown() This method returns true if the Finch's left wing is pointed at the ground |
isRightWingDown() This method returns true if the Finch's right wing is pointed at the ground |
Here is a sample program that will keep the Finch's beak black (all lights off) as long as the finch is level, and then turn it white for 3 seconds when the Finch rolls or pitches
import edu.cmu.ri.createlab.terk.robot.finch.Finch; /** * Created by: Mrs O-C * Date: 2011 * Respond to orientation methods */ public class OrientationTest { public static void main(String[] args) { // Instantiating the Finch object named jay Finch jay = new Finch(); jay.setLED(0,0,0); // set to black. red, green and blue lights off while(jay.isFinchLevel()){ // keep repeating this loop as long as jay is level jay.sleep(100); // wait a tenth of a second before checking again } jay.setLED(255,255,255); // set to white. all 3 colors on = white jay.sleep(3000); // leave the white light on for 3 seconds System.out.println("finished"); // prints to the screen to let you know the program is over // Always end your program so the finch will be reset for the next program jay.quit(); System.exit(0); } } |
Remember that ! means NOT in Java. So if you want the light to stay black as long as the Finch is NOT level, and then turn white once the Finch is returned to a level orientation, the only line you would have to change is
while (!jay.isFinchLevel()){ // keep repeating this loop as long as jay is NOT level // the loop will not end until jay IS level