i want to pass a number from php to arduino. currently, i am able to communicate between php and arduino via serial port. however, when i try to pass a number(int) from php to arduino, the arduino can't identify it. then i try to pass an character(char) it is able to detect. i have tried multiple times and i don't know what is wrong with the code. below is my code.
PHP CODE
$X = $_POST['x'];
$Y = $_POST['y'];
$query = "INSERT INTO target_position (X,Y,Date) VALUES('$X','$Y',now())";
$insert = mysql_query($query);
$serial = new phpSerial();
$serial ->deviceSet("COM6"); //Port number
$serial ->confbaudRate(9600);
$serial ->confParity("none");
$serial ->confCharacterLength(8);
$serial ->confStopBits(1);
$serial ->confFlowControl("none");
$serial ->deviceOpen();
$serial ->sendMessage('1');
//$serial ->sendMessage('$Y');
//$jinhong =$serial ->readPort();
$serial ->deviceClose();
//echo $jinhong;
here is the arduino code
int led =13;
int test=0;
void setup()
{
Serial.begin(9600);
pinMode(led, OUTPUT);
}
void loop()
{
while(Serial.available()==0);
test=Serial.read();
if(test=='1')
{
digitalWrite(led,HIGH);
delay(500);
digitalWrite(led,LOW);
delay(500);
digitalWrite(led,HIGH);
delay(500);
digitalWrite(led,LOW);
}
}
Anyone can tell me what is wrong? The led doesn't light up at when i send 1. however when i send 'A', the led is up.