deviceSet("/dev/tty.usbserial-A4001nU7");
//Set the serial port parameters. The documentation says 9600 8-N-1, so
$serial->confBaudRate(9600); //Baud rate: 9600
$serial->confParity("none"); //Parity (this is the "N" in "8-N-1")
$serial->confCharacterLength(8); //Character length (this is the "8" in "8-N-1")
$serial->confStopBits(1); //Stop bits (this is the "1" in "8-N-1")
// Ask Arduino if the LED is ON or OFF
$serial->deviceOpen();
$serial->sendMessage(chr(10)); // start transmission
$serial->sendMessage("2");
$serial->sendMessage(chr(13)); // end transmission
$read = $serial->readPort(); // waiting for reply
$led1 = $read;
$led1 = (int)$led1;
//We're done, so close the serial port again
$serial->deviceClose();
// Add some xhtml and CSS to display an ON/OFF button
echo "";
echo "";
echo "
";
echo "";
echo "Toggle LED on Arduino";
echo "";
echo "";
echo "";
// if LED is OFF (0), then display the ON button
if ($led1 === 0) {
echo "
";
}
// if LED is ON (1), then display the OFF button
if ($led1 === 1) {
echo "
";
}
echo "";
echo "";
//check the GET action var to see if an action is to be performed
if (isset($_GET['action'])) {
//Action required
//Now we "open" the serial port so we can write to it
$serial->deviceOpen();
$serial->sendMessage(chr(10)); // start Transmission
//Do the request
if ($_GET['action'] == "on") {
echo "
"; // toggle the button
$serial->sendMessage("1"); // turn LED ON
} else if ($_GET['action'] == "off") {
echo "
"; // toggle the button
$serial->sendMessage("0"); // turn LED OFF
}
$serial->sendMessage(chr(13)); // end Transmission
//We're done, so close the serial port again
$serial->deviceClose();
}
?>
Here's the last version I used I think they are the same but I'm not 100% sure
deviceSet("/dev/tty.usbserial-A4001nU7");
//Set the serial port parameters. The documentation says 9600 8-N-1, so
$serial->confBaudRate(9600); //Baud rate: 9600
$serial->confParity("none"); //Parity (this is the "N" in "8-N-1")
$serial->confCharacterLength(8); //Character length (this is the "8" in "8-N-1")
$serial->confStopBits(1); //Stop bits (this is the "1" in "8-N-1")
// Ask Arduino if the LED is ON or OFF
$serial->deviceOpen();
$serial->sendMessage(chr(10)); // start transmission
$serial->sendMessage("2");
$serial->sendMessage(chr(13)); // end transmission
$read = $serial->readPort(); // waiting for reply
$led1 = $read;
$led1 = (int)$led1;
//We're done, so close the serial port again
$serial->deviceClose();
// Add some xhtml and CSS to display an ON/OFF button
echo "";
echo "";
echo "";
echo "";
echo "Toggle LED on Arduino";
echo "";
echo "";
echo "";
// if LED is OFF (0), then display the ON button
if ($led1 === 0) {
echo "
";
}
// if LED is ON (1), then display the OFF button
if ($led1 === 1) {
echo "
";
}
echo "";
echo "";
//check the GET action var to see if an action is to be performed
if (isset($_GET['action'])) {
//Action required
//Now we "open" the serial port so we can write to it
$serial->deviceOpen();
$serial->sendMessage(chr(10)); // start Transmission
//Do the request
if ($_GET['action'] == "on") {
echo "
"; // toggle the button
$serial->sendMessage("1"); // turn LED ON
} else if ($_GET['action'] == "off") {
echo "
"; // toggle the button
$serial->sendMessage("0"); // turn LED OFF
}
$serial->sendMessage(chr(13)); // end Transmission
//We're done, so close the serial port again
$serial->deviceClose();
}
?>