This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Test the motors all all 4 ports | |
import RobotKit | |
// Create a new EV3Robot instance to talk to the robot | |
let robot = try EV3Robot() | |
// Access motors at ports A, B, C and D. | |
let motors = robot.motors(atPorts: [.A, .B, .C, .D]) // note de dot notation of the ports | |
// Adding variables to access motors individually |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// EV3 Ambient Light Sensor Sample | |
/// Demonstrates how to poll EV3's light sensor for ambient light information. | |
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 { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// EV3 Infrared Sample | |
/// The robot advances forward until the infrared sensor detects a nearby obstacle. | |
/// It then stops, plays a tone, and displays a message for two seconds. | |
/// Note that this can be done more accurately using the ultrasonic sensor. | |
import RobotKit | |
// Constants to adjust. | |
let infraredSensorPort = EV3InputPort.one | |
let motorsPorts: EV3OutputPorts = [.A] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// EV3 Ultrasonic Sensor Sample | |
/// The robot advances forward until the ultrasonic sensor detects an object within 50 cm. | |
/// It then stops, plays a tone, and displays a message for two seconds. | |
import RobotKit | |
// Constants to adjust. | |
let ultrasonicSensorPort = EV3InputPort.one | |
let motorsPorts: EV3OutputPorts = [.A] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import RobotKit | |
// Initializes a new EV3Robot instance through which all device communication happens | |
let robot = try EV3Robot() | |
// Sets up a gyro sensor at input port 1 | |
guard let gyroSensor = robot.gyroSensor(atPort: .one) else { | |
fatalError("No gyro sensor at the given port!") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
from ev3dev.ev3 import * | |
import ev3dev.ev3 as ev3 | |
ts = ev3.TouchSensor() | |
while True: | |
ev3.Leds.set_color(ev3.Leds.LEFT, (ev3.Leds.GREEN, ev3.Leds.RED)[ts.value()]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
new Promise(function(resolve, reject) { | |
setTimeout(function() { | |
var firstVal = 1; | |
// in the promise what you resolve is what gets returned | |
resolve(firstVal); | |
console.log('the initial promise renders: ', firstVal); | |
}, 3000); // faking some longer process | |
}) | |
.then(function(firstVal) { | |
var secondVal = firstVal + 1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var kb = require("ble_hid_keyboard"); | |
NRF.setServices(undefined, { hid : kb.report }); | |
var next = "n"; | |
var prev = "p"; | |
function sendPrev(){ | |
sendCharPrev(); | |
LED2.set(); | |
setTimeout("LED2.reset()",1000); | |
} |
OlderNewer