import processing.serial.*; import java.util.Arrays; Serial p; //colors: int white = 255; int black = 0; int green = #00FF00; int grey = 150; // shift, reducer and millisecond view float reducer = 1.0; boolean milliseconds = false; boolean isMilliseconds= false; int xShift; // start point in the processing window int xEdge = 60; int yEdge = 30; int xEnd; float[] xPos = {0, 0, 0, 0, 0, 0}; int yBottom = 390; int yDiff; int yPos = yEdge; int ySave = yEdge; boolean textCovered; boolean drawTimes = true; //Serial from mcu //initial data int samples; int event; int initialState; boolean first = false; boolean dataComplete = false; //following data boolean [][] state; boolean [] isLow = new boolean[6]; float[] usTime; int[] changed; float[] xTime; //buttons and others int button1X = 8; int button2X = 8; int button3X = 80; int button4X = 200; int button5X = 270; int buttonY; int buttonH = 20; int smallButtonW = 50; int bigButtonW = 100; int graphBoxH; int immage = 1; int corner = 10; void setup () { p = new Serial(this, "com3", 9600); p.bufferUntil('\n'); size(1000, 450); background(black); smooth(4); graphBoxH = height -40; buttonY = height -30; } void cleanGraph() { noStroke(); //no borders fill(black); rect(xEdge, 0, width, graphBoxH); //cancel the graph stroke(green); //line color Arrays.fill(xPos, 0); //reset start point of the graph } void draw () { if (dataComplete==true) { cleanGraph(); pushMatrix(); //move the coordinate reference translate(xEdge, 0); for (int i=0; iyBottom-15 && mouseY button1X && mouseX buttonY && mouseY button2X && mouseX buttonY && mouseY button3X && mouseX buttonY && mouseY button5X && mouseX buttonY && mouseY button4X && mouseX buttonY && mouseY button2X && mouseX buttonY && mouseY button3X && mouseX buttonY && mouseY button5X && mouseX yBottom-15 && mouseY button1X && mouseX 0) { int i; boolean drawLine = true; // alternate between dashes and gaps /* Figure out x and y distances for each of the spacing values I decided to trade memory for time; I'd rather allocate a few dozen bytes than have to do a calculation every time I draw. */ for (i = 0; i < spacing.length; i++) { xSpacing[i] = lerp(0, (x1 - x0), spacing[i] / distance); ySpacing[i] = lerp(0, (y1 - y0), spacing[i] / distance); } i = 0; while (drawn < distance) { if (drawLine) { line(x0, y0, x0 + xSpacing[i], y0 + ySpacing[i]); } x0 += xSpacing[i]; y0 += ySpacing[i]; /* Add distance "drawn" by this line or gap */ drawn = drawn + mag(xSpacing[i], ySpacing[i]); i = (i + 1) % spacing.length; // cycle through array drawLine = !drawLine; // switch between dash and gap } } } int button3X = 80; int button4X = 200; int button5X = 270; int buttonY; int buttonH = 20; int smallButtonW = 50; int bigButtonW = 100; int textBoxH; int immage = 1; int corner = 10; void setup () { p = new Serial(this, "com3", 9600); p.bufferUntil('\n'); size(1000, 450); background(black); smooth(4); textBoxH = height -40; buttonY = height -30; } void cleanScreen() { noStroke(); //no borders fill(black); rect(xEdge, 0, width, textBoxH); //cancel the graph stroke(green); //border Arrays.fill(xPos, 0); //reset start point of the graph if (graphShift==true) { int b; int mask = 1; for (int n=0; n<6; n++) { b = initialState & mask; isLow[n] = !boolean (b); mask <<= 1; //println("islow: "+isLow[n]); } } } void draw () { if (dataComplete==true || graphShift==true) { cleanScreen(); pushMatrix(); //move the coordinate reference translate(xEdge, 0); for (int i=0; iyBottom-15 && mouseY button1X && mouseX buttonY && mouseY button2X && mouseX buttonY && mouseY button3X && mouseX buttonY && mouseY button5X && mouseX buttonY && mouseY button4X && mouseX buttonY && mouseY button2X && mouseX buttonY && mouseY button3X && mouseX buttonY && mouseY button5X && mouseX yBottom-15 && mouseY button1X && mouseX 0) { int i; boolean drawLine = true; // alternate between dashes and gaps /* Figure out x and y distances for each of the spacing values I decided to trade memory for time; I'd rather allocate a few dozen bytes than have to do a calculation every time I draw. */ for (i = 0; i < spacing.length; i++) { xSpacing[i] = lerp(0, (x1 - x0), spacing[i] / distance); ySpacing[i] = lerp(0, (y1 - y0), spacing[i] / distance); } i = 0; while (drawn < distance) { if (drawLine) { line(x0, y0, x0 + xSpacing[i], y0 + ySpacing[i]); } x0 += xSpacing[i]; y0 += ySpacing[i]; /* Add distance "drawn" by this line or gap */ drawn = drawn + mag(xSpacing[i], ySpacing[i]); i = (i + 1) % spacing.length; // cycle through array drawLine = !drawLine; // switch between dash and gap } } } int boxH; int boxW; void setup () { p = new Serial(this, "com3", 9600); p.bufferUntil('\n'); size(1000, 450); background(black); smooth(3); boxH = height -50; boxW = 20; } void cleanScreen() { noStroke(); //no borders fill(black); rect(xEdge, 0, width, boxH); //cancel the graph stroke(green); //border Arrays.fill(xPos, 0); //reset start point of the graph if (graphShift==true) { int b; initialState = save_initialState; for (int n=0; n<6; n++) { b = initialState & 1; isLow[n] = !boolean (b); initialState >>= 1; //println("islow: "+isLow[n]); } } } void draw () { if (dataComplete==true || graphShift==true) { cleanScreen(); pushMatrix(); //move the coordinate reference translate(xEdge, 0); for (int i=0; iboxH && mouseY boxW && mouseX boxH && mouseY boxW+80 && mouseX boxH && mouseY boxW+330 && mouseX boxH && mouseY boxW+230 && mouseX boxH && mouseY boxW && mouseX boxW+80 && mouseX boxW+330 && mouseX >= 1; //println("islow: "+isLow[n]); } // changes for (int i=0; i>= 1; //println(state[i][n]); } } dataComplete = true; } float[] spacing = {5, 4}; //used for the dashline function, pixels void dashline(float x0, float y0, float x1, float y1, float[] spacing) { float distance = dist(x0, y0, x1, y1); float [ ] xSpacing = new float[spacing.length]; float [ ] ySpacing = new float[spacing.length]; float drawn = 0.0; // amount of distance drawn if (distance > 0) { int i; boolean drawLine = true; // alternate between dashes and gaps /* Figure out x and y distances for each of the spacing values I decided to trade memory for time; I'd rather allocate a few dozen bytes than have to do a calculation every time I draw. */ for (i = 0; i < spacing.length; i++) { xSpacing[i] = lerp(0, (x1 - x0), spacing[i] / distance); ySpacing[i] = lerp(0, (y1 - y0), spacing[i] / distance); } i = 0; while (drawn < distance) { if (drawLine) { line(x0, y0, x0 + xSpacing[i], y0 + ySpacing[i]); } x0 += xSpacing[i]; y0 += ySpacing[i]; /* Add distance "drawn" by this line or gap */ drawn = drawn + mag(xSpacing[i], ySpacing[i]); i = (i + 1) % spacing.length; // cycle through array drawLine = !drawLine; // switch between dash and gap } } }