Description:
For this assignment I wanted to tackle the biggest painpoint in my life: waking up in the morning. I decided to use a daily object: the pillow, to wake a person up. Every night when the person sleeps on the pillow, the pillow will check if the person is awake after 8 hours. After 8 hours it will start ringing to wake the person up. I tried to hook up a photocell to the circuit, so that if it is 8 hours later and it is daylight time, the pillow plays a harsher tune. But I was unable to wire the photoresistor to the pillow, due to lack of long cables. I think that would be a great addition.
Code:
/* Program to wake up a person, if he is still sleeping on his pillow after 8 hours
*/
int potPin = 0; // select the input pin for the potentiometer
int speakerOut = 7;
int FSRPin = 1;
int photopin = 2;
int potval = 0;
int FSRval =0;
int photoval = 0;
int multiplier = 1000;
byte names[] = {'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C'};
int tones[] = {1915, 1700, 1519, 1432, 1275, 1136, 1014, 956};
byte melody[] = "2d2a1f2c2d2a2d2c2f2d2a2c2d2a1f2c2d2a2a2g2p8p8p8p";
// count length: 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0
// 10 20 30
int count = 0;
int count2 = 0;
int count3 = 0;
int MAX_COUNT = 24;
int statePin = LOW;
void setup() {
pinMode(speakerOut, OUTPUT);
Serial.begin(9600);
}
void loop() {
//delay for the time set
digitalWrite(speakerOut, LOW);
potval = analogRead(potPin);
//Serial.println(potval);
//wait for 8 hours
delay(28800000);
//after 8 hours if person is still sleeping play alarm
if (potval>10){
for (count = 0; count < MAX_COUNT; count++) {
statePin = !statePin;
//digitalWrite(ledPin, statePin);
for (count3 = 0; count3 <= (melody[count*2] - 48) * 30; count3++) {
for (count2=0;count2<8;count2++) {
if (names[count2] == melody[count*2 + 1]) {
digitalWrite(speakerOut,HIGH);
delayMicroseconds(tones[count2]);
digitalWrite(speakerOut, LOW);
delayMicroseconds(tones[count2]);
}
if (melody[count*2 + 1] == 'p') {
// make a pause of a certain size
digitalWrite(speakerOut, 0);
}
}
}
}
}
}
- Login to post comments