Successfully Added To Cart

EXERCISE SOLUTIONS:

Question 1

In order to display the time since the alarm was last triggered, we need to create a new variable to hold the value of millis(). Any time the alarm is enabled, we set this variable to the output of millis(). Then, in the updateLCD() function, we print this variable, divided by 1000 to show the seconds since the alarm was last enabled.

Question 2

To have the alarm only trigger if both the PIR and laser have tripped, we have to change the line if(buzzerPIR || buzzerLaser) to if(buzzerPIR && buzzerLaser). The && instead of the || will ensure both variables are true, rather than simply one or the other.

Question 3

We can have three different alarms play by adding else if statements to the if(buzzerPIR || buzzerLaser) block of code. We need to add two if-else's. The original if will test if only buzzerPIR is true, one else if if only buzzerLaser is true, and one else if if both are true. Inside these three, you can change the alarm to play any pattern of notes you would like!