Lock Box

EXERCISE SOLUTIONS:

Question 1

This solution will utilize the millis() command. This command returns the time in milliseconds since the Uno R3 was turned on. We can use this by saving the time in a variable, and comparing the variable to the current time to determine elapsed time.

First, we will add two variables. One will hold the time at which the device was last unlocked. The other will be a constant for how many milliseconds until the device is locked again. To turn seconds into milliseconds, multiply by 1000. The code below sets the timeout to 60 seconds, which is 60,000 milliseconds.

long unlockTime;
const long lockTimeout = 60000;

Next, we add the line unlockTime = millis(); in the following if statement: