Advertisement
pleasedontcode

**Servo Lock** rev_85

Oct 6th, 2024
67
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: **Servo Lock**
  13.     - Source Code NOT compiled for: Arduino Nano ESP32
  14.     - Source Code created on: 2024-10-06 09:37:38
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* The servo motor installed in the door will lock or */
  21.     /* unlock based on the correct PIN code received by */
  22.     /* the button. If the door is unlocked and the PIN is */
  23.     /* correct, it will lock. If the door is locked and */
  24.     /* the PIN is correct, it will unlock. */
  25. /****** SYSTEM REQUIREMENT 2 *****/
  26.     /* The webserver provides a web page about lock or */
  27.     /* unlock state of the door. */
  28. /****** END SYSTEM REQUIREMENTS *****/
  29.  
  30. /****** DEFINITION OF LIBRARIES *****/
  31. #include <Deneyap_Servo.h>  //https://github.com/deneyapkart/deneyap-servo-arduino-library
  32. #include <Keypad.h> //https://github.com/Chris--A/Keypad
  33. #include <EasyButton.h> //https://github.com/evert-arias/EasyButton
  34. #include <LcdKeypad.h>  //https://github.com/dniklaus/arduino-display-lcdkeypad
  35. #include <XYZrobotServo.h>  //https://github.com/pololu/xyzrobot-servo-arduino
  36. #include "LcdKeypadAdapter.h"
  37. #include "ServoController.h"
  38.  
  39. /****** FUNCTION PROTOTYPES *****/
  40. void setup(void);
  41. void loop(void);
  42. void checkKeypadInput(); // Function to check keypad input
  43. void updateLockState(); // Function to update lock state
  44.  
  45. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  46. const uint8_t keypad_Keypad3x4_R1_PIN_D4        = 4;
  47. const uint8_t keypad_Keypad3x4_R2_PIN_D5        = 5;
  48. const uint8_t keypad_Keypad3x4_R3_PIN_D6        = 6;
  49. const uint8_t keypad_Keypad3x4_R4_PIN_D7        = 7;
  50. const uint8_t pinButton_PushButton_PIN_D2       = 2;
  51.  
  52. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  53. const uint8_t keypad_Keypad3x4_C1_PIN_D8        = 8;
  54. const uint8_t keypad_Keypad3x4_C2_PIN_D9        = 9;
  55. const uint8_t keypad_Keypad3x4_C3_PIN_D10       = 10;
  56.  
  57. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  58. bool keypad_Keypad3x4_C1_PIN_D8_rawData     = 0;
  59. bool keypad_Keypad3x4_C2_PIN_D9_rawData     = 0;
  60. bool keypad_Keypad3x4_C3_PIN_D10_rawData        = 0;
  61.  
  62. const uint8_t KEYPAD3X4_ROWS = 4; //four rows
  63. const uint8_t KEYPAD3X4_COLS = 3; //three columns
  64. char Keys_Keypad3x4[KEYPAD3X4_ROWS][KEYPAD3X4_COLS] = {
  65.     {'1','2','3'},
  66.     {'4','5','6'},
  67.     {'7','8','9'},
  68.     {'*','0','#'},
  69. };
  70.  
  71. // Instantiate the ServoController object
  72. ServoController doorServo(11); // Assuming the servo is connected to pin 11
  73.  
  74. void setup(void)
  75. {
  76.     // put your setup code here, to run once:
  77.     pinMode(keypad_Keypad3x4_R1_PIN_D4, INPUT_PULLUP);
  78.     pinMode(keypad_Keypad3x4_R2_PIN_D5, INPUT_PULLUP);
  79.     pinMode(keypad_Keypad3x4_R3_PIN_D6, INPUT_PULLUP);
  80.     pinMode(keypad_Keypad3x4_R4_PIN_D7, INPUT_PULLUP);
  81.     pinMode(pinButton_PushButton_PIN_D2, INPUT_PULLUP);
  82.  
  83.     pinMode(keypad_Keypad3x4_C1_PIN_D8, OUTPUT);
  84.     pinMode(keypad_Keypad3x4_C2_PIN_D9, OUTPUT);
  85.     pinMode(keypad_Keypad3x4_C3_PIN_D10, OUTPUT);
  86.    
  87.     // Initialize the LCD Keypad
  88.     setupLcdKeypad();
  89. }
  90.  
  91. void loop(void)
  92. {
  93.     // put your main code here, to run repeatedly:
  94.     updateOutputs(); // Refresh output data
  95.     checkKeypadInput(); // Check for keypad input
  96. }
  97.  
  98. void updateOutputs()
  99. {
  100.     digitalWrite(keypad_Keypad3x4_C1_PIN_D8, keypad_Keypad3x4_C1_PIN_D8_rawData);
  101.     digitalWrite(keypad_Keypad3x4_C2_PIN_D9, keypad_Keypad3x4_C2_PIN_D9_rawData);
  102.     digitalWrite(keypad_Keypad3x4_C3_PIN_D10, keypad_Keypad3x4_C3_PIN_D10_rawData);
  103. }
  104.  
  105. void checkKeypadInput()
  106. {
  107.     // Logic to check for correct PIN input
  108.     // If correct PIN is entered, toggle lock state
  109.     char enteredPin[4]; // Assuming a 4-digit PIN
  110.     // Logic to read the entered PIN from the keypad
  111.     // Example: if (strcmp(enteredPin, correctPin) == 0) { updateLockState(); }
  112. }
  113.  
  114. void updateLockState()
  115. {
  116.     static bool isLocked = true; // Initial state is locked
  117.     isLocked = !isLocked; // Toggle lock state
  118.     if (isLocked) {
  119.         doorServo.lock(); // Lock the door
  120.     } else {
  121.         doorServo.unlock(); // Unlock the door
  122.     }
  123. }
  124.  
  125. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement