Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ArrayList<PVector> history = new ArrayList<PVector>();
- import processing.serial.*;
- float[] portValues = new float[8];
- Serial myPort;
- String inString;
- void setup() { //set up canves
- size(400,400);
- frameRate (30);
- rectMode(CENTER);
- background(225);
- myPort = new Serial(this, "/dev/cu.usbmodem1421", 9600);
- for(int i = 0; i<2; i++) { //set inatial point
- PVector point = new PVector(425,550);
- history.add(point);
- portValues[i] = 0;
- }
- }
- void draw() { //finds last x and y positions and draws a line between them
- fill(0);
- strokeWeight(2);
- if (inString != null)
- {
- portValues = processSensorValues(inString);
- }
- float z = portValues[2]/3;
- float xx = map(portValues[0],-10,10,0,width);
- float yy = map(portValues[1],-10,10,0,height);
- if(portValues[3] == 1)
- {
- PVector point = new PVector(xx,yy);
- history.add(point);
- PVector newPt = history.get(history.size()-1);
- PVector oldPt = history.get(history.size()-2);
- line(oldPt.x,oldPt.y,newPt.x,newPt.y);
- }
- else if(portValues[3] == 0)
- {
- }
- println(inString); //prints data
- }
- float[] processSensorValues(String valString) { //uses tempture data for nothing, but helps process data
- String[] temp = new String[8];
- temp = split(valString,"\t");
- if(temp == null) {
- for(int i = 0; i<8; i++) {
- temp[i] = "0";
- }
- }
- float[] vals = new float[8];
- for(int i = 0; i<8; i++)
- {
- if(temp != null)
- {
- vals[i] = float(temp[i]);
- }
- else
- {
- vals[i] = 0;
- }
- }
- return vals;
- }
- void serialEvent(Serial p) {
- inString = myPort.readStringUntil(10);
- }
Add Comment
Please, Sign In to add comment