i want to turn on led pin on arduino mega using php code. i’m using phpserial in order to communicate with the arduino board, but instead of turning on the new led, it turns on the last led.
below is my code, based on this thread
anyone have any clue how can i make it work correctly?
BTW, the arduino part of the code works when i upload it to arduino IDE.
<?php
include 'PhpSerial.php';
class ArduinoCommunication
{
private $serial;
public function __construct($port, $baudRate)
{
$this->serial = new PhpSerial();
$this->serial->deviceSet($port);
$this->serial->confBaudRate($baudRate);
$this->serial->confParity("none");
$this->serial->confCharacterLength(8);
$this->serial->confStopBits(1);
$this->serial->deviceOpen("w");
$this->serial->deviceOpen();
}
public function turnOnLED()
{
$this->sendCommand(1);
}
public function turnOffLED()
{
$this->sendCommand('0');
}
private function sendCommand($command)
{
$this->serial->sendMessage($command);
}
public function closeConnection()
{
$this->serial->deviceClose();
}
}
$arduinoPort = 'COM3';
$baudRate = 9600;
$arduino = new ArduinoCommunication($arduinoPort, $baudRate);
$arduino->turnOnLED();
sleep(2); // Wait for 2 seconds
$arduino->closeConnection();
?>
byte led = A5;
void setup() {
pinMode(led, OUTPUT);
Serial.begin(9600);
digitalWrite(led,HIGH);
delay(500);
digitalWrite(led,LOW);
delay(500);
digitalWrite(led,HIGH);
delay(500);
digitalWrite(led,LOW);
}
void loop() {
}