3 public class SpeedTest {
5 static final int TOTALTIME = 60000;
7 public static void main(String [] args) throws Exception {
9 LightSensor ls = new LightSensor(SensorPort.S3);
10 UltrasonicSensor us = new UltrasonicSensor(SensorPort.S1);
11 Motor.A.regulateSpeed(false);
12 Motor.B.regulateSpeed(false);
13 Motor.C.regulateSpeed(false);
17 int startTime = (int)System.currentTimeMillis();
22 while(totalTime < TOTALTIME) {
23 lightVal = ls.readValue();
24 distVal = us.getDistance();
25 tacho = Motor.B.getTachoCount();
26 int RN = (int)(Math.random() * 100) + 1;
28 LCD.drawInt(tacho,0,0);
29 LCD.drawInt((lightVal + distVal + tacho)*100/RN, 0, 1);
31 LCD.drawInt(iteration, 0, 4);
35 // Set motor speed for B and C to RN (Using Coast)
42 if(A<0) Motor.A.backward(); else Motor.A.forward();
44 totalTime = (int)System.currentTimeMillis() - startTime;
47 LCD.drawInt(iteration, 0, 4);