plotting x and y coordinates

edited June 2016 in Arduino

greetings, i am trying to plot x and y coordinates from a touchpad connected to my pc via arduino. my arduino gives me a string that looks like that 233,672,0 the first part is my x coordinate, my second part is the y coordinate and that last part, is a 0 or 1 to tell me if there was a touch or not. until now i can see where my coordinates are with ellipse function, but i still cant get it to simply draw a line connecting all positions of my postion on the touchpad. my plan is to use the touchpad to write a letter, and when the letter is done written, i want to compare the letter that was drawn with another saved one on my pc. any help i would be thankful, here is my code

Answers

  • edited June 2016
    import processing.serial.*; 
    
    float x, y;
    int touch;
    
    void setup() { 
      size(600, 600);
      //fullScreen();
      Serial arduino = new Serial(this, "COM3", 9600); 
      arduino.bufferUntil('\n'); 
    } 
    
    void draw() { 
      background(0);
      line(x, y, x, y);
      ellipse(x, y, 10, 10);
    }
    
    void serialEvent(Serial p) { 
      String rawString = p.readString();
      rawString = rawString.trim();
      try {
        String[] values = split(rawString,",");
        int serialX = int(values[0]);
        int serialY = int(values[1]);    
        int touch = int(values[2]);
        x = map(serialX, 0, 640, 0, width);
        y = map(serialY, 0, 480, 0, height);
      } catch (Exception e){
        println("Error parsing string from Serial:");
        e.printStackTrace();
      }
    }
    
Sign In or Register to comment.