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 05:28:35
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* arduion 使用库 #include <Arduino.h> #include */
- /* <WiFi.h> #include <Deneyap_Servo.h> ESP32C3 mcu */
- /* 禁用延迟语句 生成 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 <Arduino.h>
- #include <WiFi.h>
- #include <Deneyap_Servo.h>
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- void updateOutputs(void);
- /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
- const uint8_t tt_LED_PIN_D12 = 12;
- const uint8_t tt_LED_PIN_D13 = 13;
- /***** DEFINITION OF PWM OUTPUT PINS *****/
- const uint8_t AA_Servomotor_PWMSignal_PIN_D5 = 5; // Changed to pin 5 as per requirement
- /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
- bool tt_LED_PIN_D12_rawData = false;
- bool tt_LED_PIN_D13_rawData = false;
- uint8_t AA_Servomotor_PWMSignal_PIN_D5_rawData = 0;
- /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
- float tt_LED_PIN_D12_phyData = 0.0;
- float tt_LED_PIN_D13_phyData = 0.0;
- float AA_Servomotor_PWMSignal_PIN_D5_phyData = 0.0;
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES *****/
- Servo servoMotor; // Instance of Servo class
- void setup(void)
- {
- // Disable delay statements
- Serial.begin(115200);
- // Set up WiFi hotspot
- WiFi.softAP("ESP32_Hotspot", "11111111"); // Create WiFi hotspot with password "11111111"
- pinMode(tt_LED_PIN_D12, OUTPUT);
- pinMode(tt_LED_PIN_D13, OUTPUT);
- servoMotor.attach(AA_Servomotor_PWMSignal_PIN_D5); // Attach servo to pin 5
- }
- void loop(void)
- {
- // Check WiFi connection
- if (WiFi.softAPgetStationNum() > 0) {
- // WiFi connected
- tt_LED_PIN_D12_rawData = true; // Turn on LED on pin 12
- tt_LED_PIN_D13_rawData = false; // Turn off LED on pin 13
- AA_Servomotor_PWMSignal_PIN_D5_rawData += 5; // Increase servo position by 5 degrees
- if (AA_Servomotor_PWMSignal_PIN_D5_rawData >= 360) {
- AA_Servomotor_PWMSignal_PIN_D5_rawData = 0; // Reset to 0 after 360 degrees
- }
- } else {
- // WiFi disconnected
- tt_LED_PIN_D12_rawData = false; // Turn off LED on pin 12
- tt_LED_PIN_D13_rawData = true; // Turn on LED on pin 13
- AA_Servomotor_PWMSignal_PIN_D5_rawData -= 1; // Decrease servo position by 1 degree
- if (AA_Servomotor_PWMSignal_PIN_D5_rawData < 0) {
- AA_Servomotor_PWMSignal_PIN_D5_rawData = 360; // Reset to 360 after reaching 0
- }
- }
- updateOutputs(); // Refresh output data
- delay(100); // Add a small delay to avoid overwhelming the loop
- }
- void updateOutputs()
- {
- digitalWrite(tt_LED_PIN_D12, tt_LED_PIN_D12_rawData);
- digitalWrite(tt_LED_PIN_D13, tt_LED_PIN_D13_rawData);
- servoMotor.write(AA_Servomotor_PWMSignal_PIN_D5_rawData); // Update servo position
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement