Translate

Interface Delphi 7 untuk Data 6 Grafik Realtime

 Interface Delphi 7 untuk Data 6 Grafik Realtime


      Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat software interface dengan menggunakan Delphi 7 untuk menampilkan 6 buah data dan grafik secara realtime berdasarkan input dari arduino menggunakan serial. untuk lebih jelasnya berikut adalah tampilan interface dan programnya.



a. Interface Delphi 7



unit TA;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls,strutils, TeeProcs, TeEngine, Chart, CPort, mmsystem,
  Series, Buttons;

type
  TForm1 = class(TForm)
    ComPort1: TComPort;
    GroupBox1: TGroupBox;
    Edit1: TEdit;
    Edit2: TEdit;
    Chart1: TChart;
    Shape1: TShape;
    Shape2: TShape;
    GroupBox2: TGroupBox;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Memo1: TMemo;
    Timer1: TTimer;
    Label7: TLabel;
    Label8: TLabel;
    BitBtn1: TBitBtn;
    Chart2: TChart;
    Series2: TFastLineSeries;
    Label5: TLabel;
    Timer2: TTimer;
    Chart3: TChart;
    Series3: TFastLineSeries;
    Chart4: TChart;
    Chart5: TChart;
    Chart6: TChart;
    Series4: TFastLineSeries;
    Series5: TFastLineSeries;
    Series6: TFastLineSeries;
    Edit5: TEdit;
    Edit6: TEdit;
    Edit7: TEdit;
    Edit8: TEdit;
    Series1: TFastLineSeries;
    Timer3: TTimer;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label6: TLabel;
    Label9: TLabel;
    procedure ComPort1RxChar(Sender: TObject; Count: Integer);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
    procedure Timer2Timer(Sender: TObject);
    procedure Timer3Timer(Sender: TObject);

  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.ComPort1RxChar(Sender: TObject; Count: Integer);
var buff:string;
begin
comport1.ReadStr(buff,count);
memo1.Text:=memo1.Text+buff;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
comport1.ShowSetupDialog;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
Timer2.Enabled := True;
Timer3.Enabled := True;
if button2.Caption='Connect' then
   begin
   button2.Caption:='Disconnect';
   comport1.Open;
   end
else if button2.Caption='Disconnect' then
   begin
   button2.Caption:='Connect';
   comport1.Close;
   end;

end;

procedure TForm1.Button3Click(Sender: TObject);
begin
Edit1.Color:=clwhite;
Edit2.Color:=clwhite;
edit1.text:='';
edit2.text:='';
memo1.Text:='';
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
close;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
ThousandSeparator:=',';
DecimalSeparator:='.';
end;


procedure TForm1.Timer1Timer(Sender: TObject);
begin
label7.Caption:='Date  '+ FormatdateTime('d/mm/yyyy',Date);
label8.Caption:='Time  '+ FormatDateTime('hh:nn:ss',Time);
end;

procedure TForm1.BitBtn1Click(Sender: TObject);
begin
close;
end;

procedure TForm1.Timer2Timer(Sender: TObject);
var ruang,kulit,ruangx,kulitx,ruangy,kulity:double;
    rin,kin,rinx,kinx,riny,kiny:string;

begin

  riny:=memo1.Lines[memo1.Lines.count-6];
  kiny:=memo1.Lines[memo1.Lines.count-5];
  rinx:=memo1.Lines[memo1.Lines.count-4];
  kinx:=memo1.Lines[memo1.Lines.count-3];
  rin:=memo1.Lines[memo1.Lines.count-2];
  kin:=memo1.Lines[memo1.Lines.count-1];

  if rightstr(riny,1)= 'a' then
     begin
     edit1.Text:=leftstr(rin,length(rin)-1);
     ruang:=strtofloat(edit1.text);
     Series1.Add(ruang,'',clred) ;
     end;
  if rightstr(kiny,1)='b' then
     begin
     edit2.Text:=leftstr(kin,length(kin)-1);
     kulit:=strtofloat(edit2.text);
     Series2.Add(kulit,'',clgreen) ;
     end;

  if rightstr(rinx,1)= 'c' then
     begin
     edit5.Text:=leftstr(rinx,length(rinx)-1);
     ruangx:=strtofloat(edit5.text);
     Series3.Add(ruangx,'',clred) ;
     end;
  if rightstr(kinx,1)='d' then
     begin
     edit6.Text:=leftstr(kinx,length(kinx)-1);
     kulitx:=strtofloat(edit6.text);
     Series4.Add(kulitx,'',clgreen) ;
     end;

  if rightstr(rin,1)= 'e' then
     begin
     edit7.Text:=leftstr(riny,length(riny)-1);
     ruangy:=strtofloat(edit7.text);
     Series5.Add(ruangy,'',clred) ;
     end;
  if rightstr(kin,1)='f' then
     begin
     edit8.Text:=leftstr(kiny,length(kiny)-1);
     kulity:=strtofloat(edit8.text);
     Series6.Add(kulity,'',clgreen) ;
     end;
end;

procedure TForm1.Timer3Timer(Sender: TObject);
var
  F: TextFile;
begin
  AssignFile(F, 'D:\recordku.txt');
  Append(F);
  WriteLn(F, '======================================');
  WriteLn(F, 'Tanggal = ',label7.Caption);
  WriteLn(F, 'Jam     = ',label8.Caption);
  WriteLn(F, '======================================');

  WriteLn(F, 'Data A : ',Edit1.Text);
  WriteLn(F, 'Data B  : ',Edit2.Text);
  WriteLn(F, 'Data C  : ',Edit3.Text);
  WriteLn(F, 'Data D : ',Edit4.Text);
  WriteLn(F, 'Data E : ',Edit5.Text);
  WriteLn(F, 'Data F : ',Edit6.Text);

  CloseFile(F);
end;

end.




b. Program Arduino IDE

void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop() {
  // read the input on analog pin 0:
  int sensorValue1 = analogRead(A0);
  int sensorValue2 = analogRead(A1);
  int sensorValue3 = analogRead(A2);
  int sensorValue4 = analogRead(A3);
  int sensorValue5 = analogRead(A4);
  int sensorValue6 = analogRead(A5);
  // print out the value you read:
  Serial.print(sensorValue1),Serial.println ('a');
  Serial.print(sensorValue2),Serial.println ('b');
  Serial.print(sensorValue3),Serial.println ('c');
  Serial.print(sensorValue4),Serial.println ('d');
  Serial.print(sensorValue5),Serial.println ('e');
  Serial.print(sensorValue6),Serial.println ('f');
  delay(1000);        // delay in between reads for stability
}




c. VIDEO HASILNYA






No comments:

Post a Comment