LEGO MINDSTORMS
These components provide control of LEGO MINDSTORMS NXT robots using Bluetooth.
LEGO and MINDSTORMS are registered trademarks of the LEGO Group.
IMPORTANT: All of these components have a BluetoothClient property that must be set in the App Inventor designer (in the browser). The property cannot be set in the blocks editor. The property tells which BluetoothClient component to use for communication with the robot. You will need to explicitly add a BluetoothClient component to your project. If you have one robot, you should have one BluetoothClient component. If you are lucky enough to have two robots and you want to control both of them simultaneously from one application, you'll need two BluetoothClient components in your project. The BluetoothClient component is available from the "Not ready for prime time" section of the palette.
Here's a list of the initial steps you'll need to perform to use one or more of the NXT components:
- Go to the Palette and click on "Not ready for prime time".
- Drag a BluetoothClient component and drop it on to the Viewer.
- The component will automatically be named "BluetoothClient1".
- In the Palette , click on "LEGO MINDSTORMS".
- Drag one of the components, for example NxtDirectCommands, and drop it on to the Viewer.
- In the Properties box , click on the area after BluetoothClient (currently "None...").
- A box appears with a list of all the BluetoothClient components in your project.
- Click on BluetoothClient1 and click OK.
- If desired, add another component, for example NxtColorSensor, and repeat steps 6-8 to set its BluetoothClient property.
Table of Contents
NxtDirectCommands
A component that provides a low-level interface to a LEGO MINDSTORMS NXT robot, with functions to send NXT Direct Commands
Properties
BluetoothClient
- The BluetoothClient component that should be used for communication. Must be set in the Designer
Methods
DeleteFile (text fileName)
- Delete a file on the robot.
DownloadFile (text source, text destination)
- Download a file to the robot.
GetBatteryLevel ()
- Get the battery level for the robot. Returns the voltage in millivolts.
GetBrickName ()
- Get the brick name of the robot.
GetCurrentProgramName ()
- Get the name of currently running program on the robot.
GetFirmwareVersion ()
- Get the firmware and protocol version numbers for the robot as a list where the first element is the firmware version number and the second element is the protocol version number.
GetInputValues (text sensorPortLetter)
- Reads the values of an input sensor on the robot. Assumes sensor type has been configured via SetInputMode.
GetOutputState (text motorPortLetter)
- Reads the output state of a motor on the robot.
KeepAlive ()
- Keep Alive. Returns the current sleep time limit in milliseconds.
ListFiles (text wildcard)
- Returns a list containing the names of matching files found on the robot.
LsGetStatus (text sensorPortLetter)
- Returns the count of available bytes to read.
LsRead (text sensorPortLetter)
- Reads unsigned low speed data from an input sensor on the robot. Assumes sensor type has been configured via SetInputMode.
LsWrite (text sensorPortLetter, list list, number rxDataLength)
- Writes low speed data to an input sensor on the robot. Assumes sensor type has been configured via SetInputMode.
MessageRead (number mailbox)
- Read a message from a mailbox (1-10) on the robot.
MessageWrite (number mailbox, text message)
- Write a message to a mailbox (1-10) on the robot.
PlaySoundFile (text fileName)
- Play a sound file on the robot.
PlayTone (number frequencyHz, number durationMs)
- Make the robot play a tone.
ResetInputScaledValue (text sensorPortLetter)
- Reset the scaled value of an input sensor on the robot.
ResetMotorPosition (text motorPortLetter, boolean relative)
- Reset motor position.
SetBrickName (text name)
- Set the brick name of the robot.
SetInputMode (text sensorPortLetter, number sensorType, number sensorMode)
- Configure an input sensor on the robot.
SetOutputState (text motorPortLetter, number power, number mode, number regulationMode, number turnRatio, number runState, number tachoLimit)
- Sets the output state of a motor on the robot.
StartProgram (text programName)
- Start execution of a previously downloaded program on the robot.
StopProgram ()
- Stop execution of the currently running program on the robot.
StopSoundPlayback ()
- Stop sound playback.
NxtColorSensor
A component that provides a high-level interface to a color sensor on a LEGO MINDSTORMS NXT robot.
Properties
BluetoothClient
- The BluetoothClient component that should be used for communication. Must be set in the Designer
SensorPort
- The sensor port that the sensor is connected to. Must be set in the Designer
DetectColor
- Whether the sensor should detect color or light.
True indicates that the sensor should detect color; False indicates that the sensor should detect light.
If the DetectColor property is set to True, the BelowRange, WithinRange, and AboveRange events will not occur and the sensor will not generate color.
If the DetectColor property is set to False, the ColorChanged event will not occur.
ColorChangedEventEnabled
- Whether the ColorChanged event should fire when the DetectColor property is set to True and the detected color changes.
GenerateColor
- The color that should generated by the sensor.
Only None, Red, Green, or Blue are valid values.
The sensor will not generate color when the DetectColor property is set to True.
BottomOfRange
- The bottom of the range used for the BelowRange, WithinRange, and AboveRange events.
TopOfRange
- The top of the range used for the BelowRange, WithinRange, and AboveRange events.
BelowRangeEventEnabled
- Whether the BelowRange event should fire when the DetectColor property is set to False and the light level goes below the BottomOfRange.
WithinRangeEventEnabled
- Whether the WithinRange event should fire when the DetectColor property is set to False and the light level goes between the BottomOfRange and the TopOfRange.
AboveRangeEventEnabled
- Whether the AboveRange event should fire when the DetectColor property is set to False and the light level goes above the TopOfRange.
Events
ColorChanged(number color)
- Detected color has changed.
The ColorChanged event will not occur if the DetectColor property is set to False or if the ColorChangedEventEnabled property is set to False.
BelowRange()
- Light level has gone below the range.
The BelowRange event will not occur if the DetectColor property is set to True or if the BelowRangeEventEnabled property is set to False.
WithinRange()
- Light level has gone within the range.
The WithinRange event will not occur if the DetectColor property is set to True or if the WithinRangeEventEnabled property is set to False.
AboveRange()
- Light level has gone above the range.
The AboveRange event will not occur if the DetectColor property is set to True or if the AboveRangeEventEnabled property is set to False.
Methods
GetColor ()
- Returns the current detected color, or the color None if the color can not be read or if the DetectColor property is set to False.
GetLightLevel ()
- Returns the current light level as a value between 0 and 1023, or -1 if the light level can not be read or if the DetectColor property is set to True.
NxtLightSensor
A component that provides a high-level interface to a light sensor on a LEGO MINDSTORMS NXT robot
Properties
BluetoothClient
- The BluetoothClient component that should be used for communication. Must be set in the Designer
SensorPort
- The sensor port that the sensor is connected to. Must be set in the Designer
GenerateLight
- Whether the light sensor should generate light.
BottomOfRange
- The bottom of the range used for the BelowRange, WithinRange, and AboveRange events.
TopOfRange
- The top of the range used for the BelowRange, WithinRange, and AboveRange events.
BelowRangeEventEnabled
- Whether the BelowRange event should fire when the light level goes below the BottomOfRange.
WithinRangeEventEnabled
- Whether the WithinRange event should fire when the light level goes between the BottomOfRange and the TopOfRange.
AboveRangeEventEnabled
- Whether the AboveRange event should fire when the light level goes above the TopOfRange.
Events
BelowRange()
- Light level has gone below the range.
WithinRange()
- Light level has gone within the range.
AboveRange()
- Light level has gone above the range.
Methods
GetLightLevel ()
- Returns the current light level as a value between 0 and 1023, or -1 if the light level can not be read.
NxtSoundSensor
A component that provides a high-level interface to a sound sensor on a LEGO MINDSTORMS NXT robot
Properties
BluetoothClient
- The BluetoothClient component that should be used for communication. Must be set in the Designer
SensorPort
- The sensor port that the sensor is connected to. Must be set in the Designer
BottomOfRange
- The bottom of the range used for the BelowRange, WithinRange, and AboveRange events.
TopOfRange
- The top of the range used for the BelowRange, WithinRange, and AboveRange events.
BelowRangeEventEnabled
- Whether the BelowRange event should fire when the sound level goes below the BottomOfRange.
WithinRangeEventEnabled
- Whether the WithinRange event should fire when the sound level goes between the BottomOfRange and the TopOfRange.
AboveRangeEventEnabled
- Whether the AboveRange event should fire when the sound level goes above the TopOfRange.
Events
BelowRange()
- Sound level has gone below the range.
WithinRange()
- Sound level has gone within the range.
AboveRange()
- Sound level has gone above the range.
Methods
GetSoundLevel ()
- Returns the current sound level as a value between 0 and 1023, or -1 if the sound level can not be read.
NxtTouchSensor
A component that provides a high-level interface to a touch sensor on a LEGO MINDSTORMS NXT robot
Properties
BluetoothClient
- The BluetoothClient component that should be used for communication. Must be set in the Designer
SensorPort
- The sensor port that the sensor is connected to. Must be set in the Designer
PressedEventEnabled
- Whether the Pressed event should fire when the touch sensor is pressed.
ReleasedEventEnabled
- Whether the Released event should fire when the touch sensor is released.
Events
Pressed()
- Touch sensor has been pressed.
Released()
- Touch sensor has been released.
Methods
IsPressed ()
- Returns true if the touch sensor is pressed.
NxtUltrasonicSensor
A component that provides a high-level interface to an ultrasonic sensor on a LEGO MINDSTORMS NXT robot
Properties
BluetoothClient
- The BluetoothClient component that should be used for communication. Must be set in the Designer
SensorPort
- The sensor port that the sensor is connected to. Must be set in the Designer
BottomOfRange
- The bottom of the range used for the BelowRange, WithinRange, and AboveRange events.
TopOfRange
- The top of the range used for the BelowRange, WithinRange, and AboveRange events.
BelowRangeEventEnabled
- Whether the BelowRange event should fire when the distance goes below the BottomOfRange.
WithinRangeEventEnabled
- Whether the WithinRange event should fire when the distance goes between the BottomOfRange and the TopOfRange.
AboveRangeEventEnabled
- Whether the AboveRange event should fire when the distance goes above the TopOfRange.
Events
BelowRange()
- Distance has gone below the range.
WithinRange()
- Distance has gone within the range.
AboveRange()
- Distance has gone above the range.
Methods
GetDistance ()
- Returns the current distance in centimeters as a value between 0 and 254, or -1 if the distance can not be read.
NxtDrive
A component that provides a high-level interface to a LEGO MINDSTORMS NXT robot, with functions that can move and turn the robot
Properties
BluetoothClient
- The BluetoothClient component that should be used for communication. Must be set in the Designer
DriveMotors
- The motor ports that are used for driving.
WheelDiameter
- The diameter of the wheels used for driving.
StopBeforeDisconnect
- Whether to stop the drive motors before disconnecting.
Methods
MoveForwardIndefinitely (number power)
- Move the robot forward indefinitely, with the specified percentage of maximum power.
MoveForward (number power, number distance)
- Move the robot forward the given distance, with the specified percentage of maximum power.
MoveBackwardIndefinitely (number power)
- Move the robot backward indefinitely, with the specified percentage of maximum power.
MoveBackward (number power, number distance)
- Move the robot backward the given distance, with the specified percentage of maximum power.
Stop ()
- Stop the drive motors of the robot.
TurnClockwiseIndefinitely (number power)
- Turn the robot clockwise indefinitely, with the specified percentage of maximum power.
TurnCounterClockwiseIndefinitely (number power)
- Turn the robot counterclockwise indefinitely, with the specified percentage of maximum power.