Commit ab5ee70b authored by Casper's avatar Casper
Browse files

Lesson6

parent e80a9cd4
import lejos.nxt.*;
public class Vehicle1 {
static SensorPort port = SensorPort.S2;
static MotorPort motorLeft = MotorPort.C;
static MotorPort motorRight = MotorPort.B;
static int raw;
static double power;
public static void main(String[] args) throws InterruptedException {
LCD.clear();
while(true) {
raw = port.readRawValue();
// Map 0 to 100
// power = 100.0 - ((100.0 / 1023.0) * raw);
// Map -100 to 100
power = 100.0 - ((100.0 / 1023.0) * raw) * 2;
motorLeft.controlMotor((int)power, MotorPort.FORWARD);
motorRight.controlMotor((int)power, MotorPort.FORWARD);
LCD.drawString("Raw: ", 0, 0);
LCD.drawInt(raw, 4, 0, 1);
LCD.drawString("Power: ", 0, 2);
LCD.drawInt((int)power, 4, 0, 3);
}
}
}
import lejos.nxt.LCD;
import lejos.nxt.MotorPort;
import lejos.nxt.SensorPort;
public class Vehicle2a {
static SensorPort portLeft = SensorPort.S2;
static SensorPort portRight = SensorPort.S3;
static MotorPort motorLeft = MotorPort.C;
static MotorPort motorRight = MotorPort.B;
static int rawLeft;
static int rawRight;
static double powerLeft;
static double powerRight;
public static void main(String[] args) throws InterruptedException {
LCD.clear();
while(true) {
rawLeft = portLeft.readRawValue();
rawRight = portRight.readRawValue();
powerLeft = 100.0 - ((100.0 / 1023.0) * rawLeft) * 2;
powerRight = 100.0 - ((100.0 / 1023.0) * rawRight) * 2;
motorLeft.controlMotor((int)powerLeft, MotorPort.FORWARD);
motorRight.controlMotor((int)powerRight, MotorPort.FORWARD);
LCD.drawString("RawLeft: ", 0, 0);
LCD.drawInt(rawLeft, 4, 0, 1);
LCD.drawString("PowerLeft: ", 0, 2);
LCD.drawInt((int)powerLeft, 4, 0, 3);
LCD.drawString("RawRight: ", 0, 4);
LCD.drawInt(rawRight, 4, 0, 5);
LCD.drawString("PowerRight: ", 0, 6);
LCD.drawInt((int)powerRight, 4, 0, 7);
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment