Thank you for reading my first post. This question relates to the Simple Write serial example.
String portName = Serial.list()[0];
myPort = new Serial(this, portName, 9600);
This doesn’t find the correct port but it does if I change [0] to [32] or do the following:
myPort = new Serial(this, "/dev/ttyUSB0", 9600);
I’m inclined to use the latter, is that the correct approach?
Also, processing, again using the simple write example, continually sends serial data to the Arduino. Is that the way it should work? Moving the mouse over the circle does send the correct data and does turn the led on and off but I’m concerned about the continual sending of data. I expected data to be sent only while the mouse is over the circle.
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