Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2014
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. #include <string.h>
  2.  
  3. #define NUMBER_OF_MOTORS 10
  4. int motorValues[NUMBER_OF_MOTORS];
  5. int motorId = 0;
  6.  
  7. Dynamixel Dxl(1);
  8.  
  9. boolean msgReceived = false;
  10.  
  11. void usbInterrupt(byte* buffer, byte nCount);
  12.  
  13. void setup() {
  14. Dxl.begin(3);
  15. Dxl.jointMode(1);
  16. delay(2000);
  17. SerialUSB.begin();
  18. SerialUSB.println("ServoSetup_Dxl");
  19. SerialUSB.attachInterrupt(usbInterrupt);
  20. }
  21.  
  22. void loop() {
  23.  
  24. }
  25.  
  26. char inChar[1];
  27. char res[3];
  28. size_t cIndex;
  29.  
  30. void usbInterrupt(byte* buffer, byte nCount){
  31. cIndex = 0;
  32.  
  33. while (SerialUSB.available()) {
  34.  
  35. *inChar = (char)SerialUSB.read();
  36.  
  37.  
  38. if (*inChar == 88) { // X
  39. motorId = 0;
  40. msgReceived = true;
  41. }
  42. else {
  43. if (*inChar == 32) {
  44. cIndex = 0;
  45. motorValues[motorId] = atoi(res);
  46. //SerialUSB.println(motorValues[motorId]);
  47. motorId++;
  48. }
  49. else {
  50. //SerialUSB.print("karakter :");
  51. //SerialUSB.println(inChar);
  52. res[cIndex++] = *inChar;
  53. //SerialUSB.println(res);
  54. }
  55. }
  56.  
  57. if(msgReceived) {
  58. for(int i = 0; i < NUMBER_OF_MOTORS; i++) {
  59. SerialUSB.println(motorValues[i]);
  60. }
  61. msgReceived = false;
  62. }
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement