Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* Pleasedontcode.com **********
- Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- - Terms and Conditions:
- You have a non-exclusive, revocable, worldwide, royalty-free license
- for personal and commercial use. Attribution is optional; modifications
- are allowed, but you're responsible for code maintenance. We're not
- liable for any loss or damage. For full terms,
- please visit pleasedontcode.com/termsandconditions.
- - Project: **WiFi Control**
- - Source Code NOT compiled for: ESP32 DevKit V1
- - Source Code created on: 2025-01-26 12:30:49
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* 生成 WiFi热点 wifi服务端 密码 8个1 wifi热点接入时 亮12脚 */
- /* 13脚闪烁 SG舵机io5 每秒5度到达360度后反转 wifi热点断开时 */
- /* 灭12脚 13脚亮 SG舵机io5每秒转1度 360度后反转 */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #include <ESP_AT_WiFiManager.h> // https://github.com/khoih-prog/ESP_AT_WiFiManager
- #include <Deneyap_Servo.h> // https://github.com/deneyapkart/deneyap-servo-arduino-library
- #include <Arduino.h>
- #include <WiFi.h>
- #include <Servo.h> // Ensure this line has no spelling errors
- // WiFi credentials
- const char* ssid = "your_SSID"; // Update with your WiFi SSID
- const char* password = "your_PASSWORD"; // Update with your WiFi password
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- void updateOutputs(void);
- /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
- const uint8_t LED_PIN_D4 = 4; // LED pin
- const int d2Pin = 2; // D2 pin
- /***** DEFINITION OF PWM OUTPUT PINS *****/
- const uint8_t Servo_PWM_PIN_D13 = 13; // Servo PWM pin
- const int servoPin = 5; // Change to your servo pin
- /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
- bool LED_PIN_D4_rawData = 0; // Raw data for LED
- uint8_t Servo_PWM_PIN_D13_rawData = 0; // Raw data for servo
- /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
- float LED_PIN_D4_phyData = 0.0; // Physical data for LED
- float Servo_PWM_PIN_D13_phyData = 0.0; // Physical data for servo
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- // Servo motor setup
- Servo myservo;
- /****** FUNCTION DECLARATIONS *****/
- int myFunction(int, int);
- void setup(void)
- {
- Serial.begin(115200);
- pinMode(d2Pin, OUTPUT);
- digitalWrite(d2Pin, LOW); // Initialize D2 pin to LOW
- pinMode(LED_PIN_D4, OUTPUT);
- pinMode(Servo_PWM_PIN_D13, OUTPUT);
- // Initialize servo
- myservo.attach(servoPin);
- // Connect to WiFi
- WiFi.begin(ssid, password);
- while (WiFi.status() != WL_CONNECTED) {
- delay(1000);
- Serial.println("Connecting to WiFi...");
- }
- Serial.println("Connected to WiFi");
- // Turn on LED when WiFi is connected
- digitalWrite(LED_PIN_D4, HIGH);
- // Rotate servo to 30 degrees and set D2 pin HIGH
- myservo.write(30);
- digitalWrite(d2Pin, HIGH);
- }
- void loop(void)
- {
- // put your main code here, to run repeatedly:
- updateOutputs(); // Refresh output data
- int result = myFunction(2, 3);
- // Control servo and LED based on WiFi connection status
- if (WiFi.status() == WL_CONNECTED) {
- // WiFi is connected
- digitalWrite(LED_PIN_D4, HIGH); // Turn on LED
- for (int angle = 30; angle <= 360; angle += 5) {
- myservo.write(angle);
- delay(200); // Adjust delay for speed
- }
- for (int angle = 360; angle >= 30; angle -= 5) {
- myservo.write(angle);
- delay(200); // Adjust delay for speed
- }
- } else {
- // WiFi is disconnected
- digitalWrite(LED_PIN_D4, LOW); // Turn off LED
- for (int angle = 360; angle >= 0; angle -= 1) {
- myservo.write(angle);
- delay(100); // Adjust delay for speed
- }
- }
- }
- void updateOutputs()
- {
- digitalWrite(LED_PIN_D4, LED_PIN_D4_rawData);
- analogWrite(Servo_PWM_PIN_D13, Servo_PWM_PIN_D13_rawData);
- }
- /***** FUNCTION DEFINITIONS *****/
- int myFunction(int x, int y) {
- return x + y;
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement