/***** * ButtonBeep * * A simple brick test class : * Push RUN to start the program; it sounds a descending sequence. * Then * pushing and releasing the VIEW button beeps twice, and * pushing and releasing the PRGM button beeps thrice. * * To test compilation on cs: * $ . unix/environment * $ lejosc ButtonBeep.java * creates ButtonBeep.class * * Jim M * v 1.0 April 30 evening before class - compiled but not run on brick * v 1.5 May 1 in class on PC - found a few bugs, but it basically ran * v 2.0 May 1 after class put in bug fixes; added "press_and_release" * * $Id: ButtonBeep.java 13258 2007-05-01 16:21:57Z mahoney $ ************/ import josx.platform.rcx.*; // imported stuff includes : // Sound.beep(); Sound.buzz(); Sound.beepSequence(); // TextLCD.print(String); // up to 5 characters // Button public class ButtonBeep { // Pause for a given number of seconds. public static void wait(double seconds){ try { Thread.sleep((long)(seconds*1000.0)); } catch (InterruptedException ie){ } } // If the button isn't being pressed, return false immediately. // If it is being pressed, wait for release, and then return true. public static boolean press_and_release(Button b){ boolean state = b.isPressed(); if (state){ while (b.isPressed()){ } } return state; } // Beep n times with a short delay between beeps. public static void nBeeps(int n){ double timeBetweenBeeps = 0.3; // seconds for (int i=0; i