// Pin connected to the potentiometer
const int potPin = A0;
// Stores sleep state
String lastSleepStatus = "";
void setup() {
Serial.begin(9600);
pinMode(potPin, INPUT);
Serial.println("Sleep Monitor Initialized");
}
void loop() {
// Read the potentiometer
int potValue = analogRead(potPin);
String currentSleepStatus;
// Simulate the different sleep states of the pet
if (potValue < 256) {
currentSleepStatus = "awake";
} else if (potValue < 512) {
currentSleepStatus = "light";
} else if (potValue < 768) {
currentSleepStatus = "deep";
} else {
currentSleepStatus = "REM";
}
// Output current sleep state
Serial.println("Current sleep status: " + currentSleepStatus);
// Check if sleep was interrupted
if (lastSleepStatus == "deep" && currentSleepStatus == "awake") {
Serial.println("Sleep was interrupted");
}
lastSleepStatus = currentSleepStatus;
delay(500);
}