Moderators: roger, 99jonathan, imaqine
byte[] newAddress = {(byte) 0xA0, (byte) 0xAA, (byte) 0xA5, (byte) 0x04};
I2CSensor s1 = new I2CSensor(SensorPort.S1);
s1.sendData(0x41, newAddress, 4);
LightSensor lightSensor = new LightSensor(SensorPort.S1);
CompassSensor compassSensor = new CompassSensor(SensorPort.S1);
compassSensor.setAddress(0x02);
// ------------------------------------------------------------------------
// read out values
while (!Button.ESCAPE.isPressed())
{
int x = 0;
int y = 0;
LCD.drawString(LABEL_COMPASS, x, y);
x+=LABEL_COMPASS.length();
LCD.drawInt((int)compassSensor.getDegreesCartesian(), 3, x , y);
x+=3;
LCD.drawString(" Grad", x, y);
x = 0;
y++;
LCD.drawString(LABEL_LIGHT, x, y);
x+=LABEL_LIGHT.length();
LCD.drawInt(lightSensor.readValue(), 3, x , y);
x+=3;
LCD.drawString("cm", x, y);
LCD.refresh();
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
}
}T ACCL-NX
mndsnsrs
V2.00
U
T
U
LEGO
V1.0T
U
LEGO
V1.0import lejos.nxt.Button;
import lejos.nxt.LCD;
import lejos.nxt.SensorPort;
import lejos.nxt.UltrasonicSensor;
import lejos.nxt.addon.TiltSensor;
public class SensorMuxTest {
public static void main(String[] args) {
LCD.clear();
TiltSensor tiltSensor = new TiltSensor(SensorPort.S1);
tiltSensor.setAddress(0x02);
LCD.drawString("T " + tiltSensor.getSensorType(), 0, 0);
LCD.drawString(" " + tiltSensor.getProductID() , 0, 1);
LCD.drawString(" " + tiltSensor.getVersion() , 0, 2);
UltrasonicSensor ultrasonicSensor = new UltrasonicSensor(SensorPort.S1);
LCD.drawString("U " + ultrasonicSensor.getSensorType() , 0, 3);
LCD.drawString(" " + ultrasonicSensor.getProductID() , 0, 4);
LCD.drawString(" " + ultrasonicSensor.getVersion() , 0, 5);
LCD.refresh();
while (!Button.ESCAPE.isPressed()) {}
}
}import lejos.nxt.Button;
import lejos.nxt.LCD;
import lejos.nxt.SensorPort;
import lejos.nxt.UltrasonicSensor;
import lejos.nxt.addon.TiltSensor;
public class SensorMuxTest {
public static void main(String[] args) throws InterruptedException {
LCD.clear();
TiltSensor tiltSensor = new TiltSensor(SensorPort.S1);
tiltSensor.setAddress(0x02);
tiltSensor.sendData(0x41, (byte) 0x4E); // ADPA On
Thread.sleep(100);
LCD.drawString("T " + tiltSensor.getSensorType(), 0, 0);
LCD.drawString(" " + tiltSensor.getProductID() , 0, 1);
LCD.drawString(" " + tiltSensor.getVersion() , 0, 2);
UltrasonicSensor ultrasonicSensor = new UltrasonicSensor(SensorPort.S1);
LCD.drawString("U " + ultrasonicSensor.getSensorType() , 0, 3);
LCD.drawString(" " + ultrasonicSensor.getProductID() , 0, 4);
LCD.drawString(" " + ultrasonicSensor.getVersion() , 0, 5);
LCD.refresh();
while (!Button.ESCAPE.isPressed()) {}
}
} TiltSensor tiltSensor = new TiltSensor(SensorPort.S1);
SensorPort.S1.i2cEnable(0);
tiltSensor.setAddress(0x02);
tiltSensor.sendData(0x41, (byte) 0x4E); // ADPA On
T ACCL-NX
mndsnsrs
V2.00
T mndsnsrs
mndsnsrs
mndsnsrs
import lejos.nxt.Button;
import lejos.nxt.LCD;
import lejos.nxt.SensorPort;
import lejos.nxt.addon.TiltSensor;
public class SensorMuxTest {
public static void main(String[] args) throws InterruptedException {
LCD.clear();
TiltSensor tiltSensor = new TiltSensor(SensorPort.S1);
tiltSensor.setAddress(0x04);
tiltSensor.sendData(0x41, (byte) 'N'); // ADPA On
Thread.sleep(100);
//UltrasonicSensor ultrasonicSensor = new UltrasonicSensor(SensorPort.S1);
LCD.drawString("T " + tiltSensor.getSensorType(), 0, 0);
LCD.drawString(" " + tiltSensor.getProductID(), 0, 1);
LCD.drawString(" " + tiltSensor.getVersion(), 0, 2);
//LCD.drawString("U " + ultrasonicSensor.getSensorType(), 0, 3);
//LCD.drawString(" " + ultrasonicSensor.getProductID(), 0, 4);
//LCD.drawString(" " + ultrasonicSensor.getVersion(), 0, 5);
LCD.refresh();
while (!Button.ESCAPE.isPressed()) {
}
}
}T
Error Code: -3
U
LEGO
V1.0T ACCL-NX
mndsnsrs
V2.00
Error Code: 0
U
import lejos.nxt.Button;
import lejos.nxt.LCD;
import lejos.nxt.SensorPort;
import lejos.nxt.UltrasonicSensor;
import lejos.nxt.addon.TiltSensor;
public class SensorMuxTest {
public static void main(String[] args) throws InterruptedException {
LCD.clear();
TiltSensor tiltSensor = new TiltSensor(SensorPort.S1);
tiltSensor.setAddress(0x04);
int errorCode = tiltSensor.sendData(0x41, (byte) 'N'); // ADPA On
Thread.sleep(100);
UltrasonicSensor ultrasonicSensor = new UltrasonicSensor(SensorPort.S1);
LCD.drawString("T " + tiltSensor.getSensorType(), 0, 0);
LCD.drawString(" " + tiltSensor.getProductID(), 0, 1);
LCD.drawString(" " + tiltSensor.getVersion(), 0, 2);
LCD.drawString("Error Code: " + errorCode, 0, 3);
LCD.drawString("U " + ultrasonicSensor.getSensorType(), 0, 4);
LCD.drawString(" " + ultrasonicSensor.getProductID(), 0, 5);
LCD.drawString(" " + ultrasonicSensor.getVersion(), 0, 6);
LCD.refresh();
while (!Button.ESCAPE.isPressed()) {
}
}
}gloomyandy wrote:Oh and in the case of the Ultrasonic sensor you probably need to add delay after talking to it as it seems to hang on to the i2c bus for a short while after being accessed...
Users browsing this forum: No registered users and 4 guests