public static void Measurement() { // execute all actions of this state LCD.drawString("Measurement", 0, 3); btThread.popElement(); Sound.beep(); Sound.beep(); // lower sensor by RCX motor tempMotor.setPower(-100); tempMotor.setPower(0); for (int i = 0; i < nrcolors; i++) { if (colorsens.getColorID() == lakes[i].color && !lakes[i].found) // kleuren komen overeen lakes[i].celsius = tempSensor.getCelcius(); lakes[i].found = true; return; } // raise temp sensor tempMotor.setPower(100); btThread.write(500); // sends the message 'action done' // leg de huidige tijd vast voor alle transitions met een timeoutcondition long starttime = System.currentTimeMillis(); // when done, wait for a trigger for a transition boolean transitionTaken = false; while (!transitionTaken) { if ((lakes[0].found && lakes[1].found && lakes[2].found)) { current = State.FINISHED; transitionTaken = true; } else if ((true)) { current = State.WATCH; transitionTaken = true; } } }
// a method for every state public static void Btinit() { // execute all actions of this state LCD.drawString("Btinit", 0, 3); LCD.drawString("Waiting...", 0, 0); LCD.refresh(); BTConnection btc = Bluetooth.waitForConnection(); LCD.clear(); LCD.drawString("Connected", 0, 0); LCD.refresh(); DataInputStream dis = btc.openDataInputStream(); DataOutputStream dos = btc.openDataOutputStream(); // BTfunctionality btThread = new BTfunctionality("SlaveReader",dis,dos); btThread = new BTfunctionality("SlaveReader", dis, dos); btThread.start(); // leg de huidige tijd vast voor alle transitions met een timeoutcondition long starttime = System.currentTimeMillis(); // when done, wait for a trigger for a transition boolean transitionTaken = false; while (!transitionTaken) { if ((true)) { current = State.WATCH; transitionTaken = true; } } }
public static void Finished() { // execute all actions of this state LCD.drawString("Finished", 0, 3); Sound.beep(); Sound.beep(); Sound.beep(); btThread.write(300); // sends the message 'all done' }
public static void Colorflag() { // execute all actions of this state LCD.drawString("Colorflag", 0, 3); Sound.beep(); btThread.write(400); // sends the message 'new color found' // leg de huidige tijd vast voor alle transitions met een timeoutcondition long starttime = System.currentTimeMillis(); // when done, wait for a trigger for a transition boolean transitionTaken = false; while (!transitionTaken) { if ((starttime + 30000 <= System.currentTimeMillis())) { current = State.WATCH; transitionTaken = true; } else if ((btThread.peekElement() == 500)) { current = State.MEASUREMENT; transitionTaken = true; } } }
public static void Sonarflag() { // execute all actions of this state LCD.drawString("Sonarflag", 0, 3); Sound.beep(); btThread.write(sonar.getDistance()); // sends the data from the sonar // leg de huidige tijd vast voor alle transitions met een timeoutcondition long starttime = System.currentTimeMillis(); // when done, wait for a trigger for a transition boolean transitionTaken = false; while (!transitionTaken) { if ((true)) { current = State.WATCH; transitionTaken = true; } } }