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: **Servo Control**
- - Source Code NOT compiled for: Arduino Nano ESP32
- - Source Code created on: 2025-02-26 22:46:35
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* The servo motor installed in the door will lock or */
- /* unlock based on the correct PIN code received by */
- /* the button. If the door is unlocked and the PIN is */
- /* correct, it will lock. If the door is locked and */
- /* the PIN is correct, it will unlock. */
- /****** SYSTEM REQUIREMENT 2 *****/
- /* The webserver provides a web page about lock or */
- /* unlock state of the door. */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #include <EasyButton.h> //https://github.com/evert-arias/EasyButton
- #include <Deneyap_Servo.h> //https://github.com/deneyapkart/deneyap-servo-arduino-library
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- void updateOutputs();
- void handleButtonPress();
- void startWebServer();
- void handleClient();
- /***** DEFINITION OF DIGITAL INPUT PINS *****/
- const uint8_t codeButton_PushButton_PIN_D9 = 9;
- /***** DEFINITION OF PWM OUTPUT PINS *****/
- const uint8_t servo_Servomotor_PWMSignal_PIN_D2 = 2;
- /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
- uint8_t servo_Servomotor_PWMSignal_PIN_D2_rawData = 0;
- /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
- float servo_Servomotor_PWMSignal_PIN_D2_phyData = 0.0;
- /***** PIN CODE VARIABLES *****/
- const String correctPIN = "1234"; // Set your correct PIN code here
- String enteredPIN = ""; // Variable to store the entered PIN
- bool doorLocked = true; // Initial state of the door (locked)
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- EasyButton codeButton(codeButton_PushButton_PIN_D9);
- Servo myServo;
- /****** SETUP FUNCTION *****/
- void setup(void)
- {
- // Initialize serial communication
- Serial.begin(115200);
- // Initialize button
- codeButton.begin();
- codeButton.onPressed(handleButtonPress);
- // Initialize servo
- myServo.attach(servo_Servomotor_PWMSignal_PIN_D2);
- // Start web server
- startWebServer();
- }
- /****** LOOP FUNCTION *****/
- void loop(void)
- {
- // Update button state
- codeButton.read();
- // Handle web client
- handleClient();
- // Refresh output data
- updateOutputs();
- }
- /****** BUTTON PRESS HANDLER FUNCTION *****/
- void handleButtonPress()
- {
- // Simulate entering a PIN code (for demonstration purposes)
- // In a real application, you would read the PIN from a keypad or similar
- enteredPIN = correctPIN; // Simulating correct PIN entry
- if (enteredPIN == correctPIN)
- {
- // Toggle door lock state
- doorLocked = !doorLocked;
- // Update servo position based on door state
- if (doorLocked)
- {
- servo_Servomotor_PWMSignal_PIN_D2_rawData = 0; // Lock the door
- }
- else
- {
- servo_Servomotor_PWMSignal_PIN_D2_rawData = 180; // Unlock the door
- }
- Serial.println(doorLocked ? "Door Locked" : "Door Unlocked");
- }
- }
- /****** UPDATE OUTPUTS FUNCTION *****/
- void updateOutputs()
- {
- myServo.write(servo_Servomotor_PWMSignal_PIN_D2_rawData);
- }
- /****** START WEB SERVER FUNCTION *****/
- void startWebServer()
- {
- // Code to initialize and start the web server
- // This would typically include setting up routes and handlers
- }
- /****** HANDLE CLIENT FUNCTION *****/
- void handleClient()
- {
- // Code to handle incoming web client requests
- // This would typically include sending the lock/unlock state to the client
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement