Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 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);
- }
Add Comment
Please, Sign In to add comment