承接 dept-of-scrapyard-robotics/hc-sr04 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

dept-of-scrapyard-robotics/hc-sr04

Composer 安装命令:

composer require dept-of-scrapyard-robotics/hc-sr04

包简介

Drive HC-SR04 ultrasonic distance sensors over GPIO with PHP

README 文档

README

Native (POSIX) driver. (Single Board Computers)

use DeptOfScrapyardRobotics\Sensors\HCSR04;
use RealityInterface\Sensors\Enums\LengthUnit;

$native_sensor = HCSR04::connection('native', 0)
    ->echo(22)
    ->trig(24)
    ->create();
     

// Trigger a Pulse
$native_sensor->fire();

// Pull a reading
$distance = $native_sensor->distance(LengthUnit::CM);  

USB (MPSSE) driver. (Linux and MacOS)

Not Recommended or Supported.

Alternative Usage

Using Through the Sensor Library (as an Ultrasonic Distance Sensor)

use RealityInterface\Sensors\Enums\LengthUnit;
use DeptOfScrapyardRobotics\Sensors\HCSR04\HCSR04;
use RealityInterface\Sensors\Applied\Distance\UltrasonicDistanceSensor;

$hc_sr04 = HCSR04::connection('native', 0)
    ->echo(22)
    ->trig(24)
    ->create();

$sensor = UltrasonicDistanceSensor::as($hc_sr04)->units(LengthUnit::FT);

// Get a distance measurement
$sensor->pulse();
$feet_away = $sensor->readDistance();

// Get a measurement object
$event = $sensor->measure();

Using Through the Sensor Library (as a Generic Distance Sensor)

use RealityInterface\Sensors\Enums\LengthUnit;
use DeptOfScrapyardRobotics\Sensors\HCSR04\HCSR04;
use RealityInterface\Sensors\Applied\Distance\DistanceSensor;

$hc_sr04 = HCSR04::connection('native', 0)
    ->echo(22)
    ->trig(24)
    ->create();

$sensor = DistanceSensor::as($hc_sr04)->units(LengthUnit::FT);

// Get a distance measurement
$feet_away = $sensor->getDistance();

// Get a measurement object
$event = $sensor->measure();

Using Through the Sensor Framework (with an autoloaded config) (as an Ultrasonic Distance Sensor)

use RealityInterface\Sensors\Applied\Distance\UltrasonicDistanceSensor;

$sensor = UltrasonicDistanceSensor::using('hc-sr04')

// Get a distance measurement
$sensor->pulse();
$feet_away = $sensor->readDistance();

// Get a measurement object
$event = $sensor->measure();

Using Through the Sensor Framework (with an autoloaded config) (as a Generic Distance Sensor)

use RealityInterface\Sensors\Applied\Distance\DistanceSensor;

$sensor = DistanceSensor::using('hc-sr04')

// Get a distance measurement
$sensor->pulse();
$feet_away = $sensor->readDistance();

// Get a measurement object
$event = $sensor->measure();

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-06-13

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固