You are on page 1of 2

clc

clear all
close all
delete(instrfind({'Port'},{'COM3'}));
s=serial('COM4','BaudRate',9600,'Terminator','CR/LF');
warning('off','MATLAB:serial:fscanf:unsuccessfulRead');
fopen(s);
TRIANGULO =[0,4,-4,0; 4,-3,-3,4; 1,1,1,1];
while (true)
pause(0.01)
A=fscanf(s,'%d,%d,%d');
V=A(1)*5/1024;
Voltaje=V;
if A(2)== 0 && A(3)==1
x=[0 4 -4 0];
z=[4 -3 -3 4];
Ma= [x(1,1) x(1,2) x(1,3) x(1,4);z(1,1) z(1,2) z(1,3)
z(1,4);1 1 1 1];
grados=Voltaje/0.0138;
n= grados;
y=[cos(n),-sin(n),0;sin(n),cos(n),0;0,0,1;0 0 0];
R=y*Ma;
a=[R(1,:),R(1,1)];
b=[R(2,:),R(2,1)];
hold on;
plot(a,b,'b')
plot(x,z,'r')
axis ([-10 10 -10 10]);
elseif A(2)== 1 && A(3)==0
x=[0 4 -4 0];
z=[4 -3 -3 4];
Ma= [x(1,1) x(1,2) x(1,3) x(1,4);z(1,1) z(1,2) z(1,3)
z(1,4);1 1 1 1];
h=Voltaje;
k=Voltaje;
y=[1,0,h;0,1,k;0,0,1];
R=y*Ma;
a=[R(1,:),R(1,1)];
b=[R(2,:),R(2,1)];
hold on;
plot(a,b,'b')
plot(x,z,'r')
axis ([-20 20 -20 20]);
elseif A(2)== 1 && A(3)==1

n= pi;
x=[0 4 -4 0];
z=[4 -3 -3 4];
Ma= [x(1,1) x(1,2) x(1,3) x(1,4);z(1,1) z(1,2) z(1,3)
z(1,4);1 1 1 1];
y=[cos(n),-sin(n),0;sin(n),cos(n),0;0,0,1;0 0 0];
R=y*Ma;
a=[R(1,:),R(1,1)];
b=[R(2,:),R(2,1)];
hold on;
plot(a,b,'b')
plot(x,z,'r')
axis ([-10 10 -10 10]);

end
end

fclose(s);
delete(s);
clear s

You might also like