centro = {300,200};
serial=DeviceOpen["Serial",{"/dev/ttyACM1","BaudRate"->115200}];
DeviceWriteBuffer[serial,"c"];
Pause[2]
img = Import["!raspistill -n -w 600 -h 400 -t 1 -o -","JPG"];
avgpv = Mean[PixelValuePositions[img,Red,.3]];
N[avgpv]
HighlightImage[img,{avgpv,centro},"HighlightColor"->Black ,Method->{"DiskMarkers",20}]
Do[
imgVarX = Import["!raspistill -n -w 600 -h 400 -t 1 -o -","JPG"];
avgpvVarX = Mean[PixelValuePositions[imgVarX,Red,.3]];
displaceX = 300 - Part[avgpvVarX,1];
If[displaceX > 0,DeviceWriteBuffer[serial,"a"];,DeviceWriteBuffer[serial,"d"];];
, 25]
Do[
imgVarY = Import["!raspistill -n -w 600 -h 400 -t 1 -o -","JPG"];
avgpvVarY = Mean[PixelValuePositions[imgVarY,Red,.3]];
displaceY = 200 - Part[avgpvVarY,2];
If[displaceY > 0,DeviceWriteBuffer[serial,"w"];,DeviceWriteBuffer[serial,"s"];];
, 15]
imgFin = Import["!raspistill -n -w 600 -h 400 -t 1 -o -","JPG"];
avgpvFin = Mean[PixelValuePositions[imgFin,Red,.3]];
N[avgpvFin]
HighlightImage[imgFin,{avgpvFin,centro},"HighlightColor"->Black ,Method->{"DiskMarkers",20}]