import lejos.hardware.KeyListener;
class ButtonListener implements KeyListener {
+
@Override
public void keyPressed(Key k) {
+ LCDPrinter.print("Bye");
System.exit(0);
}
import lejos.utility.Delay;
public class Main {
+ public static Arbitrator arbitrator;
public static void main(String[] args) {
+ String[] sounds = new String[]{
+ "bootaudio.wav",
+ "bootsystem.wav",
+ "bounds.wav",
+ "bump.wav",
+ "calibrate.wav",
+ "detect.wav",
+ "takeoff.wav",
+ "rick.wav"
+ };
+
+
EV3 brick = LocalEV3.get();
LCDPrinter lcdprinter = new LCDPrinter(brick.getGraphicsLCD(), Font.getSmallFont());
LCDPrinter.print("Starting up systems");
LCDPrinter.print("Loading audio...");
Audio audio = brick.getAudio();
WavPlayer wavplayer = new WavPlayer(audio);
+ wavplayer.preLoad(sounds);
wavplayer.start();
- WavPlayer.playWav("boot.wav");
+ WavPlayer.playWav("bootaudio.wav");
LCDPrinter.print("Loading keylistener...");
brick.getKey("Escape").addKeyListener(new ButtonListener());
WavPlayer.playWav("calibrate.wav");
LCDPrinter.print("Initializing arbitrator...");
- Arbitrator arb = new Arbitrator(behaviorList);
+ Main.arbitrator = new Arbitrator(behaviorList);
WavPlayer.playWav("takeoff.wav");
- Delay.msDelay(1850);
+ Delay.msDelay(2000);
LCDPrinter.print("Takeoff!");
- arb.start();
+ Main.arbitrator.start();
lightSensor.close();
ultraSensor.close();
}
private float black, white, dist;
public StayInFieldBehaviour(NXTLightSensor lightSensor, EV3LargeRegulatedMotor leftMotor, EV3LargeRegulatedMotor rightMotor) {
- super(rightMotor, leftMotor, "bound.wav");
+ super(rightMotor, leftMotor, "bounds.wav");
light = lightSensor.getRedMode();
samples = new float[light.sampleSize()];
calibrate();
public class WandererBehaviour implements Behavior {
private EV3LargeRegulatedMotor leftMotor, rightMotor;
+ private long play = 0;
public WandererBehaviour(EV3LargeRegulatedMotor leftMotor, EV3LargeRegulatedMotor rightMotor){
this.leftMotor = leftMotor;
@Override
public void action() {
+ if(System.currentTimeMillis() - play > 30000){
+ WavPlayer.playWav("rick.wav");
+ play = System.currentTimeMillis();
+ }
leftMotor.forward();
rightMotor.forward();
}
package nl.ru.des;
+import java.io.BufferedInputStream;
import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
import lejos.hardware.Audio;
import lejos.utility.Delay;
public WavPlayer(Audio audio){
this.audio = audio;
- audio.setVolume(100);
+ audio.setVolume(Audio.VOL_MAX);
+ }
+
+ public void preLoad(String[] files){
+ LCDPrinter.print("Preloading audiofiles...");
+ for(String sound : files){
+ try {
+ LCDPrinter.print("Preloading: " + sound);
+ InputStream inp = new BufferedInputStream(Class.class.getResourceAsStream("/nl/ru/des/sounds/" + sound));
+ File f = new File(sound);
+ if(f.exists()){
+ inp.close();
+ LCDPrinter.print(sound + " already exists, skipping...");
+ continue;
+ }
+ FileOutputStream outp = new FileOutputStream(sound);
+ byte[] buffer = new byte[1024];
+ int length;
+ while ((length = inp.read(buffer)) > 0){
+ outp.write(buffer, 0, length);
+ }
+ outp.close();
+ LCDPrinter.print("Done...");
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
}
@Override
public void run(){
+ File c;
while(true){
if(current != null){
- File c = new File(current);
+ c = new File(current);
if(c.canRead()){
audio.playSample(new File(current));
+ } else {
+ LCDPrinter.print("can't load: " + current);
}
current = null;
}
- Delay.msDelay(200);
+ Delay.msDelay(00);
}
}
}
\ No newline at end of file
-echo "Audio system loaded" | espeak --stdout | sox - -r 8000 -b 8 bootaudio.wav
-echo "Ready for calibration" | espeak --stdout | sox - -r 8000 -b 8 bootsystem.wav
-echo "Succesfull calibration" | espeak --stdout | sox - -r 8000 -b 8 calibrate.wav
-echo "Takeoff in 3 2 1 go" | espeak --stdout | sox - -r 8000 -b 8 takeoff.wav
-echo "Almost out of bounds" | espeak --stdout | sox - -r 8000 -b 8 bounds.wav
-echo "Bumped against low object" | espeak --stdout | sox - -r 8000 -b 8 bump.wav
-echo "Detected big object" | espeak --stdout | sox - -r 8000 -b 8 detect.wav
+echo "Audio system loaded" | espeak --stdout | sox -V - -c 1 -r 8k -b 8 bootaudio.wav
+echo "Ready for calibration" | espeak --stdout | sox -V - -c 1 -r 8k -b 8 bootsystem.wav
+echo "Succesfull calibration" | espeak --stdout | sox -V - -c 1 -r 8k -b 8 calibrate.wav
+echo "Takeoff in 3 2 1 go" | espeak --stdout | sox -V - -c 1 -r 8k -b 8 takeoff.wav
+echo "Almost out of bounds" | espeak --stdout | sox -V - -c 1 -r 8k -b 8 bounds.wav
+echo "Bumped against low object" | espeak --stdout | sox -V - -c 1 -r 8k -b 8 bump.wav
+echo "Detected big object" | espeak --stdout | sox -V - -c 1 -r 8k -b 8 detect.wav