Advertisement
Guest User

Untitled

a guest
Jul 29th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.79 KB | None | 0 0
  1.  
  2. import processing.serial.*;
  3. Serial myPort;
  4.  
  5. // processing global variables
  6. PFont myFont;
  7. int xPos=0;
  8. boolean newData=false;
  9. boolean newLine=false;
  10. int pressure;
  11. int pressureBase = 74500;
  12.  
  13. void setup()
  14. {
  15.   size(1440, 1000); // устанавливаем размер окна
  16.   background(0); // устанавливаем размер окна
  17.   colorMode(RGB, 255, 255, 255, 255);
  18.   frameRate(30);
  19.   myPort = new Serial(this, Serial.list()[0], 9600); // !!! Здесь прописать свой COM-порт !!!
  20.   noSmooth();
  21.   myFont = createFont("Tahoma", 5);          // Arial, 16 point, anti-aliasing on
  22.   textAlign(LEFT, TOP);
  23.   textFont(myFont, 12);
  24.   noStroke();
  25. }
  26.  
  27. void draw() {
  28.   if (newData) {
  29.     if (!newLine) {
  30.       fill(0x1000ffff);
  31.       rect(xPos, pressure, 1, 1);
  32.       //rect(10,10,100,100);
  33.     }
  34.     if (newLine) {
  35.       fill(0xffffff90);
  36.       rect(xPos, pressure, 1, 1);
  37.       if (xPos<1440) xPos++;
  38.       else xPos=0;
  39.       //point(xPos, pressure);
  40.     }
  41.     newData=false;
  42.   }
  43. }
  44.  
  45.  
  46. /* get values from serial port */
  47. String inString; //stor inbound serial string for parsing
  48. String inData; // store what's going after command char
  49.  
  50.  
  51. void serialEvent (Serial myPort) {
  52.   inString = myPort.readStringUntil('\n');  // read the serial port until a new line
  53.   if (inString != null) {  // if theres data in between the new lines
  54.     inData = trim(inString); // get rid of any whitespace just in case
  55.     int inDataSplit[] = int(split(inData, ','));
  56.     if (inDataSplit[0]<60) {
  57.       newLine=false;
  58.     }
  59.     if (inDataSplit[0]==60) {
  60.       newLine=true;
  61.     }
  62.     pressure=inDataSplit[1]-pressureBase;
  63.     print(inDataSplit[0]);
  64.     print(", x:");
  65.     print(xPos);
  66.     print(", p:");
  67.     println(inDataSplit[1]);
  68.     newData=true;
  69.   }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement