Advertisement
pleasedontcode

**WiFi Control** rev_02

Jan 25th, 2025
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: **WiFi Control**
  13.     - Source Code NOT compiled for: ESP32 DevKit V1
  14.     - Source Code created on: 2025-01-26 05:28:35
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* arduion  使用库  #include <Arduino.h>  #include */
  21.     /* <WiFi.h>  #include <Deneyap_Servo.h>   ESP32C3 mcu */
  22.     /* 禁用延迟语句   生成 WiFi热点    wifi服务端 密码 8个1    wifi热点接入时 */
  23.     /* 亮12脚 13脚闪烁      SG舵机io5 每秒5度到达360度后反转 */
  24.     /* wifi热点断开时 灭12脚 13脚亮    SG舵机io5每秒转1度 360度后反转 */
  25. /****** END SYSTEM REQUIREMENTS *****/
  26.  
  27. /* START CODE */
  28.  
  29. /****** DEFINITION OF LIBRARIES *****/
  30. #include <Arduino.h>
  31. #include <WiFi.h>
  32. #include <Deneyap_Servo.h>
  33.  
  34. /****** FUNCTION PROTOTYPES *****/
  35. void setup(void);
  36. void loop(void);
  37. void updateOutputs(void);
  38.  
  39. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  40. const uint8_t tt_LED_PIN_D12 = 12;
  41. const uint8_t tt_LED_PIN_D13 = 13;
  42.  
  43. /***** DEFINITION OF PWM OUTPUT PINS *****/
  44. const uint8_t AA_Servomotor_PWMSignal_PIN_D5 = 5; // Changed to pin 5 as per requirement
  45.  
  46. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  47. bool tt_LED_PIN_D12_rawData = false;
  48. bool tt_LED_PIN_D13_rawData = false;
  49. uint8_t AA_Servomotor_PWMSignal_PIN_D5_rawData = 0;
  50.  
  51. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  52. float tt_LED_PIN_D12_phyData = 0.0;
  53. float tt_LED_PIN_D13_phyData = 0.0;
  54. float AA_Servomotor_PWMSignal_PIN_D5_phyData = 0.0;
  55.  
  56. /****** DEFINITION OF LIBRARIES CLASS INSTANCES *****/
  57. Servo servoMotor; // Instance of Servo class
  58.  
  59. void setup(void)
  60. {
  61.     // Disable delay statements
  62.     Serial.begin(115200);
  63.  
  64.     // Set up WiFi hotspot
  65.     WiFi.softAP("ESP32_Hotspot", "11111111"); // Create WiFi hotspot with password "11111111"
  66.  
  67.     pinMode(tt_LED_PIN_D12, OUTPUT);
  68.     pinMode(tt_LED_PIN_D13, OUTPUT);
  69.     servoMotor.attach(AA_Servomotor_PWMSignal_PIN_D5); // Attach servo to pin 5
  70. }
  71.  
  72. void loop(void)
  73. {
  74.     // Check WiFi connection
  75.     if (WiFi.softAPgetStationNum() > 0) {
  76.         // WiFi connected
  77.         tt_LED_PIN_D12_rawData = true; // Turn on LED on pin 12
  78.         tt_LED_PIN_D13_rawData = false; // Turn off LED on pin 13
  79.         AA_Servomotor_PWMSignal_PIN_D5_rawData += 5; // Increase servo position by 5 degrees
  80.         if (AA_Servomotor_PWMSignal_PIN_D5_rawData >= 360) {
  81.             AA_Servomotor_PWMSignal_PIN_D5_rawData = 0; // Reset to 0 after 360 degrees
  82.         }
  83.     } else {
  84.         // WiFi disconnected
  85.         tt_LED_PIN_D12_rawData = false; // Turn off LED on pin 12
  86.         tt_LED_PIN_D13_rawData = true; // Turn on LED on pin 13
  87.         AA_Servomotor_PWMSignal_PIN_D5_rawData -= 1; // Decrease servo position by 1 degree
  88.         if (AA_Servomotor_PWMSignal_PIN_D5_rawData < 0) {
  89.             AA_Servomotor_PWMSignal_PIN_D5_rawData = 360; // Reset to 360 after reaching 0
  90.         }
  91.     }
  92.  
  93.     updateOutputs(); // Refresh output data
  94.     delay(100); // Add a small delay to avoid overwhelming the loop
  95. }
  96.  
  97. void updateOutputs()
  98. {
  99.     digitalWrite(tt_LED_PIN_D12, tt_LED_PIN_D12_rawData);
  100.     digitalWrite(tt_LED_PIN_D13, tt_LED_PIN_D13_rawData);
  101.     servoMotor.write(AA_Servomotor_PWMSignal_PIN_D5_rawData); // Update servo position
  102. }
  103.  
  104. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement