pleasedontcode

# Elevator Controller rev_01

Jan 12th, 2026
25
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: # Elevator Controller
  13.     - Source Code NOT compiled for: Arduino Mega
  14.     - Source Code created on: 2026-01-12 20:38:55
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* fai salire e scendere l'ascensore con due bottoni */
  21. /****** END SYSTEM REQUIREMENTS *****/
  22.  
  23.  
  24. void setup(void)
  25. {
  26.     // put your setup code here, to run once:
  27.  
  28.     // Configure input pins with internal pull-up resistors
  29.     pinMode(1_PushButton_PIN_D2, INPUT_PULLUP);
  30.     pinMode(2_PushButton_PIN_D3, INPUT_PULLUP);
  31.  
  32.     // Configure output pins for elevator motor control
  33.     pinMode(ELEVATOR_UP_PIN_D4, OUTPUT);
  34.     pinMode(ELEVATOR_DOWN_PIN_D5, OUTPUT);
  35.  
  36.     // Initialize elevator motor pins to LOW (motor stopped)
  37.     digitalWrite(ELEVATOR_UP_PIN_D4, LOW);
  38.     digitalWrite(ELEVATOR_DOWN_PIN_D5, LOW);
  39.  
  40.     // Initialize button1
  41.     button1.begin();
  42.     // Add callback functions for button1
  43.     button1.onPressed(onButton1Pressed);
  44.     button1.onReleased(onButton1Released);
  45.  
  46.     // Initialize button2
  47.     button2.begin();
  48.     // Add callback functions for button2
  49.     button2.onPressed(onButton2Pressed);
  50.     button2.onReleased(onButton2Released);
  51. }
  52.  
  53.  
  54. void loop(void)
  55. {
  56.     // put your main code here, to run repeatedly:
  57.  
  58.     // Continuously read the status of button1
  59.     button1.read();
  60.     // Continuously read the status of button2
  61.     button2.read();
  62. }
  63.  
  64. // Callback function for button1 pressed event - elevator goes UP
  65. void onButton1Pressed(void)
  66. {
  67.     elevatorUp();
  68. }
  69.  
  70. // Callback function for button1 released event - elevator stops
  71. void onButton1Released(void)
  72. {
  73.     elevatorStop();
  74. }
  75.  
  76. // Callback function for button2 pressed event - elevator goes DOWN
  77. void onButton2Pressed(void)
  78. {
  79.     elevatorDown();
  80. }
  81.  
  82. // Callback function for button2 released event - elevator stops
  83. void onButton2Released(void)
  84. {
  85.     elevatorStop();
  86. }
  87.  
  88. // Function to move elevator UP
  89. void elevatorUp(void)
  90. {
  91.     // Set UP direction pin HIGH and DOWN direction pin LOW
  92.     digitalWrite(ELEVATOR_UP_PIN_D4, HIGH);
  93.     digitalWrite(ELEVATOR_DOWN_PIN_D5, LOW);
  94. }
  95.  
  96. // Function to move elevator DOWN
  97. void elevatorDown(void)
  98. {
  99.     // Set DOWN direction pin HIGH and UP direction pin LOW
  100.     digitalWrite(ELEVATOR_UP_PIN_D4, LOW);
  101.     digitalWrite(ELEVATOR_DOWN_PIN_D5, HIGH);
  102. }
  103.  
  104. // Function to stop the elevator
  105. void elevatorStop(void)
  106. {
  107.     // Set both direction pins LOW to stop the motor
  108.     digitalWrite(ELEVATOR_UP_PIN_D4, LOW);
  109.     digitalWrite(ELEVATOR_DOWN_PIN_D5, LOW);
  110. }
  111.  
  112. /* END CODE */
  113.  
Advertisement
Add Comment
Please, Sign In to add comment