fork download
  1. #define ANALOG_PIN 0
  2.  
  3. void setup()
  4. {
  5. Serial.begin(9600);
  6. }
  7.  
  8. void loop()
  9. {
  10. if (Serial.available() > 0) {
  11. if (Serial.read() == '1')
  12. Serial.print(analogRead(ANALOG_PIN), DEC);
  13. }
  14. }
  15. //E o do PHP:
  16.  
  17. <?php
  18. $port = fopen('/dev/ttyUSB0', 'w+');
  19. sleep(2);
  20. fwrite($port, '1');
  21. sleep(1);
  22. echo fgets($port);
  23. fclose($port);
  24. ?>
Success #stdin #stdout #stderr 0.02s 25756KB
stdin
Standard input is empty
stdout
#define ANALOG_PIN 0

void setup()
{
  Serial.begin(9600);
}

void loop()
{
  if (Serial.available() > 0) {
    if (Serial.read() == '1')
      Serial.print(analogRead(ANALOG_PIN), DEC);
  }
}
//E o do PHP:

stderr
PHP Warning:  fopen(/dev/ttyUSB0): failed to open stream: Permission denied in /home/LBUImH/prog.php on line 18
PHP Warning:  fwrite() expects parameter 1 to be resource, bool given in /home/LBUImH/prog.php on line 20
PHP Warning:  fgets() expects parameter 1 to be resource, bool given in /home/LBUImH/prog.php on line 22
PHP Warning:  fclose() expects parameter 1 to be resource, bool given in /home/LBUImH/prog.php on line 23