hello everyone, i was following a tutorial for servo android control and wanted to modify the arduino code with no idea where to start
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created
int pos = 0; // variable to store the servo position
int motor = 0;
void setup()
{
Serial.begin(9600); // initialize serial:
myservo.attach(9); // attaches the servo on pin 9 to the servo object
Serial.print("Arduino control Servo Motor Connected OK");
Serial.print('\n');
}
void loop()
{
// if there's any serial available, read it:
while (Serial.available() > 0) {
// look for the next valid integer in the incoming serial stream:
//motor = Serial.parseInt();
// do it again:
pos = Serial.parseInt();
// look for the newline. That's the end of your sentence:
if (Serial.read() == '\n') {
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
// print the three numbers in one string as hexadecimal:
Serial.print("Data Response : ");
//Serial.print(motor, DEC);
Serial.print(pos, DEC);
}
}
}
This code will when executed set my servo to a degree of 180, and stay locked. if i tried to move it with my fingers it wont budge, only when i send an angle will it move.
What i wanted for it to do is, while input is not being send to the servo, the servo as free motion meaning if i moved it with my fingers it would move. Once i send an angle however, it stays locked to that degree for x amount of seconds then has free motion again.
Thanks!