danjohnson95 / pinout
此包的最新版本(dev-main)没有可用的许可信息。
dev-main
2024-09-24 17:15 UTC
Requires
- illuminate/console: ^10.10.0|^11.0
- illuminate/support: ^10.10.0|^11.0
- symfony/process: ^6.4|^7.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.4
- larastan/larastan: ^2.7.0
- mockery/mockery: ^1.4
- orchestra/testbench: ^8.0|^9.0
- pestphp/pest: ^1.20|^2.0
- phpstan/phpstan-phpunit: ^1.1
This package is auto-updated.
Last update: 2024-09-24 17:15:35 UTC
README
Pinout
使用 Pinout 将您的 Laravel 应用程序连接到物理世界,在这里代码与电路相遇。硬件与网络,无缝连接 🤝
特性
在支持的硬件上运行 Laravel 应用程序时,您可以
- 获取任何 GPIO 引脚的当前状态
- 设置任何 GPIO 引脚的状态
这些基本特性打开了从简单的 LED 控制到复杂机器人学等无限可能。
此外,使用包含的驱动程序,您还可以
- 在七段显示屏上显示数字
- 在 16x2 LCD 显示屏上显示任何内容
硬件支持
目前,Pinout 支持以下硬件
入门
将包安装到现有的 Laravel 项目中
composer require danjohnson95/pinout
如果您使用的是 Laravel 11 或更高版本,则包将自动发现。如果您使用的是更早的版本,您需要将服务提供程序添加到您的 config/app.php
文件中
'providers' => [ // ... DanJohnson95\Pinout\ServiceProvider::class, // ... ],
使用方法
Pinout
门面
此包允许您使用 Pinout
门面与硬件交互,并且还附带了一些 Artisan 命令以方便使用。
使用 pin
方法获取特定引脚的 Pin
实例
$pin = \DanJohnson95\Pinout\Pinout::pin(13);
参数是 GPIO 引脚号的引用。(使用的是 BCM 引脚号,而不是物理引脚号。)请参阅 pinout.xyz 以获得视觉参考。
Pin
实例有与引脚交互的方法
$pin->isOn(); // Whether the pin is "on" (high) $pin->isOff(); // Whether the pin is "off" (low) $pin->turnOn(); // Set the pin to "on" $pin->turnOff(); // Set the pin to "off" $pin->makeInput(); // Set the pin to input mode $pin->makeOutput(); // Set the pin to output mode
门面还有一个 pins
方法,可以一次拉取多个引脚
$pins = \DanJohnson95\Pinout\Pinout::pins(13, 19, 26);
这将返回一个 PinCollection
实例,它是一组 Pin
实例。
PinCollection
也附带了一些实用的方法
$pins->turnOn(); // Turns all pins on in the collection $pins->turnOff(); // Turns all pins off in the collection $pins->makeInput(); // Sets all pins to input mode $pins->makeOutput(); // Sets all pins to output mode $pins->findByPinNumber(13); // Returns the Pin instance for the given pin number $pins->whereIsOn(); // Returns a collection of pins that are on $pins->whereIsOff(); // Returns a collection of pins that are off
Artisan 命令
此包附带了一些 Artisan 命令,方便使用
php artisan pinout:pin 13
这将返回引脚的当前状态。
php artisan pinout:on 13
这将打开引脚 13。
php artisan pinout:off 13
这将关闭引脚 13。
路线图
- 硬件中断
- I2C
- SPI