Adding functions

This commit is contained in:
chabisik 2022-12-15 12:38:02 +01:00
parent b907521f59
commit 20e85b9085

View file

@ -1,8 +1,12 @@
#include <ESP32Servo.h> #include <ESP32Servo.h>
#include <WiFi.h>
Servo myservo; // create servo object to control a servo Servo myservo; // create servo object to control a servo
int servoPin = 18; int servoPin = 18;
const char* ssid = "dlink";
const char* password = "";
void closeCircuitAndOpen(int closeTime=400) void closeCircuitAndOpen(int closeTime=400)
{ {
int pos = 0; int pos = 0;
@ -20,6 +24,8 @@ void closeCircuitAndOpen(int closeTime=400)
void setup() void setup()
{ {
Serial.begin(115200);
//======SERVO PART======//
// Allow allocation of all timers // Allow allocation of all timers
ESP32PWM::allocateTimer(0); ESP32PWM::allocateTimer(0);
ESP32PWM::allocateTimer(1); ESP32PWM::allocateTimer(1);
@ -28,6 +34,17 @@ void setup()
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(0);delay(2500); // position to initial suitable position
//======WIFI PART======/
WiFi.mode(WIFI_STA); //Optional
WiFi.begin(ssid, password);
Serial.println("\nConnecting");
while(WiFi.status() != WL_CONNECTED){
Serial.print(".");
delay(100);
}
Serial.println("\nConnected to the WiFi network");
Serial.print("Local ESP32 IP: ");
Serial.println(WiFi.localIP());
} }
void loop() void loop()