Skip to content

Instantly share code, notes, and snippets.

@attilavago
Last active January 2, 2017 22:08
Show Gist options
  • Save attilavago/8a7a79e6f8869111c1aee8501c69e4c3 to your computer and use it in GitHub Desktop.
Save attilavago/8a7a79e6f8869111c1aee8501c69e4c3 to your computer and use it in GitHub Desktop.
This tests pressed/released touch sensor states
import RobotKit
// Constant that points to the port the touch sensor is situated at
let touchSensorPort = EV3InputPort.one
// Initializes a new EV3Robot instance through which all device communication happens
let robot = try EV3Robot()
// Provides access to the ultrasonic sensor at the given port
guard let touchSensor = robot.touchSensor(atPort: touchSensorPort) else {
fatalError("Can't find the touch sensor!")
}
// While the sensor is connected, check for the state of the sensor: pressed/released
while true {
let touchStatePressed = touchSensor.waitUntil(.pressed)
print("pressed")
let touchStateReleased = touchSensor.waitUntil(.released)
print("released")
}
// Stop the app via the stop button in the Robotary app
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment