Advertisement
MattRichardson

Touch Screen Processing Sketch

Oct 15th, 2011
509
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.92 KB | None | 0 0
  1. float offset = 2.23;
  2. float rot = 0.0;
  3. import processing.serial.*;
  4. int yPos =0;
  5. int xPos = 0;
  6.  
  7. boolean colorRed = false;
  8. boolean colorGreen = false;
  9. boolean colorBlue = false;
  10.  
  11.  
  12.  Serial myPort;        // The serial port
  13.  
  14.  
  15. void setup() {
  16.   smooth();
  17.   size(1200,900);
  18.   background(255);
  19.    println(Serial.list());
  20.    myPort = new Serial(this, Serial.list()[0], 115200);
  21.     myPort.bufferUntil('\n');
  22. }
  23.  
  24.  
  25. void draw() {
  26.  
  27.  
  28. }
  29. void serialEvent (Serial myPort) {
  30.  
  31.    String inString = myPort.readStringUntil('\n');
  32.     if (inString != null) {
  33.        // trim off any whitespace:
  34.        inString = trim(inString);
  35.        int xCharPos = inString.indexOf("X");
  36.        int yCharPos = inString.indexOf("Y");
  37.        int pCharPos = inString.indexOf("P");
  38.        
  39.        String xString = inString.substring(xCharPos + 1, yCharPos);
  40.        String yString = inString.substring(yCharPos + 1, pCharPos);
  41.        String pString = inString.substring(pCharPos + 1, inString.length());
  42.        
  43.       println(xString + "\t" + yString + "\t" + pString);
  44.      
  45.       xPos = int(map((Integer.parseInt(xString)), 90, 950, 0, width));
  46.       yPos = int(map((Integer.parseInt(yString)), 920, 120, 0, height));
  47.       int ellipseSize = max(int(map((Integer.parseInt(pString)), 300, 150, 1, 200)),1) ;
  48.       noStroke();
  49.       fill(40,40,40,20);
  50.       if (colorRed)
  51.         fill(255, 0, 0, 20);
  52.       if (colorGreen)
  53.         fill(0,255,0,20);
  54.       if (colorBlue)
  55.         fill(0,0,255,20);
  56.        ellipse(xPos, yPos, ellipseSize, ellipseSize);
  57.      }
  58. }
  59.  
  60. void keyPressed() {
  61.   if (key == 'r' || key == 'R') {
  62.     colorRed =! colorRed;
  63.     colorGreen = false;
  64.     colorBlue = false;
  65.   }
  66.     if (key == 'g' || key == 'G') {
  67.     colorGreen =! colorGreen;
  68.     colorRed = false;
  69.     colorBlue = false;
  70.   }
  71.     if (key == 'b' || key == 'B') {
  72.     colorBlue =! colorBlue;
  73.     colorGreen = false;
  74.     colorRed = false;
  75.   }
  76. }
  77.  
  78.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement