Clear x

f[x_,t_]:=Sin[x +t];

Needs["NETLink`"]
InstallNET[];


ser = NETNew["System.IO.Ports.SerialPort","COM8",9600]
ser@Open[]
Animate[Plot[f[x,t],{x,0,2Pi},PlotRange->{-1,1}]If[t==0||t==Pi||t==2Pi,ser@Write["D"],If[t==Pi/6||t==5Pi/6,ser@Write["E"],If[t==1Pi/3||t==2Pi/3,ser@Write["F"],If[t==Pi/2,ser@Write["G"],If[t==3Pi/2,ser@Write["A"],If[t==4Pi/3||t==5Pi/3,ser@Write["B"],If[t==7Pi/6||t==11Pi/6,ser@Write["C"]]]]]]]],{t,0,2Pi,Pi/6}]

Button["LED Off",ser@Write["H"]]
Button["Stop Program",ser@Close[]]