Projeto Controle PHP7
Criando o circuito do Controle
=====================================================
Código do projeto de Controle
Código do Arduino
int led8 = 2;
int led6 = 4;
int led4 = 6;
int led2 = 8;
void setup() {
Serial.begin(9600);
pinMode(led2, OUTPUT);
pinMode(led4, OUTPUT);
pinMode(led6, OUTPUT);
pinMode(led8, OUTPUT);
}
void loop()
{
char caracter;
caracter = Serial.read();
//se pressionado "a" liga led 2
if(caracter == 'a')
{
digitalWrite(led2, HIGH);
}
else
//Se pressionado "b" liga led 4
if(caracter == 'b')
{
digitalWrite(led4, HIGH);
}
else
//S pressionado "c" liga led 6
if(caracter == 'c')
{
digitalWrite(led6, HIGH);
}
else
//Se pressionado "d" liga led 8
if(caracter == 'd')
{
digitalWrite(led8, HIGH);
}
delay(1000);
}
Código de controle de comunicação em PHP7
<?php
$port = fopen("COM3", "w");
if ($_POST['estado']=="a")
{
echo "Ligou Led 1";
fwrite($port, "a");
}
if ($_POST['estado']=="b")
{
echo "Ligou Led 2";
fwrite($port, "b");
}
if ($_POST['estado']=="c")
{
echo "Ligou Led 3";
fwrite($port, "c");
}
if ($_POST['estado']=="d")
{
echo "Ligou Led 4";
fwrite($port, "d");
}
fclose($port);
?>
Página index.php
<html>
<head>
<meta http-equiv="Content-Language" content="pt-br">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Controle de Leds com Arduino</title>
</head>
<body>
<div align="center">
<table border="0" width="15%" cellpadding="0">
<tr></tr><tr><td>
<!--------------POST DO BOTAO LIGAR Led 1------------------------>
<form method="POST" action="arduino.php">
<p>
<input type="hidden" value="a" name="estado" >
<input type="submit" value="Ligar Led 1" name="a">
</p>
</form>
</td></tr><tr>
<!--------------POST DO BOTAO LIGAR Led2--------------------------->
<form method="POST" action="arduino.php">
<input type="hidden" value="b" name="estado" >
<td><input type="submit" value="Ligar Led 2" name="b">
</td>
</form>
</tr><tr><td>
<!-------------POST DO BOTAO LIGAR Led3------------------------->
<form method="POST" action="arduino.php">
<p>
<input type="hidden" value="c" name="estado" >
<input type="submit" value="Ligar Led 3" name="c">
</p>
</form>
</td></tr><tr>
<!------------POST DO BOTAO LIGAR Led4--------------------------->
<form method="POST" action="arduino.php">
<input type="hidden" value="d" name="estado" >
<td><input type="submit" value="Ligar Led 4" name="d">
</td>
</form>
</tr>
</tr>
</table>
</div>
</body>
</html>