Delphi控制Arduino紅綠燈與LCD

最近開始學著使用Arduino來做一些簡單的控制,對於只學商完全不懂電子、電路的人真的是一大福音!很快就能上手~
當然最終還是希望能與電腦做搭配控制,寫了個簡單的程式控制紅、黃、綠燈,並在LCD液晶顯示器顯示目前亮的是Red/Yellow/Blue LED.

#include <Wire.h> 
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 16, 2);
int redled =10; 
int yellowled =7; 
int blueled =4; 
void setup()
{
  Serial.begin(9600);
  pinMode(redled, OUTPUT);
  pinMode(yellowled, OUTPUT);
  pinMode(blueled, OUTPUT); 
  lcd.begin();
  lcd.clear();
  lcd.backlight();
  lcd.print("Lin Shou Shan");
        
}

void loop()
{
  char s;
  if (Serial.available()>0){
    s=(char) Serial.read();
    lcd.clear();
      digitalWrite(redled, LOW);
      digitalWrite(yellowled, LOW);
      digitalWrite(blueled, LOW);       
    if(s=='R'){
      digitalWrite(redled, HIGH);     
      lcd.print("Red LED");
    }
    if(s=='Y'){
      digitalWrite(yellowled, HIGH);     
      lcd.print("Yellow LED");      
    }
    if(s=='B'){
      digitalWrite(blueled, HIGH);      
      lcd.print("Blue LED");        
    } 
  }
}
procedure TForm1.Button1Click(Sender: TObject);
begin
  Comm1.StopComm;
  COMM1.CommName := 'COM6';
  COMM1.StartComm;
end;

procedure TForm1.Button2Click(Sender: TObject);
var s:AnsiString;
begin
  s:='';
  s:= TButton(Sender).Hint;
  Comm1.WriteCommData(PAnsiChar(s),Length(s)); //送出指令給遠端
end;