This file contains hidden or 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
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 { |
This file contains hidden or 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
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; | |
} |
This file contains hidden or 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 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; |
This file contains hidden or 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 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; |
This file contains hidden or 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
if (c == '5') { | |
pulse = pulseIn(sonarPin, HIGH); | |
inches = pulse/147; //convert PWM output from sonar sensor to inches | |
client.print(String(inches)); | |
} |
This file contains hidden or 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
const int sonarPin = 5; //digital pin your sonar sensor is plugged into | |
long pulse, inches, cm; | |
void setup() { | |
//... | |
pinMode(sonarPin, INPUT); | |
} |
This file contains hidden or 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
void loop() | |
{ | |
//turn on the LED if the TCP socket is open | |
if (client.connected()) { | |
digitalWrite(ledPin, HIGH); | |
} | |
else { | |
digitalWrite(ledPin, LOW); | |
} | |
This file contains hidden or 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
void stopMovement() { | |
rightservo.write(rightStopPos); | |
leftservo.write(leftStopPos); | |
} | |
void turnLeft() { | |
rightservo.write(180); | |
leftservo.write(180); | |
} |
This file contains hidden or 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
void setup() { | |
//... | |
rightservo.attach(rightservoPin); | |
leftservo.attach(leftservoPin); | |
} |
This file contains hidden or 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
#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; |