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: # Elevator Controller
- - Source Code NOT compiled for: Arduino Mega
- - Source Code created on: 2026-01-12 20:38:55
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* fai salire e scendere l'ascensore con due bottoni */
- /****** END SYSTEM REQUIREMENTS *****/
- void setup(void)
- {
- // put your setup code here, to run once:
- // Configure input pins with internal pull-up resistors
- pinMode(1_PushButton_PIN_D2, INPUT_PULLUP);
- pinMode(2_PushButton_PIN_D3, INPUT_PULLUP);
- // Configure output pins for elevator motor control
- pinMode(ELEVATOR_UP_PIN_D4, OUTPUT);
- pinMode(ELEVATOR_DOWN_PIN_D5, OUTPUT);
- // Initialize elevator motor pins to LOW (motor stopped)
- digitalWrite(ELEVATOR_UP_PIN_D4, LOW);
- digitalWrite(ELEVATOR_DOWN_PIN_D5, LOW);
- // Initialize button1
- button1.begin();
- // Add callback functions for button1
- button1.onPressed(onButton1Pressed);
- button1.onReleased(onButton1Released);
- // Initialize button2
- button2.begin();
- // Add callback functions for button2
- button2.onPressed(onButton2Pressed);
- button2.onReleased(onButton2Released);
- }
- void loop(void)
- {
- // put your main code here, to run repeatedly:
- // Continuously read the status of button1
- button1.read();
- // Continuously read the status of button2
- button2.read();
- }
- // Callback function for button1 pressed event - elevator goes UP
- void onButton1Pressed(void)
- {
- elevatorUp();
- }
- // Callback function for button1 released event - elevator stops
- void onButton1Released(void)
- {
- elevatorStop();
- }
- // Callback function for button2 pressed event - elevator goes DOWN
- void onButton2Pressed(void)
- {
- elevatorDown();
- }
- // Callback function for button2 released event - elevator stops
- void onButton2Released(void)
- {
- elevatorStop();
- }
- // Function to move elevator UP
- void elevatorUp(void)
- {
- // Set UP direction pin HIGH and DOWN direction pin LOW
- digitalWrite(ELEVATOR_UP_PIN_D4, HIGH);
- digitalWrite(ELEVATOR_DOWN_PIN_D5, LOW);
- }
- // Function to move elevator DOWN
- void elevatorDown(void)
- {
- // Set DOWN direction pin HIGH and UP direction pin LOW
- digitalWrite(ELEVATOR_UP_PIN_D4, LOW);
- digitalWrite(ELEVATOR_DOWN_PIN_D5, HIGH);
- }
- // Function to stop the elevator
- void elevatorStop(void)
- {
- // Set both direction pins LOW to stop the motor
- digitalWrite(ELEVATOR_UP_PIN_D4, LOW);
- digitalWrite(ELEVATOR_DOWN_PIN_D5, LOW);
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment