gordywills/smart-lcd

一个基于PHP的HD44780 LCD显示器驱动程序接口

dev-master 2018-04-08 14:38 UTC

This package is auto-updated.

Last update: 2024-09-22 17:48:52 UTC


README

简介

当我用我的RPi连接一个16x2 LCD显示器模块时,我发现了很多Python库,但没有PHP的,所以我决定自己写一个。这里展示的是基本的使用模型。我在主要的Worker类中公开了两个函数,允许你发送DateTime对象以显示日期和时间,或者只显示任意文本的两行字符串。我没有实现从HD44780读取或自定义字符写入函数。

16x2 LCD Display

资源

在准备代码的过程中,我使用了一些资源来学习HD44780驱动程序的行为。在源代码的LCD\Resources文件夹中,你可以找到驱动数据表和一些教程。你还可以找到urls.md,其中包含一些在线链接。

安装

首选使用composer

命令行:php composer.phar require "gordywills/smart-lcd":"dev-master"

composer.json

{
    "require": {
        "gordywills/smart-lcd": "dev-master"
    }
}

使用

注意:为了使GPIO正确运行,此脚本必须以root或使用sudo运行

使用工厂实例化一个新的实例

<?php
use LCD\WorkerFactory;
$LCD = WorkerFactory::create();

然后使用公开的方法显示字符串

<?php
$firstLine = 'This is a 16x2';
$secondLine = 'LCD Display';
$LCD->displayMessages($firstLine,$secondLine);

公开方法

  • public function displayTime(\DateTime $dateTime) 在日期时间对象中显示日期和时间
  • public function displayMessages($line1, $line2) 在1和2行显示文本(每行最多40个字符)
  • public function displayDoubleHeightTime(\DateTime $dateTime) 使用双高字符显示时间(依赖于使用默认的可编程字符)

示例

#!/usr/bin/env php
<?php

//initiate the composer autoload
require 'vendor/autoload.php';

//Dependencies
use LCD\WorkerFactory;

$LCD = WorkerFactory::create();
$firstLine = 'This is a 16x2';
$secondLine = 'LCD Display';
$firstLongLine = 'This message is very long.';
$secondLongLine = 'It causes the display to scroll.';
while (true) {
    $LCD->displayTime(new DateTime());
    sleep(15);
    $LCD->displayMessages($firstLine,$secondLine);
    sleep (15);
    $LCD->displayTime(new DateTime());
    sleep(15);
    $LCD->displayMessages($firstLongLine,$secondLongLine);
    sleep (15);
}

引脚分配

默认引脚是

<?php
$pins = [
    'D7'             => 22,
    'D6'             => 21,
    'D5'             => 17,
    'D4'             => 23,
    'D3'             => 20,
    'D2'             => 13,
    'D1'             => 19,
    'D0'             => 26,
    'RegisterSelect' => 25,
    'EnablePin'      => 24,
];

如果你想使用不同的引脚,则将pins.config.php.dist复制到你的选择位置作为pins.config.php,并将其传递给WorkerFactory

<?php
use LCD\WorkerFactory;
$LCD = WorkerFactory::create('pins.config.php');

自定义字符

可以编程8个自定义字符。默认情况下,此库将它们作为可以用于在显示中显示双高数字的符号,并在公开函数public function displayDoubleHeightTime(\DateTime $dateTime)中使用这些符号。

如果你希望创建自己的自定义字符,请将programmableCharacters.config.php.dist复制到你的选择位置作为programmableCharacters.config.php,并编辑内容,使得每行中的0是关闭的,1是打开的,每行8个字符。注意,前3位总是0,最后5位是绘制每行像素的位(参见Julyan llett - "How to use intelligent L.C.D.s - Part One"中的图5,了解更多细节)。

<?php
use LCD\WorkerFactory;
$LCD = WorkerFactory::create('pins.config.php', 'programmableCharacters.config.php');

要显示你的自定义字符,请向你的显示字符串添加<<1>>以显示字符1。例如:$message = "This is custom Char 7: <<7>>";

扩展

因为我不需要它,所以我还没有实现读取忙信号函数。如果你需要它,那么它们应该很容易添加到LCD\Instruction\CommandLCD\Instruction\Content中。