Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of 08-timer_alarm_state by
main.cpp@0:425c87a33e63, 2018-01-15 (annotated)
- Committer:
- martinale
- Date:
- Mon Jan 15 18:05:34 2018 +0000
- Revision:
- 0:425c87a33e63
- Child:
- 1:eddde0361c0a
Test
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
martinale | 0:425c87a33e63 | 1 | |
martinale | 0:425c87a33e63 | 2 | #include "mbed.h" |
martinale | 0:425c87a33e63 | 3 | #include "BtnEventM0.h" |
martinale | 0:425c87a33e63 | 4 | |
martinale | 0:425c87a33e63 | 5 | Serial pc(USBTX, USBRX); |
martinale | 0:425c87a33e63 | 6 | // LSB MSB |
martinale | 0:425c87a33e63 | 7 | BusOut lb(P1_13,P1_12,P1_7,P1_6,P1_4,P1_3,P1_1,P1_0,LED4,LED3,LED2,LED1); |
martinale | 0:425c87a33e63 | 8 | |
martinale | 0:425c87a33e63 | 9 | BtnEventM0 sw4(P1_16), sw3(P0_23), sw1(P0_10), sw2(P0_15); |
martinale | 0:425c87a33e63 | 10 | |
martinale | 0:425c87a33e63 | 11 | int blinkIdx = 0; |
martinale | 0:425c87a33e63 | 12 | int hh=0, mm=0; |
martinale | 0:425c87a33e63 | 13 | |
martinale | 0:425c87a33e63 | 14 | void ShowMode(); |
martinale | 0:425c87a33e63 | 15 | void ShowTime(); |
martinale | 0:425c87a33e63 | 16 | |
martinale | 0:425c87a33e63 | 17 | int main() |
martinale | 0:425c87a33e63 | 18 | { |
martinale | 0:425c87a33e63 | 19 | pc.baud(500000); |
martinale | 0:425c87a33e63 | 20 | sw4.Init(); sw3.Init(); sw1.Init(); sw2.Init(); |
martinale | 0:425c87a33e63 | 21 | ShowMode(); |
martinale | 0:425c87a33e63 | 22 | ShowTime(); |
martinale | 0:425c87a33e63 | 23 | |
martinale | 0:425c87a33e63 | 24 | Timer t1; t1.start(); |
martinale | 0:425c87a33e63 | 25 | while(1) |
martinale | 0:425c87a33e63 | 26 | { |
martinale | 0:425c87a33e63 | 27 | if( sw4.CheckFlag() ) { |
martinale | 0:425c87a33e63 | 28 | if( blinkIdx==-1 ) |
martinale | 0:425c87a33e63 | 29 | blinkIdx=0; |
martinale | 0:425c87a33e63 | 30 | else if( blinkIdx==0 ) |
martinale | 0:425c87a33e63 | 31 | blinkIdx=3; |
martinale | 0:425c87a33e63 | 32 | else if( blinkIdx==3 ) |
martinale | 0:425c87a33e63 | 33 | blinkIdx=-1; |
martinale | 0:425c87a33e63 | 34 | ShowMode(); |
martinale | 0:425c87a33e63 | 35 | } |
martinale | 0:425c87a33e63 | 36 | if( t1.read_ms()>150 ) { |
martinale | 0:425c87a33e63 | 37 | t1.reset(); |
martinale | 0:425c87a33e63 | 38 | if( blinkIdx==-1 ) { |
martinale | 0:425c87a33e63 | 39 | mm++; |
martinale | 0:425c87a33e63 | 40 | if( mm>29 ) |
martinale | 0:425c87a33e63 | 41 | { mm=0; hh++; } |
martinale | 0:425c87a33e63 | 42 | ShowTime(); |
martinale | 0:425c87a33e63 | 43 | } |
martinale | 0:425c87a33e63 | 44 | } |
martinale | 0:425c87a33e63 | 45 | if( blinkIdx==0 ) { |
martinale | 0:425c87a33e63 | 46 | if( sw3.CheckFlag() ) { |
martinale | 0:425c87a33e63 | 47 | hh++; |
martinale | 0:425c87a33e63 | 48 | if( hh>20 ) hh=0; |
martinale | 0:425c87a33e63 | 49 | ShowTime(); |
martinale | 0:425c87a33e63 | 50 | } |
martinale | 0:425c87a33e63 | 51 | } |
martinale | 0:425c87a33e63 | 52 | if( blinkIdx==3 ) { |
martinale | 0:425c87a33e63 | 53 | if( sw3.CheckFlag() ) { |
martinale | 0:425c87a33e63 | 54 | mm++; |
martinale | 0:425c87a33e63 | 55 | if( mm>30 ) mm=0; |
martinale | 0:425c87a33e63 | 56 | ShowTime(); |
martinale | 0:425c87a33e63 | 57 | } |
martinale | 0:425c87a33e63 | 58 | } |
martinale | 0:425c87a33e63 | 59 | } |
martinale | 0:425c87a33e63 | 60 | } |
martinale | 0:425c87a33e63 | 61 | |
martinale | 0:425c87a33e63 | 62 | void ShowMode() |
martinale | 0:425c87a33e63 | 63 | { |
martinale | 0:425c87a33e63 | 64 | if( blinkIdx==-1 ) |
martinale | 0:425c87a33e63 | 65 | // 1..in die erste Zeile schreiben |
martinale | 0:425c87a33e63 | 66 | pc.printf("1 Clock running\n"); |
martinale | 0:425c87a33e63 | 67 | if( blinkIdx==0 ) |
martinale | 0:425c87a33e63 | 68 | pc.printf("1 Edit hh\n"); |
martinale | 0:425c87a33e63 | 69 | if( blinkIdx==3 ) |
martinale | 0:425c87a33e63 | 70 | pc.printf("1 Edit mm\n"); |
martinale | 0:425c87a33e63 | 71 | // 3..BlinkIndex setzen |
martinale | 0:425c87a33e63 | 72 | // es blinken immer 2 Zeichen ( Spalten ) beginnend mit blinkIdx |
martinale | 0:425c87a33e63 | 73 | pc.printf("3 %d\n", blinkIdx); |
martinale | 0:425c87a33e63 | 74 | } |
martinale | 0:425c87a33e63 | 75 | |
martinale | 0:425c87a33e63 | 76 | void ShowTime() |
martinale | 0:425c87a33e63 | 77 | { |
martinale | 0:425c87a33e63 | 78 | // 2..in die 2te Zeile schreiben |
martinale | 0:425c87a33e63 | 79 | pc.printf("2 %02d:%02d\n",hh,mm); |
martinale | 0:425c87a33e63 | 80 | } |
martinale | 0:425c87a33e63 | 81 | |
martinale | 0:425c87a33e63 | 82 | |
martinale | 0:425c87a33e63 | 83 | |
martinale | 0:425c87a33e63 | 84 | |
martinale | 0:425c87a33e63 | 85 | |
martinale | 0:425c87a33e63 | 86 |