I am trying to turn a LED on and OFF on the arduino trough a piece of PHP code that is on my computer.
I have managed to get communication between the arduino an the computer, and the arduino to react accordingly to the code I hve written. But i have one big problem. The PHP code seems to "remeber" all the characters I have put in to $i. Ex: I start the PHP code with the character $i = (0), I then get 0 0 0 0....... in my serial monitor. But if I change the $i value to ex: $i = (1) I then get 0 1 0 1 0 1....... in my serial monitor and if I again change it to $i = (3) the serial monitor will diplay 0 1 3 0 1 3 0 1 3......
So my question is, are there any ways to get the PHP code to only output the value of $i at that given moment, and not all the values $i has been.
Sorry about my poor english grammar.
Here are the code for my little project.
PHP:
<?php exec("mode /dev/du.usbmodem3d11: BAUD=9600 PARITY=N data=8 stop=1 xon=off"); $fp =fopen("/dev/cu.usbmodem3d11", "w"); while (true){ $i = (4); fwrite($fp, chr($i)); sleep(3); } $i = $i; fclose($fp); ?>Arduino:
int ledPin = 13;
int usbnumber = 0;
void setup() {
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
if (Serial.available() > 0) {
usbnumber = Serial.read();
Serial.println(usbnumber);
}
if (usbnumber == 1){
digitalWrite(ledPin, HIGH);
delay(300);
}else{
digitalWrite(ledPin, LOW);
delay(1000);
}
usbnumber = 0;
}
I hope somone can help. Thanks!