can't use Servo library

Hi, I had this kind of problem with other library which I solved by moving the files of the library into the folder of the sketch. but now nothing works heres the code(from the examples) and the error message:

/*
 Controlling a servo position using a potentiometer (variable resistor)
 by Michal Rinott <http://people.interaction-ivrea.it/m.rinott>

 modified on 8 Nov 2013
 by Scott Fitzgerald
 http://www.arduino.cc/en/Tutorial/Knob
*/

#include <Servo.h>

Servo myservo;  // create servo object to control a servo

int potpin = 0;  // analog pin used to connect the potentiometer
int val;    // variable to read the value from the analog pin

void setup() {
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
}

void loop() {
  val = analogRead(potpin);            // reads the value of the potentiometer (value between 0 and 1023)
  val = map(val, 0, 1023, 0, 180);     // scale it to use it with the servo (value between 0 and 180)
  myservo.write(val);                  // sets the servo position according to the scaled value
  delay(15);                           // waits for the servo to get there
}

error:

Arduino: 1.8.9 (Windows Store 1.8.21.0) (Windows 10), Board: "Arduino/Genuino Uno"

Knob:10:19: error: Servo.h: No such file or directory

Multiple libraries were found for "Servo.h"
compilation terminated.

 Used: C:\Users\danny\OneDrive\Documents\Arduino\libraries\Servo
 Not used: C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.21.0_x86__mdqgnx93n4wtt\libraries\Servo
exit status 1
Servo.h: No such file or directory

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

it says multiple libraries were found for servo.h after saying no such file or directory. anyway I see only 1 file of the servo.h

int potpin = 0; // this points to RX pin

int potpin = A0;   // this points to analog-0 pin

// BTW, use byte over int, something like this

byte potpin = A0; 

// and you will save some precious 8 Bits of SRAM a piece

and to keep servo from jittering

invoke

pinMode(9,INPUT_PULLUP); in setup()

and servo.attach(9); when you want to move it

servo.detach(); when you done moving it

StrikEagle:
Hi, I had this kind of problem with other library which I solved by moving the files of the library into the folder of the sketch.

That's a patch, don't. Just place the files in the correct folder. That's the "libraries" folder in your sketchbook (NOT the libraries folder in de IDE folder). By default that's "C:\Users[user]\Documents\Arduino\libraries"

But did you mess around with the servo library files? By default they are included in the IDE for the normal boards.

And which board are you using?

@KASSIMSAMJI Although I fully agree using A0 is nicer and more universal, doing analogRead(0) will read pin A0. A digitalRead(0) (or write) will indeed read pin 0 / RX where as digitalRead(A0) will read pin A0.

I have a larger problem with the pins being an int though :stuck_out_tongue:

septillion:
That's a patch, don't. Just place the files in the correct folder. That's the "libraries" folder in your sketchbook (NOT the libraries folder in de IDE folder). By default that's "C:\Users[user]\Documents\Arduino\libraries"

But did you mess around with the servo library files? By default they are included in the IDE for the normal boards.

And which board are you using?

@KASSIMSAMJI Although I fully agree using A0 is nicer and more universal, doing analogRead(0) will read pin A0. A digitalRead(0) (or write) will indeed read pin 0 / RX where as digitalRead(A0) will read pin A0.

I have a larger problem with the pins being an int though :stuck_out_tongue:

I didn't mess with them they are all in the libraries folder under the folder "SERVO" inside

And you have no servo library in your sketch folder? Nor in your sketchbook?

I suspect OneDrive as the culprit. Your current sketchbook location is in the OneDrive. Try changing your sketchbook folder location in File > Preferences > Sketchbook Location to some folder outside of OneDrive. You will need to copy the files and folders from C:\Users\danny\OneDrive\Documents\Arduino to your new location.

If you want to do that thing

moving the files of the library into the folder of the sketch

.

Then do this thing:

#include "Servo.h"

it works now I deleted the servo folder from libraries and it regenerated this folder again automatiicaly and now it works. thanks