Class RcxBrick
java.lang.Object
io.github.jabrena.juno.api.lego.RcxBrick
Direct commands to an RCX brick that answer back, over the same infrared link as
RcxRemote (set it up with RcxRemote.begin(int, int) first, with both the IR LED and the IR
receiver module wired). It reads the touch sensors plugged into the RCX's own inputs, so a vehicle
can sense obstacles without extra wiring to the Arduino. Plain Java on Infrared.
Each call is a request and a reply, which takes 100 ms or more; they return -1 when the
brick does not answer (out of range, off, or the IR LED not pointing at it). The opcode and
argument encodings come from the published RCX opcode tables and have not been verified on a brick.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe RCX's three sensor inputs, numbered 1 to 3 on the brick.static final intstatic final intstatic final intThe highest power level ofsetMotorPower(int, int).static final intThe RCX's three outputs, as bits so that several can be combined, e.g.static final intstatic final intstatic final intstatic final intstatic final intstatic final intThe six built-in sounds forplaySound(int).static final intstatic final int -
Method Summary
Modifier and TypeMethodDescriptionstatic intThe brick's battery voltage in millivolts (about 9000 with fresh batteries, and the brick warns below about 6000), or-1if it did not answer.static voidclearSensor(int input) Sets the value of the sensor oninputback to zero, e.g. a rotation sensor's count.static voiddrive(int outputs, int speed) Runs the outputs atspeed,-7..7: the sign is the direction, the size the power level, and0brakes them.static booleanisPressed(int input) Whether the touch sensor oninputis pressed;falsealso when the brick did not answer.static voidmotorFloat(int outputs) Switches the outputs off with the motors free to coast.static voidmotorOff(int outputs) Switches the outputs off with the motors braking.static voidmotorOn(int outputs) Turns the outputsoutputs(OUTPUT_* bits) on, at the power level and in the direction last set.static booleanplaySound(int sound) Plays one of the six built-in sounds,SOUND_*.static booleanplayTone(int frequencyHz, int durationCentiseconds) Plays a tone offrequencyHz(about 31 to 20000 Hz) fordurationCentisecondshundredths of a second (1..255, so up to 2.55 s), then returns without waiting for it to end.static intreadSensor(int input) The value of the sensor oninput(for a touch sensor 1 pressed, 0 released), or-1if no reply.static introtationDegrees(int input) The rotation of the sensor oninputin degrees, as 22.5 degrees per step rounded down.static introtationSteps(int input) The signed rotation count of the sensor oninputin steps (16 per turn), or0if the brick did not answer.static booleansetLightSensor(int input) Configuresinputfor a light sensor reading the light level as a percentage,0..100, whichreadSensor(int)then returns.static voidsetMotorDirection(int outputs, boolean forward) Sets the direction of the outputs, forwards or backwards.static voidsetMotorPower(int outputs, int level) Sets the power level of the outputs,0..MAX_POWER(clamped); it takes effect while they are on.static booleansetRotationSensor(int input) Configuresinputfor a rotation sensor counting 16 steps per revolution, whichrotationSteps(int)androtationDegrees(int)read;clearSensor(int)sets it back to zero.static booleansetTemperatureSensor(int input) Configuresinputfor a temperature sensor, read in tenths of a degree Celsius bytemperatureTenths(int).static booleansetTouchSensor(int input) Configuresinputfor a touch sensor reading1when pressed and0otherwise.static inttemperatureTenths(int input) The temperature oninputin tenths of a degree Celsius (235 is 23.5 degrees), or0if the brick did not answer.
-
Field Details
-
INPUT_1
public static final int INPUT_1The RCX's three sensor inputs, numbered 1 to 3 on the brick.- See Also:
-
INPUT_2
public static final int INPUT_2- See Also:
-
INPUT_3
public static final int INPUT_3- See Also:
-
SOUND_KEY_CLICK
-
SOUND_BEEP
public static final int SOUND_BEEP- See Also:
-
SOUND_SWEEP_DOWN
public static final int SOUND_SWEEP_DOWN- See Also:
-
SOUND_SWEEP_UP
public static final int SOUND_SWEEP_UP- See Also:
-
SOUND_ERROR
public static final int SOUND_ERROR- See Also:
-
SOUND_FAST_SWEEP_UP
public static final int SOUND_FAST_SWEEP_UP- See Also:
-
OUTPUT_A
public static final int OUTPUT_AThe RCX's three outputs, as bits so that several can be combined, e.g.OUTPUT_A | OUTPUT_B.- See Also:
-
OUTPUT_B
public static final int OUTPUT_B- See Also:
-
OUTPUT_C
public static final int OUTPUT_C- See Also:
-
MAX_POWER
-
-
Method Details
-
setTouchSensor
public static boolean setTouchSensor(int input) Configuresinputfor a touch sensor reading1when pressed and0otherwise. Returns whether the brick acknowledged both commands. -
readSensor
public static int readSensor(int input) The value of the sensor oninput(for a touch sensor 1 pressed, 0 released), or-1if no reply. -
setLightSensor
public static boolean setLightSensor(int input) Configuresinputfor a light sensor reading the light level as a percentage,0..100, whichreadSensor(int)then returns. Returns whether the brick acknowledged both commands. -
setRotationSensor
public static boolean setRotationSensor(int input) Configuresinputfor a rotation sensor counting 16 steps per revolution, whichrotationSteps(int)androtationDegrees(int)read;clearSensor(int)sets it back to zero. -
setTemperatureSensor
public static boolean setTemperatureSensor(int input) Configuresinputfor a temperature sensor, read in tenths of a degree Celsius bytemperatureTenths(int). -
rotationSteps
public static int rotationSteps(int input) The signed rotation count of the sensor oninputin steps (16 per turn), or0if the brick did not answer. -
rotationDegrees
public static int rotationDegrees(int input) The rotation of the sensor oninputin degrees, as 22.5 degrees per step rounded down. -
temperatureTenths
public static int temperatureTenths(int input) The temperature oninputin tenths of a degree Celsius (235 is 23.5 degrees), or0if the brick did not answer. -
clearSensor
public static void clearSensor(int input) Sets the value of the sensor oninputback to zero, e.g. a rotation sensor's count. -
motorOn
public static void motorOn(int outputs) Turns the outputsoutputs(OUTPUT_* bits) on, at the power level and in the direction last set. -
motorOff
public static void motorOff(int outputs) Switches the outputs off with the motors braking. -
motorFloat
public static void motorFloat(int outputs) Switches the outputs off with the motors free to coast. -
setMotorDirection
public static void setMotorDirection(int outputs, boolean forward) Sets the direction of the outputs, forwards or backwards. -
setMotorPower
public static void setMotorPower(int outputs, int level) Sets the power level of the outputs,0..MAX_POWER(clamped); it takes effect while they are on. -
drive
public static void drive(int outputs, int speed) Runs the outputs atspeed,-7..7: the sign is the direction, the size the power level, and0brakes them. That is up to four commands, each waiting for the brick's acknowledgement when the receiver is wired, so one call takes a few hundred milliseconds; set the speed once and not in a tight loop. -
batteryMillivolts
public static int batteryMillivolts()The brick's battery voltage in millivolts (about 9000 with fresh batteries, and the brick warns below about 6000), or-1if it did not answer. It is a request and a reply, like the sensor reads. -
playSound
public static boolean playSound(int sound) Plays one of the six built-in sounds,SOUND_*. Returns whether the brick acknowledged the command, which needs the IR receiver wired; the sound then plays on the brick's own speaker and the call returns without waiting for it to end. -
playTone
public static boolean playTone(int frequencyHz, int durationCentiseconds) Plays a tone offrequencyHz(about 31 to 20000 Hz) fordurationCentisecondshundredths of a second (1..255, so up to 2.55 s), then returns without waiting for it to end. Returns whether the brick acknowledged the command. A tone replaces any sound still playing, so wait for the duration before sending the next. -
isPressed
public static boolean isPressed(int input) Whether the touch sensor oninputis pressed;falsealso when the brick did not answer.
-