/********* 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: Button Interrupt
- Source Code compiled for: Arduino Uno
- Source Code created on: 2023-12-28 00:52:14
********* Pleasedontcode.com **********/
/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
/* 4 floor lift, when call button press from any */
/* floor lift reaches there and floor sensor detects */
/* lift car the motor will off. when call button */
/* pressed from another floor lift starts move until */
/* floor sensor detects lift car on that floor */
/****** END SYSTEM REQUIREMENTS *****/
/****** DEFINITION OF LIBRARIES *****/
#include
#include
/****** FUNCTION PROTOTYPES *****/
void setup(void);
void loop(void);
/***** DEFINITION OF DIGITAL INPUT PINS *****/
const uint8_t Callbutton_PushButton_PIN_D2 = 2;
/****** DEFINITION OF LIBRARY CLASS INSTANCES*****/
EasyButton button(Callbutton_PushButton_PIN_D2); // Instance of the EasyButton class
/****** FUNCTION PROTOTYPES *****/
void motorOff();
void moveToFloor(int floor);
void setup(void)
{
// Initialize Serial for debugging purposes.
Serial.begin(115200);
Serial.println();
Serial.println(">>> EasyButton interrupts example <<<");
// Initialize the button.
button.begin();
// Define button callback functions
button.onPressed([]() {
motorOff();
});
button.onSequence(2, 1500, []() {
button.disableInterrupt(); // Disable interrupt during movement
moveToFloor(2);
delay(1000); // Wait for the floor sensor to detect the lift car
button.enableInterrupt([]() {}); // Re-enable interrupt after movement is complete
});
// Enable interrupt if supported by the board
if (button.supportsInterrupt())
{
button.enableInterrupt([]() {});
Serial.println("Button will be used through interrupts");
}
}
void loop(void)
{
// put your main code here, to run repeatedly:
button.read(); // Read button state and trigger callbacks if necessary
}
void motorOff()
{
// Code to turn off the motor
Serial.println("Motor off");
}
void moveToFloor(int floor)
{
// Code to move the lift to the desired floor
Serial.print("Moving to floor ");
Serial.println(floor);
}