0

Hi I am a newbie on this kind of projects and now I am starting with a project where I control 3 LEDs from web.It works to control each one, but now I want to make something like traffic lights, meaning on a start button each led to be on for 2 seconds at a time, until I press a stop button.That works too but the problem is I can't get it how to stop them. I am using wiringPi library with php (also new to this language). This is the html part:

<html>
<head>
<title>Control LED with Raspberry Pi using Apache Webserver </title>
</head>
   <body>
   <center><h1>Control LED from web using Apache Webserver</h1>
     <form method="get" action="index.php">
        <input class ="red" type="submit"  value="Turn Red LED On" name="ron">
    <input class=" red" type="submit"  value="Turn Red LED Off" name="roff">
    <br /> <br />
    <input class="yellow" type="submit" value="Turn Yellow LED On" name="yon">
    <input class="yellow" type="submit" value="Turn Yellow LED Off" name="yoff">
        <br /> <br />
    <input class="green" type="submit" value="Turn Green LED On" name="gon">
    <input class="green" type="submit" value="Turn Green LED Off" name="goff">
    <br /> <br />   
 <input class="lights" type="submit" value="Traffic Lights On" name="tlstart">
    <input class="lights" type="submit" value="Traffic Lights Off" name="tlstop">
 </form>
   </center>

And here is the php code

<?php
shell_exec("gpio -g mode 17 out");
shell_exec("gpio -g mode 22 out");
shell_exec("gpio -g mode 27 out");
$ok = 1;
if(isset($_GET['roff']))
    {
    shell_exec("gpio -g write 17 0");
    }
    else if(isset($_GET['ron']))
    {
            shell_exec("gpio -g write 17 1");
}
else if(isset($_GET['yon']))
{
    shell_exec("gpio -g write 27 1");
}
else if(isset($_GET['yoff']))
{
    shell_exec("gpio -g write 27 0");
}
else if(isset($_GET['gon']))
{
    shell_exec("gpio -g write 22 1");
}
else if(isset($_GET['goff']))
{
    shell_exec("gpio -g write 22 0");
}
else if(isset($_GET['tlstart']))
{

    while($ok == 1)
    {
    shell_exec("gpio -g write 17 1");
    sleep(2);
    shell_exec("gpio -g write 17 0");
    shell_exec("gpio -g write 27 1");
    sleep(2);
    shell_exec("gpio -g write 27 0");
    shell_exec("gpio -g write 22 1");
    sleep(2);
    shell_exec("gpio -g write 22 0");
    if(isset($_GET['tlstop']))
    {
        $ok = 0;
    }
    }
    shell_exec("gpio -g write 17 0");
    shell_exec("gpio -g write 27 0");
    shell_exec("gpio -g write 22 0");
}
?>
</body>
</html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.