Advertisement
Guest User

servo

a guest
Mar 7th, 2012
356
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. clear;
  2. clc;
  3. % connect the board
  4. a=arduino('COM8');
  5.  
  6. % a.digitalWrite(13,1);
  7.  
  8. % prints the status of both servos
  9. a.servoStatus(1);
  10.  
  11. % attach servo #1
  12. a.servoAttach(1);
  13.  
  14. % prints the status of both servos
  15. a.servoStatus;
  16.  
  17. % move servo #1 to 5 degrees position
  18. a.servoWrite(1,90);
  19. val1 = a.servoRead(1);
  20. pause(2)
  21.  
  22. % move servo #1 to 175 degrees position
  23. a.servoWrite(1,20);
  24. val2 = a.servoRead(1);
  25. pause(2)
  26.  
  27. % move servo #1 to 50 degrees position
  28. a.servoWrite(1,30);
  29. pause(2)
  30.  
  31. % reads angle from servo #1
  32. val=a.servoRead(1);
  33.  
  34. % attach servo #1
  35. a.servoDetach(1);
  36.  
  37.  
  38.  
  39. % close session
  40. delete(a)
  41.  
  42.  
  43. % Copyright 2011 The MathWorks, Inc.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement