Created
June 5, 2016 00:07
-
-
Save igoralves1/208f5ac2b94add4d1aacdfc8d7940c65 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http://888hack.com/2016/06/04/integracao-arduino-php-pelo-ubuntu/ | |
CÓDIGO PHP | |
<?php | |
$porta = '/dev/ ttyACM0'; | |
$numeroLido = $_REQUEST["numero"]; | |
echo "Numero lido: $numeroLido"; | |
$conexaoArduino = fopen($porta, 'w'); | |
fwrite($conexaoArduino, $_REQUEST["numero"]); | |
fclose($conexaoArduino); | |
?> | |
CÓDIGO ARDUINO UNO | |
int ledPin = 13 ; | |
int numero = -5; | |
void setup(){ | |
pinMode(ledPin, OUTPUT); | |
Serial.begin(9600); | |
} | |
void loop(){ | |
if(Serial.available() > 0 ){ | |
numero = Serial.read(); | |
} | |
if(numero>0){ | |
if(numero == '1'){ | |
digitalWrite(ledPin, HIGH); | |
delay(2000); | |
} | |
else if(numero == '0'){ | |
digitalWrite(ledPin, LOW); | |
delay(2000); | |
} | |
} | |
} | |
ANTES DE TUDO TEMOS QUE DAR PERMISSÕES AS PASTAS E A PORTA USB | |
chmod 666 ou chmod 777 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment