I am making an elevator simulation system using Arduino Uno. I have written a code for 4 floor elevator system without using interrupts.Here is the link of my project which is made on an online simulator
I want to read inputs from the buttons while the loop() routine is running.
Tell me what changes should be made in the circuit as well as the code.
Interrupts are intended for use where things happen in the microseconds range. Pushing a button faster than about 5Hz (200 Milliseconds) is only possible for Superman. DON'T USE INTERRUPTS, use polling instead. Each time through loop(), check the status of the buttons and act on any changes accordingly.
It is most unlikely that you need to use interrupts but you will need to get rid of the delay()s in your code so that you can read the buttons each time through loop(). Take a look at Several things at the same time
Change your loop( ) function so that it runs more often, without using delays.
If you really want to use an interrupt, this is what you should do. Connect the buttons to a set of flipflop gates ( one each ), so that a momentary press of the button sets the flip flop ( this is what you would want an elevator button to do ). Connect the output of the flip flop to the microcontroller, and also connect the output of the flip flop to a 4-input OR gate, for which you connect the output of the OR gate to the interrupt of the Arduino. This will result in an interrupt the first time any of the buttons is pressed.
You will need further arrangements if you need to reset part of the circuit to detect subsequent button-presses. I will leave that as an exercise for you.
Definitely overkill to use interrupts for human-scale events (rather than microsecond
scale events), but you can do it using pin change interrupts (PCINT). You have to write
the interrupt handler(s) yourself, or find a library to make it easy.