clear all

clc
a=arduino('COM9');
a.pinMode(9,'output');
c=1;
nm=100;
figure('name','Contro ON/OFF');
title('Contro ON/OFF de luminosidad');
xlabel('Tiempo');
ylabel('Valor');
grid off;
hold on;
while c<=nm
ylim([0 100]);
xlim([c-100 c+50]);
val=a.analogRead(0);
val=100*val/1024
if(val >=3)
a.digitalWrite(9,1);
else
a.digitalWrite(9,0);
end
plot(c,val,'.G','MarkerSize',12);
plot(c,9,'.r','MarkerSize',12);
drawnow
c=c+1;
nm=nm+1;
end