Servo motor without header file , how to run? and how to smooth run servo motor?

servo motor without header file to run ? and how to smooth run the servo motor?

const int led = 8;
int ledState = LOW;
unsigned long previousMillis = 0;
const long intervel = 1000;

#define left 9
#define right 10

int pos = 0;


void setup() {
  Serial.begin(9600);
  pinMode(led, OUTPUT);
  pinMode(left, OUTPUT);

  pinMode(right, OUTPUT);
}

void loop() {
  unsigned long currentMillis = millis();

  Serial.print(" current=");
  Serial.print(currentMillis);
  Serial.print(" previous=");
  Serial.print(previousMillis);
  Serial.print(" previous=");
  Serial.println(previousMillis);


  if (currentMillis - previousMillis >= intervel) {
    previousMillis = currentMillis;


    if (ledState == LOW) {

      ledState = HIGH;
      Serial.println(" loop");
    } else {
      ledState = LOW;
    }
    digitalWrite(led, ledState);


    Serial.print("led=");
    Serial.println(led);

    for (pos = 0; pos <= 180; pos += 1) {

      analogWrite(left, pos);
    }
    for (pos = 180; pos >= 0; pos -= 1) {
      analogWrite(left, pos);
    }

    for (pos = 0; pos <= 180; pos += 1) {
      analogWrite(right, pos);
    }
    for (pos = 180; pos >= 0; pos -= 1) {
      analogWrite(right, pos);
    }
  }
}

Your topic has been moved to a more suitable location on the forum. Please read the sticky topics in Uncategorized - Arduino Forum as to why you should not post in "Uncategorized".

1 Like

Check the difference between Servo and Servo motor. The code looks like made for a Servo. Then no header file is needed.

2 Likes

Which controller are you using?

1 Like

Hello veeravgm

Welcome to the worldbest Arduino forum ever.

Post a picture of the motor.

Have a nice day and enjoy coding in C++.

image

Servo motor is not working smooth what will be next step

Using for "STM32 F4balck pill" controller.

If you don't want to use the Servo library, then basically you will need to write code with the same functionality and incorporate it into your own program but why re-invent the wheel?

Take a search engine of your choice and ask the WWW for 'STM32 F4balck pill +servo' to collect some data to be sorted out to get the needed information.

That is not a servo motor. It's for sure a servo. Okey, it does have a motor inside being controlled by internal circuitry.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.