-
Notifications
You must be signed in to change notification settings - Fork 6
/
DriveCircle2.java
46 lines (34 loc) · 1.23 KB
/
DriveCircle2.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package ev3.exercises;
import lejos.hardware.Button;
import lejos.hardware.Sound;
import lejos.hardware.motor.*;
import lejos.hardware.port.*;
import ev3.exercises.library.*;
public class DriveCircle2
{
public static void main(String[] args)
{
TouchSensor touchSensor = new TouchSensor(SensorPort.S1);
System.out.println("Drive Circle (2)\nand Stop\n");
System.out.println("Press any key to start");
Button.LEDPattern(4); // flash green led and
Sound.beepSequenceUp(); // make sound when ready.
Button.waitForAnyPress();
// create two motor objects to control the motors.
UnregulatedMotor motorA = new UnregulatedMotor(MotorPort.A);
UnregulatedMotor motorB = new UnregulatedMotor(MotorPort.B);
// set motors to different power levels. Adjust to get a circle.
motorA.setPower(70);
motorB.setPower(30);
// wait doing nothing for touch sensor to stop driving.
while (!touchSensor.isTouched()) {}
// stop motors with brakes on.
motorA.stop();
motorB.stop();
// free up resources.
motorA.close();
motorB.close();
touchSensor.close();
Sound.beepSequence(); // we are done.
}
}