Advertisement
Guest User

Untitled

a guest
Feb 26th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. clc;
  2. clear all;
  3. comport = serial('COM8', 'BaudRate', 115200); % setup comport
  4. comport.InputBufferSize = 50000;
  5. fopen(comport); % Open comport
  6.  
  7. %% setting up plots and variables
  8. time= zeros(1,100000); v1=zeros(1,100000); v2 =zeros(1,100000); v3= zeros(1,100000);v4=zeros(1,100000);
  9. header='x';t=zeros(1000,1);data=0;
  10. figure;
  11. subplot(411) ;
  12. h = plot(v1, 'r-'); % Save handle to the line
  13. title('Channel 1'); % axis ([t(1) inf 0 inf]);
  14. ylabel('Amplitude(V)');
  15.  
  16. subplot(412); h2= plot(v2, 'b-'); % Save handle to the line
  17. title('Channel 2');%axis ([t(1) inf 0 inf]);
  18. ylabel('Amplitude(V)');
  19.  
  20.  
  21. subplot(413); h3= plot(v3, 'b-'); % Save handle to the line
  22. title('Channel 3');%axis ([t(1) inf 0 inf]);
  23. ylabel('Amplitude(V)');
  24.  
  25. subplot(414); h4= plot(v4, 'm-'); % Save handle to the line
  26. title('Channel 4');%axis ([0 inf 0 2]);
  27. xlabel('Time (seconds)');%axis ([t(1) inf 0 inf]);
  28. ylabel('Amplitude(V)')
  29.  
  30. %% Handshake part, send 1 so that Arduino starts recording and transmitting
  31. servalue= input('Enter the value 1 when ready :');
  32. fprintf(comport,servalue); %This command will send entered value to Arduino
  33.  
  34. x=1;in=1;
  35. tic; %%starting stopwatch
  36. while(toc<100)
  37.  
  38. data=strsplit(fgetl(comport),'t');
  39. if length(data)==5
  40. time(in) = str2double(data(1));
  41. v1(in) = str2double(data(2));
  42. v2(in) = str2double(data(3));
  43. v3(in)= str2double(data(4));
  44. v4(in) = str2double(data(5));
  45.  
  46. in=in+1;
  47.  
  48. %% Updating the plots after every 100 samples
  49. % if(in==x*100)
  50. % set(h, 'Xdata', time(1:in), 'ydata', v1(1:in)); %axis ([t(1) inf 0 inf]);% Update plot
  51. % set(h2, 'Xdata', time(1:in),'ydata', v2(1:in));%axis ([t(1) inf 0 inf]);% Update plot
  52. % set(h3, 'Xdata', time(1:in), 'ydata', v3(1:in)); %axis ([t(1) inf 0 inf]);% Update plot
  53. % set(h4, 'Xdata', time(1:in),'ydata', v4(1:in));% axis ([t(1) inf 0 inf]);% Update plot
  54. % disp(toc);
  55. % drawnow;
  56. % x=x+1;
  57. % end
  58. end
  59. fclose(comport); % Close comport
  60. delete(comport); % Clear comport
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement