That is how Java handles a byte. Once you send the byte out the serial port it is just data and the receiving end then has to deal with it.
What is the device that is receiving?
Take another look at the description and parameters:
write() / Libraries / Processing.org
You can convert your int to a byte and send the byte or you can send each element of your int individually in a loop.
If you are sending an integer it will only send the LSB (least significant byte which is 0 to 255):
Sending integers
import processing.serial.*;
void setup()
{
// The serial port:
Serial myPort;
// List all the available serial ports:
printArray(Serial.list());
// Open the port you are using at the rate you want:
myPort = new Serial(this, Serial.list()[2], 9600);
// Send a capital "A" out the serial port
for(int i=0; i< 300; i++)
{
myPort.write(i);
}
myPort.stop();
}
Sending byte array
import processing.serial.*;
byte [] b = new byte [300];
void setup()
{
// The serial port:
Serial myPort;
// List all the available serial ports:
printArray(Serial.list());
// Open the port you are using at the rate you want:
myPort = new Serial(this, Serial.list()[2], 9600);
// Send a capital "A" out the serial port
for(int i=0; i< 300; i++)
{
//myPort.write(i);
b[i] = byte(i);
}
myPort.write(b);
myPort.stop();
}
This is the same data received on a terminal for both of the code examples:
Take a look at the last few rows and numbers over 255 = 0xFF !
I suggest exploring this a bit more and it will make sense at some point.
Take a look at this:
void setup()
{
for(int i=0; i<256; i++)
{
byte b = byte(i);
println(b, '\t', char(b),'\t', (int(b)), '\t', hex(b), '\t', byte(b), '\t', int(b));
}
}
The output:
:)