Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. %Opening serial port
  2. s = serial('COM9');
  3. set(s,'BaudRate',9600,'Terminator','CR'); %Note that CR will be concatenated to all commands
  4. fopen(s);
  5. s %print for debugging
  6.  
  7. t=1 %loop index
  8.  
  9. while true
  10. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  11. %Here is code to mess with a joystick that works fine, using VS command
  12. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  13.  
  14. if button(joy, 3) == 1 %Button3 of joystick should trigger position reading
  15. fprintf(s,'vs,0,0'); %Halt joystick movement
  16. pause(1) %Debouncing
  17. fprintf(s,'p'); %Axe-pos reading command
  18. fgets(s) %Reading the answer
  19. end
  20.  
  21.  
  22. %This way to increment follows the skipped parts and is required for timing
  23. if mod(t, 100)==0
  24. fprintf(s,'%s',Command);
  25. t=1;
  26. else
  27. t=t+1;
  28. end
  29.  
  30. >> s = openserial()
  31. %properties as before, skipped to save space
  32. >> fprintf(s,'ps');
  33. >> fgets(s)
  34.  
  35. ans =
  36.  
  37. 100000,100000
  38.  
  39. >> fprintf(s,'p');
  40. >> fgets(s)
  41.  
  42. ans =
  43.  
  44. 100000,100000,0
  45.  
  46. >> fprintf(s,'p');
  47. >> fgets(s)
  48.  
  49. ans =
  50.  
  51. R
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement