⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 traffic.pas

📁 交通灯演示delphi程序
💻 PAS
字号:
unit traffic;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls, SPComm, NeoNumLED;

type
  TForm1 = class(TForm)
    Red1: TImage;
    Green3: TImage;
    Red4: TImage;
    Green2: TImage;
    Yellow1: TImage;
    Green1: TImage;
    Yellow4: TImage;
    Green4: TImage;
    Yellow3: TImage;
    Red3: TImage;
    Yellow2: TImage;
    Red2: TImage;
    Comm1: TComm;
    NeoNumLED1: TNeoNumLED;
    NeoNumLED2: TNeoNumLED;
    NeoNumLED3: TNeoNumLED;
    NeoNumLED4: TNeoNumLED;
    procedure FormCreate(Sender: TObject);
    procedure Comm1ReceiveData(Sender: TObject; Buffer: Pointer;
      BufferLength: Word);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  flagsn:integer;
  flagew:integer;
implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
  comm1.StartComm;
  Green1.Visible:=true;
  Red1.Visible:=false;
  neonumled1.LightColor:=cllime;
  Yellow1.Visible:=false;

  Red2.Visible:=true;
  neonumled2.LightColor:=clred;
  Green2.Visible:=false;
  Yellow2.Visible:=false;
  

  Red3.Visible:=true;
  neonumled3.LightColor:=clred;
  Green3.Visible:=false;
  Yellow3.Visible:=false;
  

  Green4.Visible:=true;
  Red4.Visible:=false;
  neonumled4.LightColor:=cllime;
  Yellow4.Visible:=false;
end;

procedure TForm1.Comm1ReceiveData(Sender: TObject; Buffer: Pointer;
  BufferLength: Word);
var
  str:string;
begin
  SetLength(Str,BufferLength);  //将str的长度设置为bufferlength
  move(buffer^,pchar(@Str[1])^,bufferlength);
  begin
    neonumled1.Text:=Str[1]+str[2];
    neonumled4.Text:=str[1]+str[2];
    neonumled2.Text:=str[3]+str[4];
    neonumled3.Text:=str[3]+str[4];
   { if (str[3]+str[4]='00') then
      begin
        flagsn:=flagsn+1;
        if(flagsn=3) then
        flagsn:=0;
      end;
    if(flagsn=0)then
      begin
        Red2.Visible:=true;
        neonumled2.LightColor:=clred;
        Green2.Visible:=false;
        Yellow2.Visible:=false;

        Red3.Visible:=true;
        neonumled3.LightColor:=clred;
        Green3.Visible:=false;
        Yellow3.Visible:=false;
      end
    else if(flagsn=1)then
        begin
        Green2.Visible:=true;
        Red2.Visible:=false;
        neonumled2.LightColor:=cllime;
        Yellow2.Visible:=false;

        Green3.Visible:=true;
        Red3.Visible:=false;
        neonumled3.LightColor:=cllime;
        Yellow3.Visible:=false;
      end
    else if(flagsn=2)then
      begin
        Yellow2.Visible:=true;
        Red2.Visible:=false;
        Green2.Visible:=false;
        neonumled2.LightColor:=clyellow;

        Yellow3.Visible:=true;
        Red3.Visible:=false;
        Green3.Visible:=false;
        neonumled3.LightColor:=clyellow;
      end;
    if(str[1]+str[2]='00')then
      begin
        flagew:=flagew+1;
        if(flagew=3)then
          flagew:=0;
      end;
    if(flagew=0)then
      begin
        red1.Visible:=false;
        green1.Visible:=true;
        yellow1.Visible:=false;
        neonumled1.LightColor:=cllime;

        red4.Visible:=false;
        green4.Visible:=true;
        yellow4.Visible:=false;
        neonumled4.LightColor:=cllime;
      end;
    if(flagew=1)then
      begin
        red1.Visible:=false;
        green1.Visible:=false;
        yellow1.Visible:=true;
        neonumled1.LightColor:=clyellow;

        red4.Visible:=false;
        green4.Visible:=false;
        yellow4.Visible:=true;
        neonumled4.LightColor:=clyellow;
      end;
    if(flagew=2)then
      begin
        red1.Visible:=true;
        green1.Visible:=false;
        yellow1.Visible:=false;
        neonumled1.LightColor:=clred;

        red4.Visible:=true;
        green4.Visible:=false;
        yellow4.Visible:=false;
        neonumled4.LightColor:=clred;
      end; }

   if((str[3]+str[4])='30')
      or ((Red2.Visible=true) and (Green2.Visible=false) and (Yellow2.Visible=false) and ((str[3]+str[4])<>'00'))
      or ((Red2.Visible=false) and (Green2.Visible=false) and (Yellow2.Visible=true) and ((str[3]+str[4])='00'))
       then
      begin
        Red2.Visible:=true;
        neonumled2.LightColor:=clred;
        Green2.Visible:=false;
        Yellow2.Visible:=false;

        Red3.Visible:=true;
        neonumled3.LightColor:=clred;
        Green3.Visible:=false;
        Yellow3.Visible:=false;
      end;

    if((Red2.Visible=false) and (Green2.Visible=false) and (Yellow2.Visible=true) and ((str[3]+str[4])<>'00'))
      then
      begin
        Yellow2.Visible:=true;
        Red2.Visible:=false;
        Green2.Visible:=false;
        neonumled2.LightColor:=clyellow;

        Yellow3.Visible:=true;
        Red3.Visible:=false;
        Green3.Visible:=false;
        neonumled3.LightColor:=clyellow;
      end;

    if((Red2.Visible=false) and (Green2.Visible=true) and (Yellow2.Visible=false) and ((str[3]+str[4])<>'00'))
      then
      begin
        Green2.Visible:=true;
        Red2.Visible:=false;
        neonumled2.LightColor:=cllime;
        Yellow2.Visible:=false;

        Green3.Visible:=true;
        Red3.Visible:=false;
        neonumled3.LightColor:=cllime;
        Yellow3.Visible:=false;
      end;
    if ((Red2.Visible=false) and (Green2.Visible=true) and (Yellow2.Visible=false) and ((str[3]+str[4])='00'))then
      begin
        Red2.Visible:=false;
        neonumled2.LightColor:=cllime;
        Green2.Visible:=true;
        Yellow2.Visible:=false;

        Red3.Visible:=false;
        neonumled3.LightColor:=cllime;
        Green3.Visible:=true;
        Yellow3.Visible:=false;

        sleep(1000);
        Yellow2.Visible:=true;
        Red2.Visible:=false;
        Green2.Visible:=false;
        //neonumled2.LightColor:=clyellow;

        Yellow3.Visible:=true;
        Red3.Visible:=false;
        Green3.Visible:=false;
        //neonumled3.LightColor:=clyellow;
      end;
    if ((Red2.Visible=true) and (Green2.Visible=false) and (Yellow2.Visible=false) and ((str[3]+str[4])='00'))then
      begin
        Green2.Visible:=true;
        Red2.Visible:=false;
        neonumled2.LightColor:=clred;
        Yellow2.Visible:=false;

        Green3.Visible:=true;
        Red3.Visible:=false;
        neonumled3.LightColor:=clred;
        Yellow3.Visible:=false;

        sleep(1000);         //延时1s
        Red2.Visible:=false;
        //neonumled2.LightColor:=cllime;
        Green2.Visible:=true;
        Yellow2.Visible:=false;

        Red3.Visible:=false;
        //neonumled3.LightColor:=cllime;
        Green3.Visible:=true;
        Yellow3.Visible:=false;
      end;



    if((str[1]+str[2])='30')
      or ((Red1.Visible=true) and (Green1.Visible=false) and (Yellow1.Visible=false) and ((str[1]+str[2])<>'00'))
      or ((Red1.Visible=false) and (Green1.Visible=false) and (Yellow1.Visible=true) and ((str[1]+str[2])='00'))
       then
      begin
        Red1.Visible:=true;
        neonumled1.LightColor:=clred;
        Green1.Visible:=false;
        Yellow1.Visible:=false;

        Red4.Visible:=true;
        neonumled4.LightColor:=clred;
        Green4.Visible:=false;
        Yellow4.Visible:=false;
      end;

    if((Red1.Visible=false) and (Green1.Visible=false) and (Yellow1.Visible=true) and ((str[1]+str[2])<>'00'))
      then
      begin
        Yellow1.Visible:=true;
        Red1.Visible:=false;
        Green1.Visible:=false;
        neonumled1.LightColor:=clyellow;

        Yellow4.Visible:=true;
        Red4.Visible:=false;
        Green4.Visible:=false;
        neonumled4.LightColor:=clyellow;
      end;

    if((Red1.Visible=false) and (Green1.Visible=true) and (Yellow1.Visible=false) and ((str[1]+str[2])<>'00'))
      then
      begin
        Green1.Visible:=true;
        Red1.Visible:=false;
        neonumled1.LightColor:=cllime;
        Yellow1.Visible:=false;

        Green4.Visible:=true;
        Red4.Visible:=false;
        neonumled4.LightColor:=cllime;
        Yellow4.Visible:=false;
      end;
    if ((Red1.Visible=false) and (Green1.Visible=true) and (Yellow1.Visible=false) and ((str[1]+str[2])='00'))then
      begin
        Red1.Visible:=false;
        neonumled1.LightColor:=cllime;
        Green1.Visible:=true;
        Yellow1.Visible:=false;

        Red4.Visible:=false;
        neonumled4.LightColor:=cllime;
        Green4.Visible:=true;
        Yellow4.Visible:=false;

        sleep(1000);
        Yellow1.Visible:=true;
        Red1.Visible:=false;
        Green1.Visible:=false;
        //neonumled1.LightColor:=clyellow;

        Yellow4.Visible:=true;
        Red4.Visible:=false;
        Green4.Visible:=false;
        //neonumled4.LightColor:=clyellow;
      end;
    if ((Red1.Visible=true) and (Green1.Visible=false) and (Yellow1.Visible=false) and ((str[1]+str[2])='00'))then
      begin
        Green1.Visible:=true;
        Red1.Visible:=false;
        neonumled1.LightColor:=clred;
        Yellow1.Visible:=false;

        Green4.Visible:=true;
        Red4.Visible:=false;
        neonumled4.LightColor:=clred;
        Yellow4.Visible:=false;

        sleep(1000);         //延时1s
        Red1.Visible:=false;
        //neonumled1.LightColor:=cllime;
        Green1.Visible:=true;
        Yellow1.Visible:=false;

        Red4.Visible:=false;
        //neonumled4.LightColor:=cllime;
        Green4.Visible:=true;
        Yellow4.Visible:=false;
      end;
  end;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -