4 public class SpeedTest {
6 static final int TOTALTIME = 60000;
8 public static void main(String [] args) throws Exception {
10 Random rand = new Random();
11 LightSensor ls = new LightSensor(SensorPort.S3);
12 UltrasonicSensor us = new UltrasonicSensor(SensorPort.S1);
16 /* Disable the speed regulation and close down the associated threads.
17 * This test does not require this type of motion control.
20 MA.regulateSpeed(false);
21 MB.regulateSpeed(false);
22 MC.regulateSpeed(false);
30 int startTime = (int)System.currentTimeMillis();
35 while(totalTime < TOTALTIME) {
36 lightVal = ls.readValue();
37 distVal = us.getDistance();
38 tacho = MB.getTachoCount();
39 int RN = rand.nextInt( 100) + 1;
40 int V3 = (lightVal + distVal + tacho)*100/RN;
42 // Uncomment the following to produce display output as per the original test.
43 LCD.drawInt(tacho,0,0);
44 LCD.drawInt(V3, 0, 1);
46 LCD.drawInt(iteration, 0, 4);
48 // Set motor speed for B and C to RN (Using Coast)
55 if(A<0) MA.backward(); else MA.forward();
57 totalTime = (int)System.currentTimeMillis() - startTime;
65 LCD.drawInt(iteration, 0, 4);