#include <VarSpeedServo.h>
VarSpeedServo myservo;
const int servoPin = 9;
const int sensorPin = 2;
volatile int pos;
void setup() {
// put your setup code here, to run once:
myservo.attach(servoPin);
if(pos = 0)
{
myservo.write(0,255,true);
pos = 0;
}
else
myservo.write(90,255,true)
pos = 90;
}
void loop() {
// put your main code here, to run repeatedly:
int sensed = digitalRead(sensorPin);// read pin 2 and put the result in the "sensed" variable
if(sensed == LOW){
Serial.println("Sensed \n position of servo is zero");
myservo.write(0,255,true);
pos = 0;
}else{
Serial.println("====");
myservo.write(90,255,true);
pos = 90;
}
delay(300);// delay for 0.3 seconds
}
#include <VarSpeedServo.h> there is no file or directory. can you guys help me fix this please? ty.
Where did you find the source code using that library?
Use the library manager to Install the library.
private person wrote it. dont know where he got it. i will install the library. i thought it may have something to do with that. do you know the name of the library? I'll try and figure it out.
No. Try search for VarSpeedServo in the forum or WWW.
Very first hit on Google:
Note: Use '==' for comparison. You are setting 'pos to zero and never executing the 'if' because 0 is 'false'.
WARNING: C++ is not like Python. It doesn't care about indentation. It only cares about curly braces: { and }. From the indentation I think you might have meant:
else
{
myservo.write(90,255,true)
pos = 90;
}
i got the library added finally. now when trying to compile, it errors 'cant compile for wemos d1 r2'. now what do i do
Now you look for error messages that tell you WHY 'cant compile for wemos d1 r2'. The messages are in the text box just below your sketch. If you can't figure out what they are telling you, copy all the text from that text box and paste it in a reply here.

Copy and paste the entire error message. The photo tells us nothing.
Also post the revised code, using code tags.
Arduino: 1.8.15 (Windows 10), Board: "LOLIN(WEMOS) D1 R2 & mini, 80 MHz, Flash, Legacy (new can return nullptr), All SSL ciphers (most compatible), 4MB (FS:2MB OTA:~1019KB), v2 Lower Memory, Disabled, None, Only Sketch, 921600"
C:\Users\JonesWin7\Documents\Arduino\libraries\VarSpeedServo-master\VarSpeedServo.cpp:71:27: fatal error: avr/interrupt.h: No such file or directory
#include <avr/interrupt.h>
^
compilation terminated.
exit status 1
Error compiling for board LOLIN(WEMOS) D1 R2 & mini.
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
Evidently that library does not support your board, which is not from Arduino.
When posting, it is always a good idea to indicate what board you are using.
is this sketch useless then? thx for your help.
The library is useless for your board.
ok so i said piss on it and i ordered the arduino branded name board, the uno. this script should work on it then. thanks for your help guys. appreciated.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.