pp

Dependencies:   mbed

Committer:
Peeraya
Date:
Sat Dec 05 16:43:40 2015 +0000
Revision:
3:dc88b52d526c
Parent:
2:6b4dda997dc0
Child:
4:a61cdd4e7afa
alarm with super snooze

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Peeraya 0:b2064b3558b6 1 #include "mbed.h"
Peeraya 0:b2064b3558b6 2 #include "DS1307.h"
Peeraya 0:b2064b3558b6 3 #include "DigitDisplay.h"
Peeraya 0:b2064b3558b6 4
Peeraya 0:b2064b3558b6 5 DS1307 myrtc(I2C_SDA,I2C_SCL);
Peeraya 0:b2064b3558b6 6 DigitDisplay display(D7,D8);
Peeraya 0:b2064b3558b6 7 DigitalOut buzzer(D6);
NamSom 1:ba7154d2d7ca 8 BusIn b(D9,D10,D11);
NamSom 1:ba7154d2d7ca 9 BusOut led(D2,D3,D4,D5);
Peeraya 3:dc88b52d526c 10 AnalogIn analog_value(A2);
Peeraya 3:dc88b52d526c 11
Peeraya 3:dc88b52d526c 12 void DisplayTime();
Peeraya 3:dc88b52d526c 13
NamSom 1:ba7154d2d7ca 14 int mode=0;
NamSom 1:ba7154d2d7ca 15 int main()
NamSom 1:ba7154d2d7ca 16 {
NamSom 1:ba7154d2d7ca 17 b.mode(PullUp);
Peeraya 3:dc88b52d526c 18 int sec=45,min=59,hour=6,day=7,date=5,month=12,year=15;
Peeraya 3:dc88b52d526c 19 int n=0,opt=1,p=0,ten_hour,nu_hour,ten_min,nu_min,hour_a=7,min_a=0;
Peeraya 3:dc88b52d526c 20 float mea;
Peeraya 3:dc88b52d526c 21
Peeraya 3:dc88b52d526c 22 myrtc.settime(sec,min,hour,day,date,month,year);
Peeraya 3:dc88b52d526c 23 //DisplayTime();
Peeraya 3:dc88b52d526c 24 //display.Displayset((hour-(hour%10))/10,hour%10,(min-(min%10))/10,min%10);
NamSom 1:ba7154d2d7ca 25 while(1)
Peeraya 3:dc88b52d526c 26 {
Peeraya 3:dc88b52d526c 27 mea=analog_value.read();
Peeraya 2:6b4dda997dc0 28 if(b==0b011){n=1;}
Peeraya 2:6b4dda997dc0 29 else if(b==0b101){n=2;}
Peeraya 2:6b4dda997dc0 30 else if(b==0b110){n=3;}
Peeraya 2:6b4dda997dc0 31 else n=0;
Peeraya 2:6b4dda997dc0 32 display.getButtonState(n);
Peeraya 2:6b4dda997dc0 33 if(display.checkButton1()==1){led=0b100;mode=1;}
Peeraya 2:6b4dda997dc0 34 else if(display.checkButton2()==1){led=0b010;mode=2;}
Peeraya 2:6b4dda997dc0 35 else if(display.checkButton3()==1){led=0b001;mode=3;}
NamSom 1:ba7154d2d7ca 36
Peeraya 2:6b4dda997dc0 37 wait_ms(100);
Peeraya 2:6b4dda997dc0 38
Peeraya 2:6b4dda997dc0 39 //printf("%d\n",mode);
Peeraya 2:6b4dda997dc0 40
Peeraya 2:6b4dda997dc0 41 wait_ms(100);
Peeraya 3:dc88b52d526c 42
Peeraya 3:dc88b52d526c 43 if(display.checkButton3()==1)
Peeraya 3:dc88b52d526c 44 {
Peeraya 3:dc88b52d526c 45 p++;
Peeraya 3:dc88b52d526c 46 if(p==10){p=0;}
Peeraya 3:dc88b52d526c 47 printf("%d\n",p);
Peeraya 3:dc88b52d526c 48 if(p%2==0){opt=1;}
Peeraya 3:dc88b52d526c 49 if(p%2==1){opt=2;}
Peeraya 3:dc88b52d526c 50 }
Peeraya 3:dc88b52d526c 51
Peeraya 0:b2064b3558b6 52 myrtc.gettime(&sec,&min,&hour,&day,&date,&month,&year);
Peeraya 0:b2064b3558b6 53
Peeraya 3:dc88b52d526c 54 if(opt==1)
Peeraya 0:b2064b3558b6 55 {
Peeraya 3:dc88b52d526c 56 display.setColon(1);
Peeraya 3:dc88b52d526c 57 display.Displayset((hour-(hour%10))/10,hour%10,(min-(min%10))/10,min%10);
Peeraya 0:b2064b3558b6 58 }
Peeraya 3:dc88b52d526c 59 if(opt==2)
Peeraya 3:dc88b52d526c 60 {
Peeraya 3:dc88b52d526c 61 ten_hour=(hour_a-(hour_a%10))/10;
Peeraya 3:dc88b52d526c 62 nu_hour=hour_a%10;
Peeraya 3:dc88b52d526c 63 ten_min=(min_a-(min_a%10))/10;
Peeraya 3:dc88b52d526c 64 nu_min=min_a%10;
Peeraya 3:dc88b52d526c 65 display.Displayset(ten_hour,nu_hour,ten_min,nu_min);
Peeraya 0:b2064b3558b6 66
Peeraya 3:dc88b52d526c 67 if(display.checkButton1()==1){hour_a++;}
Peeraya 3:dc88b52d526c 68 if(display.checkButton2()==1){min_a++;}
Peeraya 3:dc88b52d526c 69
Peeraya 3:dc88b52d526c 70 if(hour_a==24){hour_a=0;}
Peeraya 3:dc88b52d526c 71 if(min_a==60){min_a=0;}
Peeraya 3:dc88b52d526c 72
Peeraya 3:dc88b52d526c 73 }
Peeraya 3:dc88b52d526c 74 if(hour==hour_a&&min==min_a){buzzer=1;}
Peeraya 3:dc88b52d526c 75 else{buzzer=0;}
Peeraya 3:dc88b52d526c 76
Peeraya 3:dc88b52d526c 77 printf("%f\n",mea);
Peeraya 3:dc88b52d526c 78 if(mea>=0.65){min_a=min_a+1;}
Peeraya 3:dc88b52d526c 79
Peeraya 3:dc88b52d526c 80 }
Peeraya 3:dc88b52d526c 81 }