Skip to content

Instantly share code, notes, and snippets.

View attilavago's full-sized avatar
💭
Code is happening...

Attila Vago attilavago

💭
Code is happening...
View GitHub Profile
@attilavago
attilavago / motortest.swift
Last active January 1, 2017 22:30
Running motors with robotary
// 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
@attilavago
attilavago / touchSensorTest.swift
Last active January 2, 2017 22:08
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 {
@attilavago
attilavago / ambientLightSensorTest.swift
Last active January 2, 2017 22:08
This tests the ambient light sensor in light intensity percentage
/// 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 {
@attilavago
attilavago / colorSensorTest.swift
Created January 2, 2017 21:41
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 {
@attilavago
attilavago / irSensorTest.swift
Last active January 2, 2017 21:57
This test demonstrates using the IR sensor
/// 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]
@attilavago
attilavago / ultrasonicSensorTest.swift
Created January 2, 2017 22:07
This test demonstrates measuring distance in cm
/// 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]
@attilavago
attilavago / gyroSensorTest.swift
Created January 2, 2017 22:40
This test demonstrates getting the tilt value from a gyro sensor
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!")
}
@attilavago
attilavago / ledTestEV3.py
Created January 6, 2017 21:30
Simple demo python program for EV3
#!/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()])
@attilavago
attilavago / promises.js
Created January 25, 2017 15:35
Node.js ES6 Promises Example
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;
@attilavago
attilavago / puck_pp_presenter.js
Last active November 20, 2019 16:44
PowerPoint presenter using a Puck.js beacon's button and magnetic sensor.
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);
}