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-23 11:07:03
- ********* 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"; // Define the correct PIN code
- String inputPIN = ""; // Variable to store the input PIN
- bool doorLocked = true; // Initial state of the door (locked)
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- // Create instances for EasyButton and Servo
- EasyButton button(codeButton_PushButton_PIN_D9);
- Servo servoMotor;
- void setup(void)
- {
- // put your setup code here, to run once:
- pinMode(codeButton_PushButton_PIN_D9, INPUT_PULLUP);
- pinMode(servo_Servomotor_PWMSignal_PIN_D2, OUTPUT);
- // Initialize the button
- button.begin();
- button.onPressed(handleButtonPress); // Set the button press handler
- // Initialize servo motor
- servoMotor.attach(servo_Servomotor_PWMSignal_PIN_D2);
- // Start the web server
- startWebServer();
- }
- void loop(void)
- {
- // put your main code here, to run repeatedly:
- button.read(); // Read the button state
- handleClient(); // Handle web server client requests
- updateOutputs(); // Refresh output data
- }
- void updateOutputs()
- {
- // Update the servo position based on the lock state
- if (doorLocked) {
- servo_Servomotor_PWMSignal_PIN_D2_rawData = 0; // Locked position
- } else {
- servo_Servomotor_PWMSignal_PIN_D2_rawData = 180; // Unlocked position
- }
- analogWrite(servo_Servomotor_PWMSignal_PIN_D2, servo_Servomotor_PWMSignal_PIN_D2_rawData);
- }
- void handleButtonPress()
- {
- // Simulate entering a PIN code (for demonstration purposes)
- inputPIN += "1"; // Append a digit (this should be replaced with actual input handling)
- if (inputPIN.length() == 4) { // Check if 4 digits are entered
- if (inputPIN == correctPIN) {
- doorLocked = !doorLocked; // Toggle the lock state
- }
- inputPIN = ""; // Reset the input PIN
- }
- }
- void startWebServer() {
- // Code to initialize and start the web server
- }
- void handleClient() {
- // Code to handle incoming client requests and serve the web page
- // This should display the current lock state of the door
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement