Skip to content

Instantly share code, notes, and snippets.

View jonmarkgo's full-sized avatar
🎓
preparing the MLH Fellowship

Jonathan Gottfried jonmarkgo

🎓
preparing the MLH Fellowship
View GitHub Profile
function getDigits(call, input) {
console.log('pressed ' + input);
if (arduinoTcp === null) {
call.say("I can't do that for you, Hal. I'm offline.");
} else {
curr_call = call;
if (['2', '4', '5', '6', '8', '0'].indexOf(input) >= 0) {
arduinoTcp.write(input);
call.gather(getDigits, {numDigits: 1});
} else {
tcpServer.on('connection', function (socket) {
console.log('num of connections on port 1337: ' + tcpServer.connections);
arduinoTcp = socket;
socket.on('data', function (mydata) {
console.log('received on tcp socket:' + mydata);
curr_call.load(function (err, call) {
if (err) {
throw err;
}
@jonmarkgo
jonmarkgo / gist:2962480
Created June 20, 2012 21:59
Twilio app setup
var twilio_app = cli.account.getApplication(process.env.app_sid, function (err, app) {
if (err) {
throw err;
}
app.register();
app.on('incomingCall', function (call) {
if (arduinoTcp === null) {
call.say("I can't do that for you, Hal. I'm offline.");
} else {
curr_call = call;
var express = require('express'), app = express.createServer(), net = require('net'), twilioAPI = require('twilio-api');
var cli = new twilioAPI.Client(process.env.account_sid, process.env.auth_token);
app.use(cli.middleware());
app.listen(8002);
var arduinoTcp = null;
var curr_call = null;
if (c == '5') {
pulse = pulseIn(sonarPin, HIGH);
inches = pulse/147; //convert PWM output from sonar sensor to inches
client.print(String(inches));
}
@jonmarkgo
jonmarkgo / gist:2950131
Created June 18, 2012 19:09
Sonar config
const int sonarPin = 5; //digital pin your sonar sensor is plugged into
long pulse, inches, cm;
void setup() {
//...
pinMode(sonarPin, INPUT);
}
@jonmarkgo
jonmarkgo / gist:2949728
Created June 18, 2012 17:59
Respond to commands
void loop()
{
//turn on the LED if the TCP socket is open
if (client.connected()) {
digitalWrite(ledPin, HIGH);
}
else {
digitalWrite(ledPin, LOW);
}
@jonmarkgo
jonmarkgo / gist:2949682
Created June 18, 2012 17:51
Movement functions
void stopMovement() {
rightservo.write(rightStopPos);
leftservo.write(leftStopPos);
}
void turnLeft() {
rightservo.write(180);
leftservo.write(180);
}
@jonmarkgo
jonmarkgo / gist:2949671
Created June 18, 2012 17:50
setup servos
void setup() {
//...
rightservo.attach(rightservoPin);
leftservo.attach(leftservoPin);
}
@jonmarkgo
jonmarkgo / gist:2949656
Created June 18, 2012 17:46
Set up Servos
#include <Servo.h>
const int rightservoPin = 9; //digital pin your right servo is plguged into
const int leftservoPin = 10; //digital pin your left servo is plguged into
const int rightStopPos = 91; //stop position of your right servo
const int leftStopPos = 91; //stop position of your left servo
Servo rightservo;
Servo leftservo;