Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string.h>
- #define NUMBER_OF_MOTORS 10
- int motorValues[NUMBER_OF_MOTORS];
- int motorId = 0;
- Dynamixel Dxl(1);
- boolean msgReceived = false;
- void usbInterrupt(byte* buffer, byte nCount);
- void setup() {
- Dxl.begin(3);
- Dxl.jointMode(1);
- delay(2000);
- SerialUSB.begin();
- SerialUSB.println("ServoSetup_Dxl");
- SerialUSB.attachInterrupt(usbInterrupt);
- }
- void loop() {
- }
- char inChar[1];
- char res[3];
- size_t cIndex;
- void usbInterrupt(byte* buffer, byte nCount){
- cIndex = 0;
- while (SerialUSB.available()) {
- *inChar = (char)SerialUSB.read();
- if (*inChar == 88) { // X
- motorId = 0;
- msgReceived = true;
- }
- else {
- if (*inChar == 32) {
- cIndex = 0;
- motorValues[motorId] = atoi(res);
- //SerialUSB.println(motorValues[motorId]);
- motorId++;
- }
- else {
- //SerialUSB.print("karakter :");
- //SerialUSB.println(inChar);
- res[cIndex++] = *inChar;
- //SerialUSB.println(res);
- }
- }
- if(msgReceived) {
- for(int i = 0; i < NUMBER_OF_MOTORS; i++) {
- SerialUSB.println(motorValues[i]);
- }
- msgReceived = false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement