Skip to content

Instantly share code, notes, and snippets.

@attilavago
Created January 2, 2017 21:41
Show Gist options
  • Save attilavago/4be04cabf158ddce9f932c96344e6883 to your computer and use it in GitHub Desktop.
Save attilavago/4be04cabf158ddce9f932c96344e6883 to your computer and use it in GitHub Desktop.
This test demonstrates how to get color information via the light sensor
// EV3 Color Sensor Sample
// Demonstrates how to get color information via the light sensor
import RobotKit
// Initializes a new EV3Robot instance through which all device communication happens
let robot = try EV3Robot()
// Sets up a light sensor at input port 1
guard let lightSensor = robot.lightSensor(atPort: .one) else {
fatalError("No light sensor at the given port!")
}
// Continues until the program is stopped
while true {
// Reads the color value as a string and outputs to the console
let colorRed = lightSensor.waitUntilColorIs(.red)
print("red")
let colorBlack = lightSensor.waitUntilColorIs(.black)
print("black")
let colorYellow = lightSensor.waitUntilColorIs(.yellow)
print("yellow")
}
// Stop program via the app's stop button
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment