Beginner question on Serial Communication

edited July 2014 in Library Questions


Im new to the whole Processing world. Im trying to make to Processing to communicating with my Arduino. I found this tutorial that uses this code:

import processing.serial.*;

Serial myPort;  // Create object from Serial class

void setup() 
  size(200,200); //make our canvas 200 x 200 pixels big
  String portName = Serial.list()[0]; //change the 0 to a 1 or 2 etc. to match your port
  myPort = new Serial(this, portName, 9600);

void draw() {
  if (mousePressed == true) 
  {                           //if we clicked in the window
   myPort.write('1');         //send a 1
  } else 
  {                           //otherwise
  myPort.write('0');          //send a 0

I understand the void draw with no problems. My problem is the setup:

1) Why use the "String" command? Could "char" not be used? 2) The following line: "myPort = new Serial(this, portName, 9600);" I doesn't understand the "new" and "this". What is the function of these commands??

Thanks! :)


Sign In or Register to comment.