How to turn the servo motor using Arduino and a button? What would be the function?

Asked

Viewed 749 times

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

  • How do I control time within the function is what controls the servo position?

  • 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.

  • What if I don’t use delay? It’s timestamps

  • But it’s like active waiting

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.