Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- clc;
- clear all;
- comport = serial('COM8', 'BaudRate', 115200); % setup comport
- comport.InputBufferSize = 50000;
- fopen(comport); % Open comport
- %% setting up plots and variables
- time= zeros(1,100000); v1=zeros(1,100000); v2 =zeros(1,100000); v3= zeros(1,100000);v4=zeros(1,100000);
- header='x';t=zeros(1000,1);data=0;
- figure;
- subplot(411) ;
- h = plot(v1, 'r-'); % Save handle to the line
- title('Channel 1'); % axis ([t(1) inf 0 inf]);
- ylabel('Amplitude(V)');
- subplot(412); h2= plot(v2, 'b-'); % Save handle to the line
- title('Channel 2');%axis ([t(1) inf 0 inf]);
- ylabel('Amplitude(V)');
- subplot(413); h3= plot(v3, 'b-'); % Save handle to the line
- title('Channel 3');%axis ([t(1) inf 0 inf]);
- ylabel('Amplitude(V)');
- subplot(414); h4= plot(v4, 'm-'); % Save handle to the line
- title('Channel 4');%axis ([0 inf 0 2]);
- xlabel('Time (seconds)');%axis ([t(1) inf 0 inf]);
- ylabel('Amplitude(V)')
- %% Handshake part, send 1 so that Arduino starts recording and transmitting
- servalue= input('Enter the value 1 when ready :');
- fprintf(comport,servalue); %This command will send entered value to Arduino
- x=1;in=1;
- tic; %%starting stopwatch
- while(toc<100)
- data=strsplit(fgetl(comport),'t');
- if length(data)==5
- time(in) = str2double(data(1));
- v1(in) = str2double(data(2));
- v2(in) = str2double(data(3));
- v3(in)= str2double(data(4));
- v4(in) = str2double(data(5));
- in=in+1;
- %% Updating the plots after every 100 samples
- % if(in==x*100)
- % set(h, 'Xdata', time(1:in), 'ydata', v1(1:in)); %axis ([t(1) inf 0 inf]);% Update plot
- % set(h2, 'Xdata', time(1:in),'ydata', v2(1:in));%axis ([t(1) inf 0 inf]);% Update plot
- % set(h3, 'Xdata', time(1:in), 'ydata', v3(1:in)); %axis ([t(1) inf 0 inf]);% Update plot
- % set(h4, 'Xdata', time(1:in),'ydata', v4(1:in));% axis ([t(1) inf 0 inf]);% Update plot
- % disp(toc);
- % drawnow;
- % x=x+1;
- % end
- end
- fclose(comport); % Close comport
- delete(comport); % Clear comport
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement