#include "LowPower.h"
// set the corresponding snooze/off button pin number
const int buttonPin = 2;
// set the four corresponding LED pin numbers
const int ledPin1 = 4;
const int ledPin2 = 3;
const int ledPin3 = 5;
const int ledPin4 = 6;
// set the corresponding piezo buzzer pin
const int alarmPin = 9;
// initialize timer variables
int nappingTime = 0;
String strNappingTime = "";
// initialize the snooze/off button state
int buttonState = 0;
void setup() {
// initialize the LED pins as outputs:
Serial.begin(9600);
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
pinMode(ledPin4, OUTPUT);
// initialize the snooze button pin as an input:
pinMode(buttonPin, INPUT);
// user inputs napping time
Serial.println("How long do you want to set the timer for?");
while (Serial.available() == 0) { }
strNappingTime = Serial.readString();
nappingTime = strNappingTime.toInt();
delay (nappingTime * 60000);
}
void loop() {
// after time is up, reads the state of the snooze button:
buttonState = digitalRead(buttonPin);
// checks to see if the snooze/off button is pressed:
if (buttonState == LOW) {
// alarm rings
// LEDs flash
tone(alarmPin, 3000);
digitalWrite(ledPin1, HIGH);
digitalWrite(ledPin2, HIGH);
digitalWrite(ledPin3, HIGH);
digitalWrite(ledPin4, HIGH);
delay (500);
noTone(alarmPin);
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, LOW);
digitalWrite(ledPin3, LOW);
digitalWrite(ledPin4, LOW);
delay(500);
}
// if the snooze button is pressed
else {
// alarm stops
// turns LEDs off
noTone(alarmPin);
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, LOW);
digitalWrite(ledPin3, LOW);
digitalWrite(ledPin4, LOW);
delay (1000);
// shuts down until reset button is pressed
LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);
}
}
Comments
Please log in or sign up to comment.