I have a code that allows me to control a led from my pc to a microcontroller.The led goes on and off.
The problem:
-When I press the "Light On" button: It takes 2 seconds to light on.
-When I press the "Light Off" button: It goes off right away.
I would understand the 2 seconds because I put a sleep(2), but why is the light goes off with no delay.How can I get no delay on both side (I put ths 2 seconds sleep because deviceOpen reset the microcontroller and it takes about this time to be ready)
So, what I think I need to do: Make sur that the connection with the microcontroller get execute only one time.
Please help me. Thank you (all codes found online. all open source)
- Code: Select all
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Arduino Project 1: Serial LED Control</title>
</head>
<body>
<h1>Arduino Project 1: Serial LED Control</h1>
<p><a href="<?=$_SERVER['PHP_SELF'] . "?action=greenon" ?>">
Click here to turn the GREEN LED on.</a></p>
<p><a href="<?=$_SERVER['PHP_SELF'] . "?action=greenoff" ?>">
Click here to turn the GREEN LED off.</a></p>
</body>
</html>
<?php
include("php_serial.class.php");
$serial = new phpSerial();
$serial->deviceSet("/dev/ttyACM0");
$serial->confBaudRate(115200); //Baud rate: 9600
$serial->deviceOpen();
sleep(2) ;
if (isset($_GET['action'])) {
if ($_GET['action'] == "greenon") {
$serial->sendMessage("1");
} else if ($_GET['action'] == "greenoff") {
$serial->sendMessage("2");
}
$serial->deviceClose();
}
?>


