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: Strongbox
- - Source Code compiled for: Arduino Mega
- - Source Code created on: 2023-09-17 20:10:00
- - Source Code generated by: Tom
- ********* Pleasedontcode.com **********/
- /****** DEFINITION OF LIBRARIES *****/
- #include <Arduino.h>
- #include <Wire.h>
- #include <LiquidCrystal_I2C.h>
- #include <Keypad.h>
- #include <Servo.h>
- /****** SYSTEM REQUIREMENT 1 *****/
- // This is a project to create a strongbox with a keypad (to enter the code), a display (to show the state of strongbox) and a servo (to lock or unlock the door).
- /****** SYSTEM REQUIREMENT 2 *****/
- // A code number has to be stored in EEPROM (the value is 3478) and used for comparison with the code provided by user.
- /****** SYSTEM REQUIREMENT 3 *****/
- // At startup, Arduino has to initialize the display showing "Press digit code of 4 numbers:".
- /****** SYSTEM REQUIREMENT 4 *****/
- // Periodically the system has to wait the code of 4 numbers from keypad. After each number is introduced, add a '*' character on the second row. When the 4 digits are introduced, check if the code is equal to the value saved in EEPROM.
- /****** SYSTEM REQUIREMENT 5 *****/
- // Save on EEPROM also the state of machine which is composed of 2 states: "DOOR LOCKED" and "DOOR UNLOCKED".
- /****** SYSTEM REQUIREMENT 6 *****/
- // If the code is equal to EEPROM value and the state is "DOOR LOCKED", unlock the door: drive the servo to 180 degrees, show on display 'DOOR UNLOCKED' for 2 seconds, and change the state to 'DOOR UNLOCKED'.
- /****** SYSTEM REQUIREMENT 7 *****/
- // If the state is 'DOOR UNLOCKED', write on the display 'Enter 4 digits to lock the door', then wait for 4 digits on the keypad. And at each digit pressed, display a '*' character on the second row of the display.
- /****** SYSTEM REQUIREMENT 8 *****/
- // After the 4 digits are entered, change the state from 'DOOR UNLOCKED' to 'DOOR LOCKED', save it in EEPROM, drive the servo to 0 degrees, display 'DOOR LOCKED' for 3 seconds, and save the code in EEPROM.
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- /***** DEFINITION OF PWM OUTPUT PINS *****/
- const uint8_t servo_PIN_D2 = 2;
- /***** DEFINITION OF I2C PINS *****/
- const uint8_t display_LCD1602I2C_I2C_PIN_SDA_D20 = 20;
- const uint8_t display_LCD1602I2C_I2C_PIN_SCL_D21 = 21;
- const uint8_t display_LCD1602I2C_I2C_SLAVE_ADDRESS = 39;
- // Function prototypes
- static void initializeDisplay();
- static void displayMessage(const char* message);
- static void displayCodeEntry();
- static void displayCodeConfirmation();
- static void unlockDoor();
- static void lockDoor();
- void setup(void)
- {
- // Initialize the servo pin as output
- pinMode(servo_PIN_D2, OUTPUT);
- // Initialize the display
- initializeDisplay();
- }
- void loop(void)
- {
- // Main code logic goes here
- }
- // Function to initialize the display
- static void initializeDisplay()
- {
- // Code to initialize the display goes here
- }
- // Function to display a message on the LCD
- static void displayMessage(const char* message)
- {
- // Code to display the message on the LCD goes here
- }
- // Function to display the code entry prompt on the LCD
- static void displayCodeEntry()
- {
- // Code to display the code entry prompt on the LCD goes here
- }
- // Function to display the code confirmation prompt on the LCD
- static void displayCodeConfirmation()
- {
- // Code to display the code confirmation prompt on the LCD goes here
- }
- // Function to unlock the door
- static void unlockDoor()
- {
- // Code to unlock the door goes here
- }
- // Function to lock the door
- static void lockDoor()
- {
- // Code to lock the door goes here
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement