Processing, Arduino and Linux

https://processing.org/reference/libraries/serial/Serial.html
show you that you can get a list of the ports
and use directly the

myPort = new Serial(this, Serial.list()[0], 9600); // change [0] to [..] correct port

so no need to type the name…


for the write, you only send once if needed,
so like from

void keyPresssed() {
  if ( key == '1' ) myPort.write('1');
  if ( key == '0' ) myPort.write('0');
}

and on the Arduino side find again
1 or 0 AS character !
that code there would be testable also from arduino monitor
( again by type 1 0 from keyboard ? but there must press enter? )

what i want to say is stay on the ( easy diagnostic ) ASCII level
until there is no other way as to write byte stream / own protocol …


mouse over circle is not good idea,
better mouse over circle and click send once is better.

here would use the

void mousePressed() {
  if ( over_circle(x0,y0,r0) ) myPort.write('0');
  if ( over_circle(x1,y1,r1) ) myPort.write('1');
}

or use one circle and a toggle bit ( memory )
anyhow the

boolean over_circle(x,y,r) {}

you should write first.

1 Like