2
I would like a help to program the servo motor with Arduino with a button. How can I control the rotation time with timestamp? I need to turn the servo motor from -90º to 180º. Thank you!
#include <Servo.h>
Servo servo;
#define pinServo A1
void servolala(){
static unsigned long timestamp;
static byte stateS = 0;
static int angle = 0;
unsigned long timer;
timestamp = millis();
for(angle=0; angle>-90; angle--){
servo.write()
}
switch(state){
case 1:
//continue
}
}
void setup(){
Serial.begin(9600);
pinMode(6, OUTPUT);
pinMode(pinServo, INPUT_PULLUP);
servo.attach(6);
}
void loop(){
servolala();
}"
The
servo.write
takes the position the servant has to stay in degrees (0-180). See the example of the Servo in the documentation, as well as the own library if you would like to consult any of the functions– Isac
How do I control time within the function is what controls the servo position?
– Yunrin 127
Control the time just use
delay()
placing the time in milliseconds, which will serve as the waiting time between each rotation. The example I mentioned above has delays for the rotation to be timed.– Isac
What if I don’t use delay? It’s timestamps
– Yunrin 127
But it’s like active waiting
– Isac