Created
November 20, 2017 23:03
-
-
Save lisajamhoury/6a692d36a3672e1eeb9c825edae7da44 to your computer and use it in GitHub Desktop.
For Sam
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
// Serial commands to send data to Arduino | |
var serial; // variable to hold an instance of the serialport library | |
var portName = '/dev/cu.usbmodem1421'; // fill in your serial port name here | |
var options = { | |
baudrate: 9600 | |
}; // change the data rate to whatever you wish | |
var inData; // for incoming serial data | |
// var xPos = 0; // x position of the graph // UNNECESSARY | |
function setup() { | |
createCanvas(400, 400); | |
serialCommands(); | |
// connectKinect(); | |
} | |
var outByte = ''; | |
function draw() { | |
// background(120) | |
// fill(255) | |
// ellipse(xpos, ypos, 20, 20) | |
// movePos() | |
// drawBird() | |
// getSpeed() | |
// outByte = int(ypos) + ',' + int(xpos) + ',' + int(avgSpeed) | |
// outByte = 25; | |
// console.log(outByte); | |
// serial.write(outByte) | |
} | |
function serialCommands() { | |
serial = new p5.SerialPort(); // make a new instance of the serialport library | |
serial.open(portName); // open a serial port | |
serial.on('connected', serverConnected); // callback for connecting to the server | |
serial.on('list', printList); // set a callback function for the serialport list event | |
//serial.on('data', serialEvent); // callback for when new data arrives | |
serial.on('error', serialError); // callback for errors | |
serial.on('open', portOpen); // callback for the port opening | |
//serial.on('close', portClose); // callback for the port closing | |
//serial.open(portName); | |
//serial.list(); // list the serial ports | |
} | |
function serverConnected() { | |
console.log('connected to server.'); | |
} | |
function portOpen() { | |
console.log('the serial port opened.') | |
} | |
function serialEvent() { | |
// serial.write(outByte + '\n') | |
var inByte = serial.read(); | |
// store it in a global variable: | |
inData = inByte; | |
// write data to serial port | |
// serial.print(outByte) | |
// // read a string from the serial port: | |
// var inString = serial.readLine(); | |
// console.log(inString) | |
// // check to see that there's actually a string there: | |
// if (inString.length > 0 ) { | |
// // convert it to a number: | |
// inData = int(inString); | |
// } | |
} | |
function serialError(err) { | |
console.log('Something went wrong with the serial port. ' + err); | |
} | |
function portClose() { | |
console.log('The serial port closed.'); | |
} | |
function keyPressed() { | |
console.log("press"); | |
serial.write(5); | |
} | |
// get the list of ports: | |
function printList(portList) { | |
// portList is an array of serial port names | |
for (var i = 0; i < portList.length; i++) { | |
// Display the list the console: | |
console.log(i + " " + portList[i]); | |
} | |
} | |
function connectKinect() { | |
var address = { | |
host: '172.16.216.97', | |
port: 9001, | |
path: '/' | |
}; | |
kinectron = new Kinectron('kinectron', address); | |
kinectron.makeConnection(); | |
kinectron.startTrackedBodies(trackBody); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment