Hi, so I'm making a useless box where the timing of two different servo motors is very important.
When running the code it works fine initially, but after flipping the switch a few times both servos are inconsistent about starting.
when the switch is flipped it will do one of four things.
- it will react immediately, working correctly, flipping the switch back and go back in place
- it will react immediately, but stops after it flips the switch for a few second then goes back
- it will have a delayed reaction before it starts to flip the switch then goes back in to place correctly
- Sometime both motors work separately too when they should not.
Only the first one option should be running consistently. I am not sure what is wrong with it but here is my code below. If anyone has any suggestions it would be greatly appreciated.
#include <Servo.h>
int tswitch = 2;
int servo1 = 7;
int servo2 = 6;
Servo Door;
Servo Arm;
void setup()
{
Door.attach(servo1);
Arm.attach(servo2);
pinMode(tswitch, INPUT_PULLUP);
digitalWrite(tswitch, HIGH);
Door.write(110);//110//startin positions
Arm.write(90);///40
}
void loop()
{
if(digitalRead(tswitch) == LOW)/////Low == ON
{
simpleClose();
}
}
void simpleClose()
{
Door.write(90);
Arm.write(150);
delay(100);
Door.write(110);
Arm.write(90);
}