Advertisement
Guest User

Untitled

a guest
Nov 15th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. % Delete Opened Ports in MATLAB
  2. clear all;
  3. clc;
  4.  
  5. delete(instrfind)
  6.  
  7. ser = serial('COM3', 'BaudRate',115200, 'Timeout',10);
  8. syms right;
  9. syms left;
  10. syms stan;
  11. stan = 1;
  12. fopen(ser);
  13. while true
  14. d = fscanf(ser, '%d %d %d');
  15. value1 = d(1,:);
  16. value2 = d(2,:);
  17. value3 = d(3,:);
  18.  
  19. fprintf("%d\t%d\t%d\r\n", value1,value3,stan);
  20.  
  21.  
  22. switch stan
  23. case 1
  24. if(value1<600 && value3>600)
  25. stan = 2;
  26. elseif(value1>600 && value3<600)
  27. stan = 4;
  28. end
  29. case 2
  30. if(value1>600 && value3<600)
  31. stan = 3;
  32. end
  33. case 3
  34. fprintf("z prawej");
  35. if(value1>600 && value3>600)
  36. stan = 1;
  37. end
  38. case 4
  39. if(value1<600 && value3>600)
  40. stan = 5;
  41. end
  42. case 5
  43. fprintf("z lewej");
  44. if(value1>600 && value3>600)
  45. stan = 1;
  46. end
  47. end
  48.  
  49.  
  50.  
  51.  
  52. plot(d, 'LineWidth',2,'Color',[0,0,1.0])
  53. ylim([0,4000])
  54.  
  55. drawnow
  56. end
  57.  
  58.  
  59. fclose(ser);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement