dio_out = digitalio('nidaq', 1);
addline(dio_out, 0:4, 0, 'Out');

putvalue(dio_out.Line(3),0);
ao=analogoutput('nidaq')
addchannel(ao, 0);
ch0=ao.Channel
% frequency  = 500;
% amplitude  = 5;
offset     = 0;
% dutycycle  = 50;
sampleRate=10000;
set(ao,'SampleRate',sampleRate);

%------------------------------------------------------

val=0;
set(ao, 'TriggerType', 'Immediate');
set(ao, 'RepeatOutput', 1);


while val~=9,
     
    disp('introduza o valor: ');
    val=input('');
    
%     valor=str2num(val);
    
    if val<=5 & val>=-5  
   
        
    waveData =offset+val;
    putdata(ao, [waveData]);
    pause;
    putvalue(dio_out.Line(3),1);
    start(ao);
    else
    
    disp('valor invalido');
    end
    putvalue(dio_out.Line(3),0);
end

disp('pp');
pause(0.05);
z=0+offset;
putdata(ao, [z]');
start(ao);

stop(ao);
delete(ao);
