Hi,


I have a problem about my java program keeps on sending all 4 values to Arduino instead of sending 1 at a time

I wonder is it something wrong with my Java Codes since arduino site already been tested with the serial monitor

This is what i have written in Java
public void writeData(int UpCounter, int DownCounter, int LeftCounter, int RightCounter)
if (UpCounter == 1)
{
output.write('w');
output.flush();
}

if(DownCounter == 1)
{
output.write('s');
output.flush();

}

if(LeftCounter == 1)
{
output.write('a');
output.flush();
}

if(DownCounter == 1)
{
output.write('d');
output.flush();
}



This is what in Arduino
void setup()
{
Serial.begin(9600);
Serial.println("Hello world!");

pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(13, OUTPUT);

}//end setup()

void loop(){

int id = Serial.read();

switch (id){
case 'w':
digitalWrite(13,HIGH);
delay(0500);
digitalWrite(13,LOW);
Serial.println("w!");
Serial.flush();
break;

case 's':
digitalWrite(13,HIGH);
delay(0500);
digitalWrite(13,LOW);
Serial.println("s!");
Serial.flush();
break;

case 'a':
digitalWrite(13,HIGH);
delay(0500);
digitalWrite(13,LOW);
Serial.println("a!");
Serial.flush();
break;

case 'd':
digitalWrite(13,HIGH);
delay(0500);
digitalWrite(13,LOW);
Serial.println("d!");
Serial.flush();
break;
default:{;}
}
}


Any suggestions or modifications can be done to make it works properly ?

Thanks in Advance.