Positioning Problem

edited May 2015 in Library Questions

Hey Guys, bit of a noob here but if i could get help on this problem it would be greatly appreciated. I'm trying to make a graph of inString to run in three lines, one after one another, relative to the height of the canvas, and then refresh after xPos reaches bottom right corner on the third line. I tried making yPos a PVector, push/popping, and translating but I cant seem to get it to work.

import org.firmata.*; import cc.arduino.*;

import processing.serial.*;

Serial myPort; // create object from serial class String val; //data recieved from the serial port

boolean firstContact = false;

float xPos = 0; //horizontal position of the graph float yPos = height/3;

void setup() { size(400, 300); //canvas size myPort = new Serial(this, Serial.list()[0], 9600); myPort.bufferUntil('\n'); background(0); smooth(); }

void draw() { //everything happens in serialEvent }

void serialEvent(Serial myPort) {
  String inString = myPort.readStringUntil('\n'); //put incoming data into a string
  if (inString != null) {
    inString = trim(inString); //trim whitespace
    float inByte = float(inString);
    inByte = map(inByte, 0, 1023, 0, height);

    stroke(127, 34, 255, 40); //draw the line
    line(xPos, (height/3), xPos, (height/3) - (inByte/1.5));

    if ( xPos> width) { //at the edge of the screen
      translate(-width, height/3);
      line(xPos, yPos, xPos, yPos - (inByte/1.5));

     if (yPos>=height) { //at the bottom corner of the screen
        yPos = 0;  //back to beginning
        background(0, 20); //put a veil over previous data
    } else {
      xPos++; //increment horizontal position


Sign In or Register to comment.