Modifying servo initial position
This commit is contained in:
parent
ff914468d7
commit
a2472dce49
1 changed files with 4 additions and 3 deletions
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
Servo myservo; // create servo object to control a servo
|
Servo myservo; // create servo object to control a servo
|
||||||
int servoPin = 18;
|
int servoPin = 18;
|
||||||
|
int initialPos = 100;
|
||||||
|
|
||||||
const char* ssid = "dlink";
|
const char* ssid = "dlink";
|
||||||
const char* password = "";
|
const char* password = "";
|
||||||
|
@ -13,13 +14,13 @@ WebServer server(80);
|
||||||
void closeCircuitAndOpen(int closeTime=400)
|
void closeCircuitAndOpen(int closeTime=400)
|
||||||
{
|
{
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
for(pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
|
for(pos = initialPos; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
|
||||||
// in steps of 1 degree
|
// in steps of 1 degree
|
||||||
myservo.write(pos); // tell servo to go to position in variable 'pos'
|
myservo.write(pos); // tell servo to go to position in variable 'pos'
|
||||||
delay(15); // waits 15ms for the servo to reach the position
|
delay(15); // waits 15ms for the servo to reach the position
|
||||||
}
|
}
|
||||||
delay(closeTime);
|
delay(closeTime);
|
||||||
for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
|
for (pos = 180; pos >= initialPos; pos -= 1) { // goes from 180 degrees to 0 degrees
|
||||||
myservo.write(pos); // tell servo to go to position in variable 'pos'
|
myservo.write(pos); // tell servo to go to position in variable 'pos'
|
||||||
delay(15); // waits 15ms for the servo to reach the position
|
delay(15); // waits 15ms for the servo to reach the position
|
||||||
}
|
}
|
||||||
|
@ -53,7 +54,7 @@ void setup()
|
||||||
ESP32PWM::allocateTimer(3);
|
ESP32PWM::allocateTimer(3);
|
||||||
myservo.setPeriodHertz(50); // standard 50 hz servo
|
myservo.setPeriodHertz(50); // standard 50 hz servo
|
||||||
myservo.attach(servoPin, 1000, 2000); // attaches the servo on pin 18 to the servo object
|
myservo.attach(servoPin, 1000, 2000); // attaches the servo on pin 18 to the servo object
|
||||||
myservo.write(0);delay(2500); // position to initial suitable position
|
myservo.write(initialPos);delay(2500); // position to initial suitable position
|
||||||
//======WIFI PART======//
|
//======WIFI PART======//
|
||||||
WiFi.mode(WIFI_STA); //Optional
|
WiFi.mode(WIFI_STA); //Optional
|
||||||
WiFi.begin(ssid, password);
|
WiFi.begin(ssid, password);
|
||||||
|
|
Loading…
Reference in a new issue