This manual is also available in French, Spanish, German and Russian.
The runtime-library for the EV3 is organized in individual parts, called 'objects'. Each object provides functionality for a different part of the system. This list contains everything that is available for both Small Basic on the PC (with EV3-extension) and also on the brick when compiling with EV3 Explorer. When developing programs that only need to run on the PC, you can also use everything else that is provided by Small Basic, but the standard Small Basic objects are not documented here except for the Math, Program and Text objects. The objects documented here are:
Assert Buttons Byte EV3 EV3File F LCD Math Motor
Program Sensor Speaker Text Thread Vector
Click HERE for descriptions of the Small Basic objects.
A test facility to help check part of the code for correctness.
Assertions make implicit assumptions about the current program state explicit. By adding assertion calls you can help finding bugs in your program more easily. For example, when a part of the program depends on the variable A having a positive value, you could call Assert.Greater(A,0,"A must be > 0!"). In the case that the program runs into an assertion that is not satisfied, the error message is displayed stating the problem.
a First value
b Second value
message Message that will be displayed if the assertion fails.
message Message to be displayed
a First value
b Second value
message Message that will be displayed if the assertion fails.
a First value
b Second value
message Message that will be displayed if the assertion fails.
a First value
b Second value
message Message that will be displayed if the assertion fails.
a First value
b Second value
message Message that will be displayed if the assertion fails.
a First value
b Second value
message Message that will be displayed if the assertion fails.
a First value
b Second value
message Message that will be displayed if the assertion fails.
Reads the states and clicks of the buttons on the brick. The buttons are specified with the following letters: U(p), D(own), L(eft), R(ight), E(nter)
Returns A text containing the letters of the clicked buttons (can be empty)
Manipulate individual bits of an 8-bit numerical quantity. This library lets you treat Small Basic numbers as if they were organized as 8-bit integer values (a.k.a. "bytes"). To do so, the parameter values are always converted to plain bytes, then the requested operation is performed and then the result is converted back to a Small Basic number. The usual bit operations are supported: AND, OR, NOT, XOR, various shifts and data conversion operations. Note that the identifiers AND and OR are reserved words of Small Basic and so these operations are named AND_ and OR_ instead. For further information see https://en.wikipedia.org/wiki/Bitwise_operation .
Bitwise AND operation.
a First operand
b Second operand
Returns The number you get when merging the two input bytes a and b by doing a binary AND operation on their individual bits
Convert a string that contains a binary value into a number.
value The string holding a byte in binary form (for example: "01001111")
Returns The byte as number
Extract a single bit from a byte.
value The byte number from where to extract the bit
index Position of the bit inside the byte
Returns The bit on the specified position which is either 0 or 1
Convert a string that contains a hexadecimal value into a number.
value The string holding a byte in hexadecimal form (for example: "4F")
Returns The byte as number
Convert a string that contains a logic value into a numerical 0 or 1.
value The string holding a logic value. All case-insensitive variants of "True" ("TRUE","TrUe", "truE", etc.) are considered the same. Everything else is treated as "False".
Returns 0 or 1
Bitwise negation.
value Number to negate
Returns The number you get when every bit of the input byte is individually inverted
Bitwise OR operation.
a First operand
b Second operand
Returns The number you get when merging the two input bytes a and b by doing a binary OR operation on their individual bits
Perform a bitwise shift operation to the left.
value The byte whose bits will be shifted
distance By how many positions to shift the bits
Returns The number you get after moving every bit of the input value towards the more significant positions
Perform a bitwise shift operation to the right.
value The byte whose bits will be shifted
distance By how many positions to shift the bits
Returns The number you get after moving every bit of the input value towards the less significant positions
Convert an 8-bit byte to its 8-digit binary string representation.
value The byte to convert into a string
Returns A string holding 8 binary digits
Convert an 8-bit byte to its 2-digit hexadecimal string representation.
value The byte to convert into a string
Returns A string holding 2 hexadecimal digits
Convert a number (can be a 8-bit byte or any other number) to a logic value of either "True" or "False".
This value can then be used for the condition in If or While or any other purpose.
Note that any input value greater than 0 results in a "True" while an input value of 0 or any negative value results in "False".
This specific behaviour allows some weird and wonderful things to be done with this command. Refer to the appendix for advanced logic operations.
value The numeric value to be converted into its corresponding logic value
Returns Either "True" or "False"
Bitwise XOR operation.
a First operand
b Second operand
Returns The number you get when merging the two input bytes a and b by doing a binary XOR operation on their individual bits
Small utility functions that concern the EV3 brick as a whole.
color Can be "OFF", "GREEN", "RED", "ORANGE"
effect Can be "NORMAL", "FLASH", "PULSE"
commandline The system command.
Returns Exit status of the command.
Access the file system on the EV3 brick to read or write data.
File names can be given either absolute (with a leading '/') to reach any file in the system, or relative to the 'prjs' folder.
handle The file handle (previously obtained from an Open... call)
text A text holding a number in decimal representation (with optional fractional digits)
Returns The number
filename Name of the file to create/extend.
Returns A number that identifies this open file (a.k.a. file handle).
filename Name of the file to read from.
Returns A number that identifies this open file (a.k.a. file handle) or 0 if file does not exist.
filename Name of the file to create/overwrite.
Returns A number that identifies this open file (a.k.a. file handle).
handle The file handle (previously obtained from an Open... call)
Returns The next byte from the file.
handle The file handle (previously obtained from an Open... call)
Returns The text from the current line in the file.
filename The name of the file.
bytes_per_row When the file has a row/column structure, this is the number of bytes in one row. Use 1 if not applicable.
row Which row to access (start with 0).
column Which column to access (start with 0).
Returns The byte on the denoted position
handle The file handle (previously obtained from an Open... call)
data One byte to write (value of 0 - 255).
handle The file handle (previously obtained from an Open... call)
text The text to write to the file.
A framework to create functions with parameters and local variables in Small Basic. This enables programs to call user-defined library functions in a form similar to what is possible with the built-in commands, including nicer parameter passing and return values. Functions can be defined by use of the F.Function command and can be later called with one of the F.Call commands. See the provided example "Function.sb" for a better introduction.
This property must be set to a subprogram before a subsequent F.Function operation is done which actually defines the function.
Do a function call without passing parameters.
name
The name of the function (case insensitive)
Returns
The value returned by the function
Do a function call with 1 parameter.
name
The name of the function (case insensitive)
p1
Parameter 1
Returns
The value returned by the function
Do a function call with 2 parameters.
name
The name of the function (case insensitive)
p1
Parameter 1
p2
Parameter 2
Returns
The value returned by the function
Define a named function and its local variables/parameters with default values. Before this command is executed, the Start property needs to be set to a subroutine that will then be the starting point of the function.
The local variables are also used for parameter passing when using a Call command: For any call with n parameters, these parameters will be assigned to the first n local variables. The rest of the local variables will be set to their defined initial value.
name
The name for the function (needs to be a string literal)
parameterdefinitions
A string that holds a sequence of local variable names and initial values. This looks like for example "A B:5 T:hello". When no default is specified, 0 will be used.
Retrieve the value of a named local variable.
variablename
The name of the local variable (case insensitive)
Returns
The value stored in the variable
Causes the current function call to terminate immediately.
In "brick mode" it is only allowed to use this command in the topmost sub of a function.
Causes the current function call to terminate immediately and delivers the value as number back to the caller.
In "brick mode" it is only allowed to use this command in the topmost sub of a function.
value
The return value (must be a number)
Causes the current function call to terminate immediately and delivers the value as text back to the caller.
In "brick mode" it is only allowed to use this command in the topmost sub of a function.
value
The return value (is interpreted as text)
Set a named local variable to a specified value.
variablename
The name of the local variable (case insensitive)
value
The value to store into the local variable
Control the LCD display on the brick.
The EV3 has a black-and-white display with 178 x 128 pixels. All pixels are addressed with X,Y coordinates where X=0 is the left edge and Y=0 is the top edge. Thus the coordinates of the bottom right pixel are (177,127).
color 0 (white) or 1 (black)
x X coordinate of left edge
y Y coordinate of top edge
filename Name of the file containing the bitmap
color 0 (white) or 1 (black)
x X coordinate of center point
y Y coordinate of center point
radius Radius of the circle
color 0 (white) or 1 (black)
x X coordinate of center point
y Y coordinate of center point
radius Radius of the circle
color 0 (white) or 1 (black)
x Left edge of rectangle
y Top edge of rectangle
width Width of rectangle
height Height of rectangle
x Left edge of rectangle
y Top edge of rectangle
width Width of rectangle
height Height of rectangle
color 0 (white) or 1 (black)
x1 X coordinate of start point
y1 Y coordinate of start point
x2 X coordinate of end point
y2 Y coordinate of end point
color 0 (white) or 1 (black)
x X coordinate
y Y coordinate
color 0 (white) or 1 (black)
x Left edge of rectangle
y Top edge of rectangle
width Width of rectangle
height Height of rectangle
color 0 (white) or 1 (black)
x X coordinate where text starts
y Y coordinate of the top corner
font Size of the letters: 0 (TINY), 1 (SMALL), 2 (BIG)
text The text (or number) to write to the display
x X coordinate where text starts
y Y coordinate of the top corner
text The text (or number) to write to the display
The Math class provides lots of useful mathematics related methods
number The number to get the absolute value for.
Returns The absolute value of the given number.
cosValue The cosine value whose angle is needed.
Returns The angle (in radians) for the given cosine Value.
sinValue The sine value whose angle is needed.
Returns The angle (in radians) for the given sine Value.
tanValue The tangent value whose angle is needed.
Returns The angle (in radians) for the given tangent Value.
number The number whose ceiling is required.
Returns The ceiling value of the given number.
angle The angle whose cosine is needed (in radians).
Returns The cosine of the given angle.
number The number whose floor value is required.
Returns The floor value of the given number.
angle The angle in radians.
Returns The converted angle in degrees.
angle The angle in degrees.
Returns The converted angle in radians.
maxNumber The maximum number for the requested random value.
Returns A Random number that is less than or equal to the specified max.
number The number whose logarithm value is required
Returns The log value of the given number
number1 The first of the two numbers to compare.
number2 The second of the two numbers to compare.
Returns The greater value of the two numbers.
number1 The first of the two numbers to compare.
number2 The second of the two numbers to compare.
Returns The smaller value of the two numbers.
number The number whose natural logarithm value is required.
Returns The natural log value of the given number.
baseNumber The number to be raised to the exponent power.
exponent The power to raise the base number.
Returns The base number raised to the specified exponent.
dividend The number to divide.
divisor The number that divides.
Returns The remainder after the division.
number The number whose approximation is required.
Returns The rounded value of the given number.
angle The angle whose sine is needed (in radians)
Returns The sine of the given angle
number The number whose square root value is needed.
Returns The square root value of the given number.
angle The angle whose tangent is needed (in radians).
Returns The tangent of the given angle.
Note that EV3 Basic makes no distinction between large and medium motors.
The Motor commands control the motors connected to the brick. For every command you need to specify one or more motor ports that should be affected (for example, "A", "BC", "ABD"). When additional bricks are daisy-chained to the master brick, address the correct port by adding the layer number to the specifier (for example, "3BC", "2A"). In this case only the motors of one brick can be accessed with a single command.
Speed vs. Power: When requesting to drive a motor with a certain speed, the electrical power will be permanently adjusted to keep the motor on this speed regardless of the necessary driving force (as long as enough power can be provided). When requesting a certain power instead, the motor will just be provided with this much electrical power and the actual speed will then depend on the resistance it meets. The normal choice in EV3 Basic should be speed.
The following table summarises nine commands that can be used to make motors move. It does not include the commands MoveSteer, ScheduleSteer and StartSteer which mimic the functionality of the Move Steering block in EV-G. These three commands are only available in versions 1.2 and later of the EV3 extension.
The four highlighted commands are the most basic ones, the ones beginners will use most of the time.
To make one motor turn through a given angle or make two motors turn at the same speed through a given angle (as for straight line motion), prefer Motor.Move.
To make the robot follow a curved path for a given angle of wheel rotation (two motors moving with different speeds), prefer Motor.MoveSync. This function causes program execution to pause until the movement completes. This function is equivalent to the 'move tank' block of the standard Lego software. Alternatively, you can use Motor.Movesteer which is the equivalent of the Move Steering block in EV3-G. This command is only available in version 1.2 and later of the EV3 extension.
To make motors turn for a given length of time, turn them on with Motor.Start (to give motors the same speed) or Motor.StartSync (to give motors different speeds), then use Program.Delay to make the program wait the desired time, then stop the motors with Motor.Stop.
When you have to change power or speed of an already running motor, just re-issue a Start() command with the appropriate speed or power value. The motor will then seamlessly switch over to the new mode of operation.
For all the motor commands:
port(s) = Motor port name(s). E.g. "BC"
degrees = Number of degrees to move the motor. Motor commands will always use the absolute value of the degree parameter (in other words any negative sign will be ignored), so if you want the motor to turn backwards give it a negative power or speed rather than a negative angle.
brake = "True", if the motor(s) should switch on the brake after movement
speed = speed from -100 (full reverse) to 100 (full forward)
power = Power level from -100 (full reverse) to 100 (full forward)
Returns The current rotation count in degrees.
Returns Current speed in range -100 to 100
Motor.Invert (ports)
This command is only available in versions 1.2 and later of the EV3 extension. Invert the polarity (direction) of one or more motors. This will affect all future commands that move this motors and also the tacho and speed readings will deliver inverted values. This operation makes it easy to change the way a motor is built into a robot without altering the rest of the program. You just need to add a single Motor.Invert() command at the very start of the program. Note that there is intentionally no way to disable the inversion later on.
Returns "True" if at least one of the motors is busy, "False" otherwise.
speed Speed level from -100 (full reverse) to 100 (full forward)
degrees The angle to rotate. Any negative sign will be ignored.
power Power level from -100 (full reverse) to 100 (full forward)
degrees The angle to rotate. Any negative sign will be ignored.
Motor.MoveSteer (ports, speed, turn, degrees, brake)
This command is only available in versions 1.2 and later of the EV3 extension. Move two motors a defined number of degrees with a specified speed and relative ratio. This ratio is determined by the 'turn' parameter which basically determines into which direction a vehicle with a simple two-wheel drive would make its turn (given that the motor with the lower port letter is mounted on the left side). The two motors are synchronized which means that when one motor experiences some resistance and cannot keep up its speed, the other motor will also slow down or stop altogether. This is especially useful for vehicles with two independently driven wheels which still need to go straight or make a specified turn. The angle to move is for the motor with the higher speed. This command makes the program pause until the movement has completed.
ports Names of 2 motor ports (for example "AB" or "CD"
speed Speed value from -100 (full reverse) to 100 (full forward) of the faster motor.
turn Turn ratio from -100 (rotating left on the spot) to 100 (rotating right on the spot).
degrees The angle of the faster motor to rotate
brake "True", if the motors should switch on the brake after movement
ports Names of exactly TWO motor ports (for example "AB" or "CD")
speed1 Speed value from -100 (full reverse) to 100 (full forward) of the motor with the lower port letter.
speed2 Speed value from -100 (full reverse) to 100 (full forward) of the motor with the higher port letter.
degrees The angle that the faster motor should rotate. Any negative sign will be ignored.
speed Speed level from -100 (full reverse) to 100 (full forward)
degrees1 The part of the rotation with acceleration
degrees2 The part of the rotation with uniform speed
degrees3 The part of the rotation with deceleration
power Power level from -100 (full reverse) to 100 (full forward)
degrees1 The part of the rotation with acceleration
degrees2 The part of the rotation with uniform motion
degrees3 The part of the rotation with deceleration
ports Names of 2 motor ports (for example "AB" or "CD"
speed Speed value from -100 (full reverse) to 100 (full forward) of the faster motor.
turn Turn ratio from -100 (rotating left on the spot) to 100 (rotating right on the spot).
degrees The angle through which the faster motor should rotate.
brake "True", if the motors should switch on the brake after movement.
ports Names of exactly 2 motor ports (for example "AB" or "CD")
speed1 Speed value from -100 (full reverse) to 100 (full forward) of the motor with the lower port letter.
speed2 Speed value from -100 (full reverse) to 100 (full forward) of the motor with the higher port letter.
degrees The angle of the faster motor to rotate. Any negative sign will be ignored.
speed Speed value from -100 (full reverse) to 100 (full forward).
power Power value from -100 (full reverse) to 100 (full forward).
ports Name of two motor ports (for example "AB" or "CD").
speed Speed value from -100 (full reverse) to 100 (full forward) for the faster motor.
turn Turn ratio from -100 (rotating left on the spot) to 100 (rotating right on the spot).
ports Name of exactly two motor ports (for example "AB" or "CD").
speed1 Speed value from -100 (full reverse) to 100 (full forward) of the motor with the lower port letter.
speed2 Speed value from -100 (full reverse) to 100 (full forward) of the motor with the higher port letter.
The Program class provides helpers to control the program execution.
milliSeconds The amount of delay.
index Index of the argument.
Returns The command-line argument at the specified index.
Access sensors that are attached to the brick. To specify the sensor use the port number which is printed below the socket on the brick (for example 1). To access sensors of further bricks that are connected via daisy-chaining, use the next higher numbers instead (5 - 8 will access the sensors on the first daisy-chained brick, 9-12 the sensors on the next one and so on).
port Number of the sensor port
address Address (0 - 127) of the I2C slave on the I2C bus
writebytes Number of bytes to write to the slave (maximum 31).
readbytes Number of bytes to request from the slave (maximum 32, minimum 1).
writedata Array holding the data bytes to be sent (starting at 0).
Returns An array holding the requested number of values. Index starts at 0.
port Number of the sensor port
Returns Current operation mode (0 is always the default mode)
port Number of the sensor port
Returns Description text (for example, "TOUCH")
port Number of the sensor port
Returns Sensor type identifier (for example, 16 for a touch sensor)
port Number of the sensor port
Returns "True" if the sensor is currently busy
port Number of the sensor port
address Address (0 - 127) of the I2C slave on the I2C bus
registernumber Number of register in the slave to read data from.
Returns The content of the register
port Number of the sensor port
address Address (0 - 127) of the I2C slave on the I2C bus
registernumber Number of the first register in the slave to read data from.
readbytes How many register to read (maximum 32).
Returns An array holding the requested number of values. Index starts at 0.
port Number of the sensor port
Returns The percentage value (for example, the touch sensor gives 100 for pressed and 0 for non pressed)
port Number of the sensor port
values Requested size of result array
Returns An array holding the requested number of values. Index starts at 0. Elements that received no data are set to 0.
port Number of the sensor port
index Index of the value that should be picked from the result array (starting with index 0). The index value should always be 0 unless you are using the infrared sensor in remote control mode - see the sensor appendix.
Returns One element of a raw sensor reading.
port Number of the sensor port
mode New mode to switch to. This only succeeds when the mode is indeed supported by the sensor.
port Number of the sensor port
Sensor.WriteI2CRegister (port, address, registernumber, value)
This command is only available in versions 1.2 and later of the EV3 extension. This command addresses one device on the I2C-bus and tries to write the value of a single register of a connected I2C slave. Note that this command does not work over daisy-chaining.
port Number of the sensor port
address Address (0 - 127) of the I2C slave on the I2C bus
registernumber Number of the register in the slave to write data to.
value Value to write into the register.
Sensor.WriteI2CRegisters (port, address, registernumber, writebytes, writedata)
This command is only available in versions 1.2 and later of the EV3 extension. This command addresses one device on the I2C-bus and tries to write the values of multiple registers of a connected I2C slave. Note that this command does not work over daisy-chaining.
port Number of the sensor port
address Address (0 - 127) of the I2C slave on the I2C bus
registernumber Number of the first register in the slave to write data to.
writebytes How many bytes to write into the registers (maximum 30).
writedata Array holding the data bytes to be written (starting at 0).
Use the built-in speaker of the brick to play tones or sound files.
Returns "True", if there is a sound still playing, "False" otherwise.
volume Volume can be 0 - 100
note Text defining a note "C4" to "B7" or half-tones like "C#5"
duration Duration of the tone in milliseconds
volume Volume can be 0 - 100
filename Name of the sound file without the .rsf extension
volume Volume can be 0 - 100
frequency Frequency in Hz can be 250 - 10000
duration Duration of the tone in milliseconds
The Text object provides helpful operations for working with Text.
text1 First part of the text to be appended.
text2 Second part of the text to be appended.
Returns The appended text containing both the specified parts.
text The text to convert to lower case.
Returns The lower case version of the given text.
text The text to convert to upper case.
Returns The upper case version of the given text.
text The larger text to search within.
subText The sub-text to search for.
Returns True if the subtext was found at the end of the given text.
characterCode The character code (Unicode based) for the required character.
Returns A Unicode character that corresponds to the code specified.
character The character whose code is requested.
Returns A Unicode based code that corresponds to the character specified.
text The text to search in.
subText The text to search for.
Returns The position at which the sub-text appears in the specified text. If the text doesn't appear, it returns 0.
text The text whose length is needed.
Returns The length of the given text.
text The text to derive the sub-text from.
start Specifies where to start from.
length Specifies the length of the sub text.
Returns The requested sub-text
text The text to derive the sub-text from.
start Specifies where to start from.
Returns The requested sub-text.
text The larger text within which the sub-text will be searched.
subText The sub-text to search for.
Returns True if the subtext was found within the given text.
text The larger text to search within.
subText The sub-text to search for.
Returns True if the subtext was found at the start of the given text.
This object supports the use of threads in a program. A thread is a part of program code that can run independently and at the same time as other parts of the program. For example, you could create a thread that controls the motors, while a different thread can watch sensors or user input. Generally speaking, multi-threading is quite a complex topic. To really understand it, some extra study is recommended.
Returns A number specifying the new mutex. Use this for calls to Lock and Unlock
mutex The number of the mutex, as returned from CreateMutex()
mutex The number of the mutex, as returned from CreateMutex()
This object allows direct manipulation of larger quantities of numbers.
These are called vectors and will be stored using arrays with consecutive indices (starting at 0). When arrays with different content are given to the operations, every missing array element with be treated as being 0.
size That many numbers are taken for computation
A First vector
B Second vector
Returns A vector of the given size what contains sum values.
size Size of the vector
value The value to use for all elements
Returns The created vector
rows Number of rows in the resulting output matrix
columns Number of columns in the resulting output matrix
k Number of columns in input matrix A and number of rows in input matrix B
A A matrix of size rows * k
B A matrix of size k * columns
Returns A matrix holding the multiplication result
size Number of elements to sort
A The array containing the elements
Returns A new vector with the elements in correct order