Hello everyone, I am a Arduino beginner.
I uses Leap Motion to simulate real persons finger action to control Arduino Mega 2560 microcontrollers manipulator, and I'm using Processing 3.2.3 and import de.voidplus.leapmotion for Leap Motion sensor.
Leap Motion will detect my finger and send messages to Arduino constantly. My question is, Arduino sends massive messages to the servomotor to process, causing the manipulator can't synchronize with my hand. Although it will save the datas in Serial.read and extract one character at a time to choose for my case statement, but the delay setting in the statement will make the synchronize between the electronic signal and the manipulator can not be reached.
If I set the delay too short or simply not set the delay, the motor will keep getting the same message and will not be able to move smoothly. In this aspect, should i do a communication management? or use solutions which there will be no delays such as using Millis()? but how should I execute it?
[/my code]
#include <Servo.h>int thumb = 4; //define the pin of the five fingers
int index = 5;
int middle = 6;
int ring = 7;
int pinky = 8;
int finger=Serial.available(); // variable to store the servo positionServo myservo; // create Servo objects to control the servo motor
void setup() {
myservo.attach(4);
myservo.attach(5);
myservo.attach(6);
myservo.attach(7);
myservo.attach(8);
pinMode(8, OUTPUT);
pinMode(7, OUTPUT);
pinMode(6, OUTPUT);
pinMode(5, OUTPUT);
pinMode(4, OUTPUT);
Serial.begin(9600);
delay(500);
}void loop()
{
finger = 0;
if (Serial.available() > 0)//check
{
finger = Serial.read(); //load and Save the variableswitch (finger) {
case 84:
//ASCII code 84('T')Thumb
//Serial.println("Thumb");
myservo.attach(4); // Connect the servo motor to the servo object on pin 4
myservo.write(5); // Tell the servo motor to rotate the position
delay(20);break;
case 116: // close_Thumb
//ASCII code 116('t')
myservo.attach(4); //Connect the servo motor to the servo object on pin 4
myservo.write(175);
delay(20);break;
case 73:
//ASCII code 73('I')Index
myservo.attach(5); // Connect the servo motor to the servo object on pin 5
myservo.write(5);
delay(20);break;
case 105: // close_Index
//ASCII code 105('i')
myservo.attach(5); // Connect the servo motor to the servo object on pin 5
myservo.write(175);
delay(20);break;
case 77:
//ASCII code 77('M')Middle
myservo.attach(6); // Connect the servo motor to the servo object on pin 6
myservo.write(5); /
delay(20);break;
case 109: // close_Middle
//ASCII code 109('m')
myservo.attach(6); // Connect the servo motor to the servo object on pin 6
myservo.write(175);
delay(20);break;
case 82:
//ASCII code 82('R')Ring
myservo.attach(7); // Connect the servo motor to the servo object on pin 7
myservo.write(5);
delay(20);break;
case 114: // close_Ring
//ASCII code 114('r')
myservo.attach(7); // Connect the servo motor to the servo object on pin 7
myservo.write(175);
delay(20);break;
case 80:
//ASCII code 80('P')Pinky
myservo.attach(8); // Connect the servo motor to the servo object on pin 8
myservo.write(5);
delay(20);break;
case 112: // close_Pinky
//ASCII code 112('p')
myservo.attach(8); // Connect the servo motor to the servo object on pin 8
myservo.write(180);
delay(20);break;
}//end of switch
}//end of if
}//end of loop