Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import processing.serial.*;
- Serial myPort;
- // processing global variables
- PFont myFont;
- int xPos=0;
- boolean newData=false;
- boolean newLine=false;
- int pressure;
- int pressureBase = 74500;
- void setup()
- {
- size(1440, 1000); // устанавливаем размер окна
- background(0); // устанавливаем размер окна
- colorMode(RGB, 255, 255, 255, 255);
- frameRate(30);
- myPort = new Serial(this, Serial.list()[0], 9600); // !!! Здесь прописать свой COM-порт !!!
- noSmooth();
- myFont = createFont("Tahoma", 5); // Arial, 16 point, anti-aliasing on
- textAlign(LEFT, TOP);
- textFont(myFont, 12);
- noStroke();
- }
- void draw() {
- if (newData) {
- if (!newLine) {
- fill(0x1000ffff);
- rect(xPos, pressure, 1, 1);
- //rect(10,10,100,100);
- }
- if (newLine) {
- fill(0xffffff90);
- rect(xPos, pressure, 1, 1);
- if (xPos<1440) xPos++;
- else xPos=0;
- //point(xPos, pressure);
- }
- newData=false;
- }
- }
- /* get values from serial port */
- String inString; //stor inbound serial string for parsing
- String inData; // store what's going after command char
- void serialEvent (Serial myPort) {
- inString = myPort.readStringUntil('\n'); // read the serial port until a new line
- if (inString != null) { // if theres data in between the new lines
- inData = trim(inString); // get rid of any whitespace just in case
- int inDataSplit[] = int(split(inData, ','));
- if (inDataSplit[0]<60) {
- newLine=false;
- }
- if (inDataSplit[0]==60) {
- newLine=true;
- }
- pressure=inDataSplit[1]-pressureBase;
- print(inDataSplit[0]);
- print(", x:");
- print(xPos);
- print(", p:");
- println(inDataSplit[1]);
- newData=true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement