Issue with sending data from Processing to Arduino over serial

Hello everyone,

I'm trying to send data from a Processing sketch to my Arduino nano over serial, but I'm having an issue.

The arduino sketch:

void setup() {
Serial.begin(9600);
Serial.setTimeout(20);
pinMode(13,OUTPUT);
}

void loop() {
int a=Serial.parseInt();
if  (a==65){
  digitalWrite(13,HIGH);}
else{
  digitalWrite(13,LOW);}
}

Basically, it's listening for the number 65, which turns on the on-board LED connected to pin 13.

The Processing sketch:

import processing.serial.*;
Serial port;
int variable=65;

void setup(){
  size(200,200);
  port=new Serial(this, "COM5", 9600);
}

void draw(){
  port.write("65"); 
}

This sketch will send the number 65, and turn on the LED on the arduino.
However, I dont want it to just send the number 65. I want to use a variable.
But when I replace port.write("65"); with port.write(variable); that doesn't work. From what I understand, it doesnt send the integer 65, but the letter A.
Could anyone tell me how to make my sketch send the number 65 instead of the letter A?
Eventually my plan is to use the processing sketch to send a joystick position to the arduino, and control a motor or servo.

This sketch will send the number 65

It will NOT. It will send the STRING "65". That is NOT the same thing.

Could anyone tell me how to make my sketch send the number 65 instead of the letter A?

Serial.write(65);

Using a variable:

byte var = 65;
Serial.write(var);

Do NOT use the wrong type for the variable.

Thanks! I'll see if I can make it work.

Have a look at Serial Input Basics - simple reliable ways to receive serial data. There is also a parse example

...R