pp
Dependencies: mbed
main.cpp@2:6b4dda997dc0, 2015-12-05 (annotated)
- Committer:
- Peeraya
- Date:
- Sat Dec 05 14:32:27 2015 +0000
- Revision:
- 2:6b4dda997dc0
- Parent:
- 1:ba7154d2d7ca
- Child:
- 3:dc88b52d526c
button ok
Who changed what in which revision?
User | Revision | Line number | New 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); |
NamSom | 1:ba7154d2d7ca | 10 | int mode=0; |
NamSom | 1:ba7154d2d7ca | 11 | int main() |
NamSom | 1:ba7154d2d7ca | 12 | { |
NamSom | 1:ba7154d2d7ca | 13 | b.mode(PullUp); |
Peeraya | 2:6b4dda997dc0 | 14 | int n=0; |
Peeraya | 0:b2064b3558b6 | 15 | // DisplayTime(); |
NamSom | 1:ba7154d2d7ca | 16 | display.Displayset(0x77,5,5,5); |
NamSom | 1:ba7154d2d7ca | 17 | while(1) |
NamSom | 1:ba7154d2d7ca | 18 | { |
Peeraya | 2:6b4dda997dc0 | 19 | if(b==0b011){n=1;} |
Peeraya | 2:6b4dda997dc0 | 20 | else if(b==0b101){n=2;} |
Peeraya | 2:6b4dda997dc0 | 21 | else if(b==0b110){n=3;} |
Peeraya | 2:6b4dda997dc0 | 22 | else n=0; |
Peeraya | 2:6b4dda997dc0 | 23 | display.getButtonState(n); |
Peeraya | 2:6b4dda997dc0 | 24 | if(display.checkButton1()==1){led=0b100;mode=1;} |
Peeraya | 2:6b4dda997dc0 | 25 | else if(display.checkButton2()==1){led=0b010;mode=2;} |
Peeraya | 2:6b4dda997dc0 | 26 | else if(display.checkButton3()==1){led=0b001;mode=3;} |
NamSom | 1:ba7154d2d7ca | 27 | |
Peeraya | 2:6b4dda997dc0 | 28 | wait_ms(100); |
Peeraya | 2:6b4dda997dc0 | 29 | |
Peeraya | 2:6b4dda997dc0 | 30 | //printf("%d\n",mode); |
Peeraya | 2:6b4dda997dc0 | 31 | |
Peeraya | 2:6b4dda997dc0 | 32 | wait_ms(100); |
NamSom | 1:ba7154d2d7ca | 33 | } |
Peeraya | 0:b2064b3558b6 | 34 | } |
Peeraya | 0:b2064b3558b6 | 35 | |
Peeraya | 0:b2064b3558b6 | 36 | void DisplayTime() |
Peeraya | 0:b2064b3558b6 | 37 | { |
Peeraya | 0:b2064b3558b6 | 38 | int sec=0,min=35,hour=15,day=7,date=5,month=12,year=15; |
Peeraya | 0:b2064b3558b6 | 39 | int a_hour=15,a_min=36; |
Peeraya | 0:b2064b3558b6 | 40 | |
Peeraya | 0:b2064b3558b6 | 41 | myrtc.settime(sec,min,hour,day,date,month,year); |
Peeraya | 0:b2064b3558b6 | 42 | |
Peeraya | 0:b2064b3558b6 | 43 | printf("time set : %d:%d:%d day : %d date set : %d:%d:%d\n ",hour,min,sec,day,date,month,year); |
Peeraya | 0:b2064b3558b6 | 44 | |
Peeraya | 0:b2064b3558b6 | 45 | while(1) { |
Peeraya | 0:b2064b3558b6 | 46 | myrtc.gettime(&sec,&min,&hour,&day,&date,&month,&year); |
Peeraya | 0:b2064b3558b6 | 47 | printf("time read : %d:%d:%d day : %d date read : %d:%d:%d\n ",hour,min,sec,day,date,month,year); |
Peeraya | 0:b2064b3558b6 | 48 | |
Peeraya | 0:b2064b3558b6 | 49 | display.setColon(1); |
Peeraya | 0:b2064b3558b6 | 50 | |
Peeraya | 0:b2064b3558b6 | 51 | if(((hour-(hour%10))/10)>0) |
Peeraya | 0:b2064b3558b6 | 52 | { |
Peeraya | 0:b2064b3558b6 | 53 | display.write(0, (hour-(hour%10))/10); |
Peeraya | 0:b2064b3558b6 | 54 | display.write(1, hour%10); |
Peeraya | 0:b2064b3558b6 | 55 | display.write(2, (min-(min%10))/10); |
Peeraya | 0:b2064b3558b6 | 56 | display.write(3, min%10); |
Peeraya | 0:b2064b3558b6 | 57 | } |
Peeraya | 0:b2064b3558b6 | 58 | else if(((hour-(hour%10))/10)==0 ) |
Peeraya | 0:b2064b3558b6 | 59 | { |
Peeraya | 0:b2064b3558b6 | 60 | display.write(0, 0xFF); |
Peeraya | 0:b2064b3558b6 | 61 | display.write(1, hour%10); |
Peeraya | 0:b2064b3558b6 | 62 | display.write(2, (min-(min%10))/10); |
Peeraya | 0:b2064b3558b6 | 63 | display.write(3, min%10); |
Peeraya | 0:b2064b3558b6 | 64 | } |
Peeraya | 0:b2064b3558b6 | 65 | if(hour==a_hour && min==a_min){buzzer=1;wait(2);buzzer=0;} |
Peeraya | 0:b2064b3558b6 | 66 | |
Peeraya | 0:b2064b3558b6 | 67 | } |
Peeraya | 0:b2064b3558b6 | 68 | } |