School project problem (arduino)

Try Serial.write() on Arduino side and myPort.read(); on Processing side.

I got that to work with your code and it moved in a square.

Once you understand that try working with sending and receiving strings of data; these always caused me some grief until I understood it better.

Arduino test code:

void setup()
  {
  Serial.begin(9600);
  }

void loop()
  {
  int x;
  for (int i = 0; i <= 100; i++)
    {
    x = 2;
    Serial.write(x);
    }

  for (int i = 0; i <= 100; i++)
    {
    x = 4;
    Serial.write(x);
    }

  for (int i = 0; i <= 100; i++)
    {
    x = 1;
    Serial.write(x);
    }
  for (int i = 0; i <= 100; i++)
    {
    x = 3;
    Serial.write(x);
    }
  }

On the Processing side convert all strings to int:

int valori;

printArray(Serial.list());
myPort = new Serial(this, Serial.list()[2], 9600);
//myPort = new Serial(this, "COM3",9600);

valori = myPort.read();

print(valori);

if (valori != 0) 

if (valori==1)

if (key=='1') valori=1;

Going for a hike now!