Hello,
I have a problem here. I want to make servos start at a predefined position BEFORE i start the program that I've written (in python) which then in turn controls the servos.
Because when I start the program, they move to what ever default position they have (90 degrees i think) and only after boot I have to press a "home" button that ive made to send them wherever i need.
Please help as I'm totally new to programming with arduino.
#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 help would be appreciated. :