Hello,
I have a problem here. I found this code somewhere to control servos via python and it works very nice except it lacks one small thing... It doesn't have the option to set the position at which servos stay when arduino is powered on.
I want to make servos start at a predefined position BEFORE i start the software that I've written which then in turn controls the servos.
Because before I start the software they move to what ever default position they have (90 degrees i think).
Any thoughts would be appreciated.
#include <Servo.h>
Servo servo1;
Servo servo2;
Servo servo3;
Servo servo4;
int minPulse = 600;
int maxPulse = 2400;
int userInput[3];
int startbyte;
int servo;
int pos;
int i;
void setup()
{
servo1.attach(3, minPulse, maxPulse);
servo2.attach(4, minPulse, maxPulse);
servo3.attach(5, minPulse, maxPulse);
servo4.attach(6, minPulse, maxPulse);
Serial.begin(9600);
}
void loop()
{
if (Serial.available() > 2) {
startbyte = Serial.read();
if (startbyte == 255) {
for (i=0;i<2;i++) {
userInput[i] = Serial.read();
}
servo = userInput[0];
pos = userInput[1];
if (pos == 255) { servo = 255; }
switch (servo) {
case 1:
servo1.write(pos);
break;
case 2:
servo2.write(pos);
break;
case 3:
servo3.write(pos);
break;
case 4:
servo4.write(pos);
break;
}
}
}
}
Any ideas?