Swift
EV3 API Reference


Contents


Brick Display & Sound


ev3.brickLightOff()

ev3.brickLightOn(withColor: BrickLightColor, inMode: BrickLightMode)

ev3.display(text: String)

ev3.display(text: String, atX: Int, atY: Int, withColor: DisplayColor, withFont: DisplayFont, clearScreen: Bool)

ev3.displayCircle(centerX: Int, centerY: Int, withRadius: Float, withFill: Bool, withColor: DisplayColor, clearScreen: Bool)

ev3.displayImage(named: ImageName)

ev3.displayImage(named: ImageName, atX: Int, atY: Int, clearScreen: Bool)

ev3.displayLine(fromX: Int, fromY: Int, toX: Int, toY: Int, withColor: DisplayColor, clearScreen: Bool)

ev3.displayPoint(atX: Int, atY: Int, withColor: DisplayColor, clearScreen: Bool)

ev3.displayRectangle(atX: Int, atY: Int, length: Int, height: Int, withFill: Bool, withColor: DisplayColor, clearScreen: Bool)

ev3.playSound(file: SoundFile, atVolume: Float, withStyle: SoundStyle)

ev3.playSound(frequency: Float, forSeconds: Float, atVolume: Float)

ev3.playSound(frequency: Float, forSeconds: Float, atVolume: Float, waitForCompletion: Bool)

ev3.playSound(note: Note, forSeconds: Float, atVolume: Float)

ev3.playSound(note: Note, forSeconds: Float, atVolume: Float, waitForCompletion: Bool)

ev3.stopSound()



General Functions


ev3.waitFor(seconds: Float)



Gyro Sensor


ev3.measureGyroAngle(on: InputPort)

ev3.measureGyroRate(on: InputPort)

ev3.resetGyro(on: InputPort)

ev3.waitForGyroRateChange(on: InputPort)

ev3.waitForGyroAngleChange(on: InputPort)

ev3.waitForGyroAngle(on: InputPort, lessThanOrEqualTo: Float)

ev3.waitForGyroAngle(on: InputPort, greaterThanOrEqualTo: Float)

ev3.waitForGyroRate(on: InputPort, lessThanOrEqualTo: Float)

ev3.waitForGyroRate(on: InputPort, greaterThanOrEqualTo: Float)



Infrared Sensor


ev3.measureIRProximity(on: InputPort)

ev3.measureIRSeek(on: InputPort)

ev3.waitForIRSeekChange(on: InputPort)

ev3.waitForIRProximityChange(on: InputPort)

ev3.waitForIRSeek(on: InputPort, lessThanOrEqualTo: Float)

ev3.waitForIRSeek(on: InputPort, greaterThanOrEqualTo: Float)

ev3.waitForIRProximity(on: InputPort, lessThanOrEqualTo: Float)

ev3.waitForIRProximity(on: InputPort, greaterThanOrEqualTo: Float)



Color/Light Sensor


ev3.measureLightAmbient(on: InputPort)

ev3.measureLightColor(on: InputPort)

ev3.measureLightReflection(on: InputPort)

ev3.waitForLightColor(on: InputPort, color: ColorValue)

ev3.waitForLightColorChange(on: InputPort)

ev3.waitForLightAmbientChange(on: InputPort)

ev3.waitForLightReflectionChange(on: InputPort)

ev3.waitForLightAmbient(on: InputPort, lessThanOrEqualTo: Float)

ev3.waitForLightAmbient(on: InputPort, greaterThanOrEqualTo: Float)

ev3.waitForLightReflection(on: InputPort, lessThanOrEqualTo: Float)

ev3.waitForLightReflection(on: InputPort, greaterThanOrEqualTo: Float)



Touch Sensor


ev3.measureTouch(on: InputPort)

ev3.measureTouchCount(on: InputPort)

ev3.resetTouchCount(on: InputPort)

ev3.waitForTouch(on: InputPort)

ev3.waitForTouchReleased(on: InputPort)

ev3.waitForTouchCount(on: InputPort, greaterThanOrEqualTo: Float)



UltrasonicSensor


ev3.measureUltrasonicCentimeters(on: InputPort)

ev3.measureUltrasonicInches(on: InputPort)

ev3.waitForUltrasonicChange(on: InputPort)

ev3.waitForUltrasonicDecrease(on: InputPort)

ev3.waitForUltrasonicIncrease(on: InputPort)

ev3.waitForUltrasonicInches(on: InputPort, greaterThanOrEqualTo: Float)

ev3.waitForUltrasonicInches(on: InputPort, lessThanOrEqualTo: Float)

ev3.waitForUltrasonicCentimeters(on: InputPort, lessThanOrEqualTo: Float)

ev3.waitForUltrasonicCentimeters(on: InputPort, greaterThanOrEqualTo: Float)



Motor Control


ev3.measureMotorDegrees(on: OutputPort)

ev3.measureMotorPower(on: OutputPort)

ev3.measureMotorRotations(on: OutputPort)

ev3.motorOff(on: OutputPort)

ev3.motorOff(on: OutputPort, brakeAtEnd: Bool)

ev3.motorOn(forDegrees: Float, on: OutputPort, withPower: Float)

ev3.motorOn(forDegrees: Float, on: OutputPort, withPower: Float, brakeAtEnd: Bool)

ev3.motorOn(forRotations: Float, on: OutputPort, withPower: Float)

ev3.motorOn(forRotations: Float, on: OutputPort, withPower: Float, brakeAtEnd: Bool)

ev3.motorOn(forSeconds: Float, on: OutputPort, withPower: Float)

ev3.motorOn(forSeconds: Float, on: OutputPort, withPower: Float, brakeAtEnd: Bool)

ev3.motorOn(on: OutputPort, withPower: Float)

ev3.move(forDegrees: Float, leftPort: OutputPort, rightPort: OutputPort, leftPower: Float, rightPower: Float)

ev3.move(forDegrees: Float, leftPort: OutputPort, rightPort: OutputPort, leftPower: Float, rightPower: Float, brakeAtEnd: Bool)

ev3.move(forRotations: Float, leftPort: OutputPort, rightPort: OutputPort, leftPower: Float, rightPower: Float)

ev3.move(forRotations: Float, leftPort: OutputPort, rightPort: OutputPort, leftPower: Float, rightPower: Float, brakeAtEnd: Bool)

ev3.move(forSeconds: Float, leftPort: OutputPort, rightPort: OutputPort, leftPower: Float, rightPower: Float)

ev3.move(forSeconds: Float, leftPort: OutputPort, rightPort: OutputPort, leftPower: Float, rightPower: Float, brakeAtEnd: Bool)

ev3.move(leftPort: OutputPort, rightPort: OutputPort, leftPower: Float, rightPower: Float)
ev3.resetMotor(on: OutputPort)

ev3.stopMove(leftPort: OutputPort, rightPort: OutputPort)

ev3.stopMove(leftPort: OutputPort, rightPort: OutputPort, withBrake: Bool)

ev3.waitForMotorDegreesChange(on: OutputPort)

ev3.waitForMotorRotationsChange(on: OutputPort)

ev3.waitForMotorPower(on: OutputPort, lessThanOrEqualTo: Float)

ev3.waitForMotorPower(on: OutputPort, greaterThanOrEqualTo: Float)

ev3.waitForMotorDegrees(on: OutputPort, lessThanOrEqualTo: Float)

ev3.waitForMotorDegrees(on: OutputPort, greaterThanOrEqualTo: Float)

ev3.waitForMotorRotations(on: OutputPort, lessThanOrEqualTo: Float)

ev3.waitForMotorRotations(on: OutputPort, greaterThanOrEqualTo: Float)




Brick Display & Sound


[Contents]











ev3.displayRectangle(atX: Int, atY: Int, length: Int, height: Int, withFill: Bool, withColor: DisplayColor, clearScreen: Bool)

Method for displaying a rectangle in a specific position, with a specific width, length, color, and fill, and possibly clearing the Display.

Example

Clear the Display and show a long, filled, black rectangle in the top left of the Display:
ev3.displayRectangle(atX: 0, atY: 0, length: 80, height: 20, withFill: true, withColor: .black, clearSCreen: true

Parameters

atX
takes an Int in range 0 to 177 for the top horizontal position, starting from the left, of the top left corner of the rectangle

atY
takes an Int 0 to 127 for the top vertical position, starting from the top, of the top left corner of the rectangle

length
takes an Int describing the length in pixels of the rectangle

height
takes an Int describing the height in pixels of the rectangle

withFill
takes a Bool with vlaue true if the rectangle should be filled

withColor
takes an input conforming to enum DisplayColor, either .white or .black

clearScreen
takes a Bool with value true if the Display should be cleared beforehand, and false otherwise

Declaration

func displayRectangle(atX: Int, atY: Int, length: Int, height: Int, withFill: Bool, withColor: DisplayColor, clearScreen: Bool)

[Contents]





General Functions


[Contents]
ev3.waitFor(seconds: Float)

Method for waiting for a specific time.

Example

Wait for 3 seconds:
ev3.waitFor(seconds: 3.0)

Parameters

seconds
takes a Float specifying the time to wait for in seconds

Declaration

func waitFor(seconds: Float)

[Contents]


Gyro Sensor


[Contents]











Infrared Sensor


[Contents]









Color/Light Sensor


[Contents]









Touch Sensor


[Contents]








UltrasonicSensor


[Contents]











Motor Control


[Contents]







Wir verwenden Cookies. Durch die Nutzung unserer Website erklärst du dich mit der Verwendung von Cookies einverstanden. Mehr dazu in unserer Datenschutzerklärung.