Is there a way that can store the input until the Arduino has time to check it?
No, there is no way to remember/buffer input changes within the Arduino (You could use a flipfop IC like JRobert wrote. That can give you that functionality). But there are interrupts, that you can use with pins. A triggered interrupt will really interrupt the main code from running and execute its corresponding ISR (Interrupt Service Routine), to handle the interrupt cause, and then returning to execute the main code. A microcontoller has many different interrupts, each one connected to its special hardware. There are interrupts for the Serial interface, for SPI, I2C, and also some connected to the External Interrupt pins or the PinChange Interrupt (these last two could be used with your button). So this would not "store" the input change, but it will interrupt the main code to immediately act upon the input change. So that's a different principle.
If you want to bind your button to an interrupt, you could just stay in the Arduino Framework and use the attachInterrupt()
function. There are many tutorials online for that. Keep in mind, that you should never do long things inside an ISR, and functions like delay()
won't work there.
That said, most likely it is not really needed to use interrupts with buttons. Humans are rather slow, thus each button press will last in the ballpark of 100ms or longer.
You could now say, that your code is doing things longer than 100ms. But here the rabbit is buried (literal translation of a german saying, meaning "there is the problem"). When starting with Arduino, one is doing many blocking things, like delay()
or blocking while loops. These are often very easy to implement, but nothing else will be running during these things.
Instead you should divide up your actions into small parts. When it is time to do something, you are doing that small part and exit fast. This enables other code to run in between. A good example is the BlinkWithoutDelay
example. The normal blink example uses delay()
, which blocks everything else. Instead you can use the millis()
function as a clock and only take action, when it is time to do so, otherwise to further fast. Much like you would bake a pizza in your oven. You won't sit in front of the oven, waiting for the pizza to be ready. You would do something else and regularly look at your clock, if it is time to take the pizza out.
You didn't show your code, so we cannot advice you more in that direction. But you can find many tutorials about it, if you search for terms like Arduino blink without delay
or Arduino millis tutorial
.