arduino.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /**
  3. * Fun with Binary - a fun way of introducing binary
  4. * Copyright (C) 2018, Diogo Cordeiro.
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. *
  19. */
  20. class arduino
  21. {
  22. /*
  23. * ==Warning==
  24. * You must add www-data to dialout group
  25. * for serial port communication to work!
  26. */
  27. // Arduino related
  28. protected $comPort = "/dev/ttyACM0";
  29. /**
  30. * Resets Arduino
  31. */
  32. public function reset()
  33. {
  34. // Sends reset command to Arduino
  35. $fp = fopen($this->comPort, "wb");
  36. fwrite($fp, 9); // 9 is the Reset Byte
  37. }
  38. /**
  39. * Send a byte to Arduino
  40. */
  41. public function send($byte)
  42. {
  43. // Updates Arduino output
  44. $fp = fopen($this->comPort, "wb");
  45. fwrite($fp, (int)$byte);
  46. }
  47. }