-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLedExample.php
More file actions
34 lines (30 loc) · 1.03 KB
/
Copy pathLedExample.php
File metadata and controls
34 lines (30 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
require_once __DIR__ . '/Defines/pinMode.php';
require_once __DIR__ . '/Adapters/USBConnecting.php';
require_once __DIR__ . '/Hardware/HardwareFactory.php';
use PIOT\USBConnecting\USBConnectingFactory;
use PIOT\Hardware\Factory\HardwareFactory;
try {
$usbFactory = new USBConnectingFactory();
$connect = $usbFactory->create(true);
// change your number com ( USB COM connecting ), at here I have COM3
$connect->setSerial(3);
// change BAUD like hardware
$connect->setBAUD(9600);
// Delay time for read data from device
$connect->setReceiveDelay(3);
$hardwareFactory = new HardwareFactory();
$led = $hardwareFactory->createLed();
$led->high();
$connect->setMessage($led->currentMode());
$connect->send();
echo $led->recieve($connect->receive()) . ' | ';
sleep(3);
$led->low();
$connect->setMessage($led->currentMode());
$connect->send();
echo $led->recieve($connect->receive()) . ' | ';
sleep(3);
} catch (\Exception $e) {
echo "Error: " . $e->getMessage();
}