Hi,
Very new at arduino, I’m trying to open/close my blinds with a futaba s3003. what I would like happen is when I press a button and keep it held down the the servo rotates 160 when I release the button it goes back to 20. I found some simple code to do this however the servos buzz. So what I need to figure out is how to hold a button down make the servo rotate to 160 then detach, release the button the servo goes back to 20 and detach. below. is the code I put together from other code I found. I cant for the life of me figure out what I’m do wrong. NOTE if the delay is 1000 it ignores the detach command all together. If the delay is 15 the detach command works put servos won’t attach again. Please help/advise
Thank You
//zoomkat servo button test
#include <Servo.h>
int button1 = 4; //button pin, connect to ground to move servo
int press1 = 0;
Servo servo1;
void setup()
{
pinMode(button1, INPUT);
servo1.attach(7);
digitalWrite(4, HIGH); //enable pullups to make pin high
}
void loop()
{
press1 = digitalRead(button1);
if (press1 == LOW)
{
servo1.attach(7);
servo1.write(160);
delay (1000);
servo1.detach();
}
else {
servo1.attach(7);
servo1.write(20);
delay (1000);
servo1.detach();
}
}