Line Graph instead of Bar graph

Hi all, I am helping my daughter with a science project where she has to measure vibration.

I followed a tutorial and I got the bar graph to show up in processing but I would like to graph it as a line graph instead. I found this page here that he modified the code from the same tutorial I used but the code as he posted does not work.

http://arduining.com/2013/08/05/arduino-and-processing-graph-example/

The people in the comments seem to have the same problems I am having with his code.

Here is my code that graphs a piezo to processing to a bar graph and it works well. I just think it would look nicer as a line graph.

Written to arduino uno

const int threshold = 25;
int sensorReading = 0;

void setup() {
  
  // initialize the serial communication:
  Serial.begin(9600);
}

void loop() {
sensorReading = analogRead(A0);
  if (sensorReading >= threshold) {
  

  Serial.println(sensorReading);
  }
  else {
  Serial.println(0);

  delay(5);
}
}

and here is the processing sketch

import processing.serial.*;

Serial myPort;        // The serial port
int xPos = 1;         // horizontal position of the graph
float inByte = 0;

void setup () {
  // set the window size:
  size(900, 800);

  // List all the available serial ports
  // if using Processing 2.1 or later, use Serial.printArray()
  println(Serial.list());

  // I know that the first port in the serial list on my mac
  // is always my  Arduino, so I open Serial.list()[0].
  // Open whatever port is the one you're using.
  myPort = new Serial(this, "COM4", 9600);

  // don't generate a serialEvent() unless you get a newline character:
  myPort.bufferUntil('\n');

  // set inital background:
  background(0);
}
void draw () {
  // draw the line:
  stroke(127, 34, 255);
  line(xPos, height, xPos, height - inByte);

  // at the edge of the screen, go back to the beginning:
  if (xPos >= width) {
    xPos = 0;
    background(0);
  } else {
    // increment the horizontal position:
    xPos++;
  }
}


void serialEvent (Serial myPort) {
  // get the ASCII string:
  String inString = myPort.readStringUntil('\n');

  if (inString != null) {
    // trim off any whitespace:
    inString = trim(inString);
    // convert to an int and map to the screen height:
    inByte = float(inString);
    println(inByte);
    inByte = map(inByte, 0, 1023, 0, height);
  }
}

I don't know Processing, but it sounds like your problem is a Processing problem rather than an Arduino problem. I assume there is a Processing Forum somewhere.

...R

The people in the comments seem to have the same problems I am having with his code.

I'm not going to wade through a boat load of vague comments to guess what YOUR problem is. Define the problem HERE, since you posted your issue HERE.

I assume there is a Processing Forum somewhere.

There is, but enough of us use both that Arduino-related Processing questions are OK here.

To draw a line graph you need to draw a line from the previous point to the latest point and then make the latest the previous point.

line(xPos, height, xPos, height - inByte);

==>

int latestHeight = height - inByte; line(xPos-1, previousHeight , xPos, latestHeight); previousHeight = latestHeight;

previousHeight must be a global int and you need to add some extra admin to get the first & last point of the graph correct.