Functions
ev3_ambientLightIntensity(colorSensor) → {number}
Gets the ambient light intensity seen by the colour sensor.
Parameters:
Name | Type | Description |
---|---|---|
colorSensor |
peripheral | The colour sensor. |
Returns:
The ambient light intensity, as a percentage from 0 to 100.
- Type
- number
ev3_colorSensor() → {peripheral}
Gets the colour sensor connected any of ports 1, 2, 3 or 4.
Returns:
The colour sensor.
- Type
- peripheral
ev3_colorSensorBlue(colorSensor) → {number}
Gets the amount of blue seen by the colour sensor.
Parameters:
Name | Type | Description |
---|---|---|
colorSensor |
peripheral | The colour sensor. |
Returns:
The amount of blue, in sensor-specific units.
- Type
- number
ev3_colorSensorGetColor(colorSensor) → {number}
Gets the colour as seen by the colour sensor.
Possible colour return values are:
- 0 none
- 1 black
- 2 blue
- 3 green
- 4 yellow
- 5 red
- 6 white
- 7 brown
Parameters:
Name | Type | Description |
---|---|---|
colorSensor |
peripheral | The colour sensor. |
Returns:
A number representing the colour observed by the device.
- Type
- number
ev3_colorSensorGreen(colorSensor) → {number}
Gets the amount of green seen by the colour sensor.
Parameters:
Name | Type | Description |
---|---|---|
colorSensor |
peripheral | The colour sensor. |
Returns:
The amount of green, in sensor-specific units.
- Type
- number
ev3_colorSensorRed(colorSensor) → {number}
Gets the amount of red seen by the colour sensor.
Parameters:
Name | Type | Description |
---|---|---|
colorSensor |
peripheral | The colour sensor. |
Returns:
The amount of red, in sensor-specific units.
- Type
- number
ev3_connected(obj) → {boolean}
Checks if the peripheral is connected.
Parameters:
Name | Type | Description |
---|---|---|
obj |
peripheral | The peripheral to check. |
Returns:
true if the peripheral is connected, false otherwise
- Type
- boolean
ev3_gyroSensor() → {peripheral}
Gets the gyro sensor connected any of ports 1, 2, 3 or 4.
Returns:
The gyro sensor.
- Type
- peripheral
ev3_gyroSensorAngle(gyroSensor) → {number}
Gets the absolute angle detected by the gyro sensor, measured from when
the sensor was last switched to angle mode from sensor rate mode.
Parameters:
Name | Type | Description |
---|---|---|
gyroSensor |
peripheral | The gyro sensor. |
Returns:
The angle, in degrees.
- Type
- number
ev3_gyroSensorRate(gyroSensor) → {number}
Gets the rate of rotation detected by the gyro sensor.
Parameters:
Name | Type | Description |
---|---|---|
gyroSensor |
peripheral | The gyro sensor. |
Returns:
The rate of rotation, in degrees per second.
- Type
- number
ev3_hello() → {string}
Returns a hello world message.
Returns:
A hello world message.
- Type
- string
ev3_ledGetBrightness(led) → {number}
Gets the brightness of the given LED.
The brightness is a number ranging from 0 (off) to 255 (maximum).
Parameters:
Name | Type | Description |
---|---|---|
led |
peripheral | The LED |
Returns:
The brightness of the given LED
- Type
- number
ev3_ledLeftGreen() → {peripheral}
Gets the left green LED.
Note that the four LEDs on the EV3 are laid out in two pairs of green and
red. If both in a pair are turned on, you can vary the colours in a small
spectrum between red and green.
Returns:
The left green LED
- Type
- peripheral
ev3_ledLeftRed() → {peripheral}
Gets the left red LED.
Note that the four LEDs on the EV3 are laid out in two pairs of green and
red. If both in a pair are turned on, you can vary the colours in a small
spectrum between red and green.
Returns:
The left red LED
- Type
- peripheral
ev3_ledRightGreen() → {peripheral}
Gets the right green LED.
Note that the four LEDs on the EV3 are laid out in two pairs of green and
red. If both in a pair are turned on, you can vary the colours in a small
spectrum between red and green.
Returns:
The right green LED
- Type
- peripheral
ev3_ledRightRed() → {peripheral}
Gets the right red LED.
Note that the four LEDs on the EV3 are laid out in two pairs of green and
red. If both in a pair are turned on, you can vary the colours in a small
spectrum between red and green.
Returns:
The right red LED
- Type
- peripheral
ev3_ledSetBrightness(led, brightness)
Sets the brightness of the given LED.
The brightness is a number ranging from 0 (off) to 255 (maximum).
Parameters:
Name | Type | Description |
---|---|---|
led |
peripheral | The LED |
brightness |
number | The desired brightness |
ev3_motorA() → {peripheral}
Gets the motor connected to port A.
Returns:
The motor connected to port A
- Type
- peripheral
ev3_motorB() → {peripheral}
Gets the motor connected to port B.
Returns:
The motor connected to port B
- Type
- peripheral
ev3_motorC() → {peripheral}
Gets the motor connected to port C.
Returns:
The motor connected to port C
- Type
- peripheral
ev3_motorD() → {peripheral}
Gets the motor connected to port D.
Returns:
The motor connected to port D
- Type
- peripheral
ev3_motorGetPosition(motor) → {number}
Gets the motor's current position, in pulses of the rotary encoder.
Parameters:
Name | Type | Description |
---|---|---|
motor |
peripheral | The motor |
Returns:
The current position.
- Type
- number
ev3_motorGetSpeed(motor) → {number}
Gets the motor's current speed, in tacho counts per second.
Parameters:
Name | Type | Description |
---|---|---|
motor |
peripheral | The motor |
Returns:
The current speed.
- Type
- number
ev3_motorSetSpeed(motor, speed)
Sets the speed the motor will run at the next time ev3_motorStart
is called.
Parameters:
Name | Type | Description |
---|---|---|
motor |
peripheral | The motor |
speed |
number | The speed to run at, in tacho counts per second |
ev3_motorSetStopAction(motor, stopAction)
Sets the stop action of the motor.
Possible stop actions are:
"coast"
: power will be removed from the motor and it will freely coast to a stop."brake"
: power will be removed from the motor and a passive electrical load will be placed on the motor. This load will absorb the energy from the rotation of the motors and cause the motor to stop more quickly than coasting."hold"
: actively try to hold the motor at the current position. If an external force tries to turn the motor, the motor will ‘push back’ to maintain its position.
Parameters:
Name | Type | Description |
---|---|---|
motor |
peripheral | The motor. |
stopAction |
string | The stop action to use. |
ev3_motorStart(motor)
Causes the motor to start with the previously set speed and stop action
(see motorSetSpeed and motorSetStopAction).
Parameters:
Name | Type | Description |
---|---|---|
motor |
peripheral | The motor |
ev3_motorStop(motor)
Causes the motor to stop using the previously set stop action.
Parameters:
Name | Type | Description |
---|---|---|
motor |
peripheral | The motor |
ev3_pause(time)
Pauses for a period of time.
Parameters:
Name | Type | Description |
---|---|---|
time |
number | The time to wait, in milliseconds. |
ev3_playSequence(beeps)
Causes the robot to emit a sequence of beeps. Returns after the beeps are
emitted.
The beep sequence is an array of
[frequency, length (ms), delay (ms),
...]
. For example, [1000, 500, 500, 250, 500, 0]
will
cause the robot to emit a 1000 Hz beep for 500 ms, wait 500 ms, then emit a
250 Hz beep for 500 ms.
Parameters:
Name | Type | Description |
---|---|---|
beeps |
Array | The beep sequence. |
ev3_reflectedLightIntensity(colorSensor) → {number}
Gets the reflected light intensity seen by the colour sensor.
Parameters:
Name | Type | Description |
---|---|---|
colorSensor |
peripheral | The colour sensor. |
Returns:
The reflected light intensity, as a percentage from 0 to 100.
- Type
- number
ev3_runForTime(motor, time, speed)
Causes the motor to rotate for a specified duration at the specified speed.
Note: this works by sending instructions to the motors. This will return almost immediately, without waiting for the motor to actually run for the specified duration. If you wish to wait, use ev3_pause.
Parameters:
Name | Type | Description |
---|---|---|
motor |
peripheral | The motor |
time |
number | The duration to turn, in milliseconds |
speed |
number | The speed to run at, in tacho counts per second |
ev3_runToAbsolutePosition(motor, position, speed)
Causes the motor to rotate to the given absolute position (as reported by
ev3_motorGetPosition) with the given speed.
Note: this works by sending instructions to the motors. This will return almost immediately, without waiting for the motor to reach the given absolute position. If you wish to wait, use ev3_pause.
Parameters:
Name | Type | Description |
---|---|---|
motor |
peripheral | The motor |
position |
number | The absolute position to turn to |
speed |
number | The speed to run at, in tacho counts per second |
ev3_runToRelativePosition(motor, position, speed)
Causes the motor to rotate until the position reaches
ev3_motorGetPosition()
+ position
with the given speed.
Note: this works by sending instructions to the motors. This will return almost immediately, without waiting for the motor to reach the given absolute position. If you wish to wait, use ev3_pause.
Parameters:
Name | Type | Description |
---|---|---|
motor |
peripheral | The motor |
position |
number | The amount to turn |
speed |
number | The speed to run at, in tacho counts per second |
ev3_speak(words)
Makes the robot speak the given words through its speaker. Returns after the
words are spoken.
Parameters:
Name | Type | Description |
---|---|---|
words |
string | The words to speak. |
ev3_touchSensor1() → {peripheral}
Gets the touch sensor connected to port 1.
Returns:
The touch sensor.
- Type
- peripheral
ev3_touchSensor2() → {peripheral}
Gets the touch sensor connected to port 2.
Returns:
The touch sensor.
- Type
- peripheral
ev3_touchSensor3() → {peripheral}
Gets the touch sensor connected to port 3.
Returns:
The touch sensor.
- Type
- peripheral
ev3_touchSensor4() → {peripheral}
Gets the touch sensor connected to port 4.
Returns:
The touch sensor.
- Type
- peripheral
ev3_touchSensorPressed(touchSensor) → {boolean}
Gets whether the touch sensor is pressed.
Parameters:
Name | Type | Description |
---|---|---|
touchSensor |
peripheral | The touch sensor. |
Returns:
true when the touch sensor is pressed, false otherwise.
- Type
- boolean
ev3_ultrasonicSensor() → {peripheral}
Gets the ultrasonic sensor connected any of ports 1, 2, 3 or 4.
Returns:
The ultrasonic sensor.
- Type
- peripheral
ev3_ultrasonicSensorDistance(ultrasonicSensor) → {number}
Gets the distance read by the ultrasonic sensor in centimeters.
Parameters:
Name | Type | Description |
---|---|---|
ultrasonicSensor |
peripheral | The ultrasonic sensor. |
Returns:
The distance, in centimeters.
- Type
- number
ev3_waitForButtonPress() → {number}
Waits for one of the buttons on the EV3's control face to be pressed, then
returns a value corresponding to the button that was pressed:
- 0 enter (the middle button)
- 1 back (the top left button)
- 2 left
- 3 right
- 4 up
- 5 down
Returns:
A number corresponding to the button that was pressed
- Type
- number