![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
An alarm clock that wakes you up naturally!
Dependencies: 4DGL-uLCD-SE DebounceIn mbed RPCInterface
main.cpp
- Committer:
- ooglezoiden
- Date:
- 2017-03-16
- Revision:
- 0:397faf7a0a52
- Child:
- 1:57e06832197a
File content as of revision 0:397faf7a0a52:
#include "mbed.h" #include "uLCD_4DGL.h" #include "DebounceIn.h" Timeout alarm; Timer t; PwmOut lights(p25); uLCD_4DGL uLCD(p9,p10,p11); AnalogIn photocell(p15); DebounceIn pb1(p8); DebounceIn pb2(p7); Serial blue(p28,p27); void lightsOn(){ uLCD.cls(); uLCD.printf("Turning on lights!"); //lights = 1; while(lights<=0.99f){ lights = lights + .01f; wait(1); } while(1);//do nothing until reset } void lightMode(){ uLCD.cls(); uLCD.printf("not bright out yet!\n"); while(photocell.read() < .9f){ uLCD.cls(); uLCD.printf("not bright out yet!\n"); } lightsOn(); } void timerMode(int time){ alarm.attach(&lightsOn, time); t.start(); float curTime; while(1){ uLCD.cls(); curTime = t.read(); uLCD.printf("%f secs since alarm set.\n", curTime); } } int getTime(){ bool done = false; int time[3] = {0,0,0}; int modifying = 0; uLCD.cls(); uLCD.printf("Connect Bluetooth now.\n\n"); uLCD.printf("Up and down change time\n left and right select unit.\n"); //uLCD.printf("This message will display for five seconds. Then input your desired time."); wait(5); char bnum = 0; char bhit = 0; while(!done){ uLCD.cls(); uLCD.printf("Current timer will last:\n"); uLCD.printf("%d hours, %d mins, %d secs\n", time[2], time[1], time[0]); uLCD.printf("You are now modifying: "); if(modifying == 0){ uLCD.printf("Secs\n"); } else if(modifying == 1){ uLCD.printf("Mins\n"); } else if(modifying == 2){ uLCD.printf("Hours\n"); } uLCD.printf("Press 1 to set the timer to the current value.\n"); if(blue.getc()=='!'){ if(blue.getc()=='B'){ bnum = blue.getc();//button number bhit = blue.getc();//1=hit, 0=release if(blue.getc()==char(~('!' + 'B' + bnum + bhit))){//checksum switch(bnum){ case '1'://number button 1 if(bhit == '1'){ done = true; } break; case '5'://up arrow if(bhit=='1'){ time[modifying]++; } break; case '6'://down arrow if(bhit=='1'&&time[modifying]>0){ time[modifying]--; } break; case '7'://left arrow if(bhit=='1'&&modifying>0){ modifying--; } break; case '8'://right arrow if(bhit=='1'&&modifying<2){ modifying++; } break; } } } } } return time[0] + time[1] * 60 + time[2] * 60 * 60; } int main() { lights = 0; uLCD.printf("LIGHT_ALARM V1.0 Donn Green\n\n"); uLCD.printf("Press Button 1 to begin light activation mode\n"); uLCD.printf("Press Button 2 to begin timer activation mode\n"); pb1.mode(PullDown); pb2.mode(PullDown); lights.period(1.0f/25000.0f); while(!(pb1||pb2)){ //do nothing until a button is pressed } if(pb1){ lightMode(); } else if(pb2){ int time = getTime(); timerMode(time); } }