Hello
I have a robot arm consisting of 6 servo motor 've programmed the arm by Arduino mega so if sent to the Arduino example letter (P) will move servo first by 10 degrees clockwise , and if sent to the Arduino example letter (R) will move servo first 10 degrees counterclockwise note I have found that the servo spins 180 degrees
If the letter was sent in several times , it will be up to the corner at 180 and continue to send the letter P , the servo will issue a sound and vibrate because of its potential to spin more
So how do I Arrduino programming so that if you came to the end of the corner either 180 or 0 then it is not possible to instruct the sender because of the arrival at the final grade of the movement
This code
#include <Servo.h>
Servo myservo; // create servo object to control a servo
int pos = 0; // variable to store the servo position
int message ;
void setup()
{
pinMode(9,OUTPUT);
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
There are a number of problems with your code. First, it's posted incorrectly. There are two threads at the top of the forum that explain what you should do when posting in this forum. Either you didn't read them or you thought they didn't apply to you. You should have, and they do.
Second, it has useless open and close curly braces, positioned incorrectly. Put each { on a new line. Put each } on a line by itself. Learn which ones are actually needed, which ones are optional but a god idea, and which ones are simply silly looking.
Third, it calls Serial.flush(), which blocks until all pending serial data has been sent. Nowhere do you actually send any, so the flush() call looks stupid, since it has nothing to do.
Finally, if the letter P arrives, or the letter R arrives, you can check to see if the value in pos is already at the limit before incrementing or decrementing pos.
So how do I Arrduino programming so that if you came to the end of the corner either 180 or 0 then it is not possible to instruct the sender because of the arrival at the final grade of the movement
You can make conditional checks to limit values like below.