... | ... | @@ -82,6 +82,33 @@ The goal is to implement a ButtonListener for the ESCAPE button, so you can exit |
|
|
We are planning to do this by looking at the leJos tutorial on how to use a ButtonListener.
|
|
|
|
|
|
#### Results
|
|
|
```
|
|
|
import lejos.nxt.*;
|
|
|
/**
|
|
|
* The locomotions of a LEGO 9797 car is controlled by
|
|
|
* sound detected through a microphone on port 1.
|
|
|
*
|
|
|
* @author Ole Caprani
|
|
|
* @version 23.08.07
|
|
|
*/
|
|
|
public class SoundCtrCar
|
|
|
{
|
|
|
private static int soundThreshold = 90;
|
|
|
private static SoundSensor sound = new SoundSensor(SensorPort.S1);
|
|
|
|
|
|
private static void waitForLoudSound() throws Exception
|
|
|
{
|
|
|
int soundLevel;
|
|
|
Button.ESCAPE.addButtonListener(new ButtonListener() {
|
|
|
public void buttonPressed(Button b) {
|
|
|
LCD.drawString("escape pressed", 0, 0);
|
|
|
System.exit(0);
|
|
|
}
|
|
|
public void buttonReleased(Button b) {
|
|
|
LCD.clear();
|
|
|
}
|
|
|
});
|
|
|
```
|
|
|
|
|
|
#### Conclusion
|
|
|
|
... | ... | |