tim004 tim004
/
Lab6_Zad1_Priprema
AnesaD
main.cpp@0:0a9e290df947, 2014-04-09 (annotated)
- Committer:
- tim004
- Date:
- Wed Apr 09 22:32:27 2014 +0000
- Revision:
- 0:0a9e290df947
AnesaD
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tim004 | 0:0a9e290df947 | 1 | #include "mbed.h" |
tim004 | 0:0a9e290df947 | 2 | |
tim004 | 0:0a9e290df947 | 3 | BusOut seg(dp18, dp4, dp28, dp6, dp5, dp27, dp26); |
tim004 | 0:0a9e290df947 | 4 | BusOut dig(dp23, dp24, dp25); |
tim004 | 0:0a9e290df947 | 5 | DigitalOut decPoint(dp17); |
tim004 | 0:0a9e290df947 | 6 | InterruptIn tast1(dp1); |
tim004 | 0:0a9e290df947 | 7 | InterruptIn tast2(dp2); |
tim004 | 0:0a9e290df947 | 8 | |
tim004 | 0:0a9e290df947 | 9 | Timer timer; |
tim004 | 0:0a9e290df947 | 10 | Timer db1; |
tim004 | 0:0a9e290df947 | 11 | Timer db2; |
tim004 | 0:0a9e290df947 | 12 | Ticker tiker; // za reload |
tim004 | 0:0a9e290df947 | 13 | |
tim004 | 0:0a9e290df947 | 14 | int redniCifra; |
tim004 | 0:0a9e290df947 | 15 | int ispisCifra; |
tim004 | 0:0a9e290df947 | 16 | int prvaCifra, drugaCifra, trecaCifra; |
tim004 | 0:0a9e290df947 | 17 | int predefSeg[10] = {0x01, 0x4f, 0x12, 0x06, 0x4c, 0x24, 0x20, 0x0f, 0x00, 0x04}; |
tim004 | 0:0a9e290df947 | 18 | int chars[6] = {0x08, 0x60, 0x31, 0x42, 0x30, 0x38}; |
tim004 | 0:0a9e290df947 | 19 | bool stoped = true; |
tim004 | 0:0a9e290df947 | 20 | |
tim004 | 0:0a9e290df947 | 21 | void reload(){ |
tim004 | 0:0a9e290df947 | 22 | redniCifra = 3; |
tim004 | 0:0a9e290df947 | 23 | ispisCifra = predefSeg[prvaCifra]; |
tim004 | 0:0a9e290df947 | 24 | redniCifra = 5; |
tim004 | 0:0a9e290df947 | 25 | ispisCifra = predefSeg[drugaCifra]; |
tim004 | 0:0a9e290df947 | 26 | redniCifra = 6; |
tim004 | 0:0a9e290df947 | 27 | ispisCifra = predefSeg[trecaCifra]; |
tim004 | 0:0a9e290df947 | 28 | } |
tim004 | 0:0a9e290df947 | 29 | |
tim004 | 0:0a9e290df947 | 30 | void prikaz(float trenutno){ // provjeriti |
tim004 | 0:0a9e290df947 | 31 | int timerCifra[3] = {(int)(trenutno / 10.) % 10, (int)(trenutno) % 10, (int)(trenutno * 10.) % 10}; |
tim004 | 0:0a9e290df947 | 32 | for(int i = 1; i <= 4; i = i * 2){ |
tim004 | 0:0a9e290df947 | 33 | dig = ~i; |
tim004 | 0:0a9e290df947 | 34 | seg = predefSeg[timerCifra[i / 2] ]; |
tim004 | 0:0a9e290df947 | 35 | decPoint = (i == 2) ? 0 : 1; |
tim004 | 0:0a9e290df947 | 36 | tiker.attach_us(&reload, 1000); |
tim004 | 0:0a9e290df947 | 37 | } |
tim004 | 0:0a9e290df947 | 38 | } |
tim004 | 0:0a9e290df947 | 39 | |
tim004 | 0:0a9e290df947 | 40 | |
tim004 | 0:0a9e290df947 | 41 | void start(){ |
tim004 | 0:0a9e290df947 | 42 | if(db1.read_ms() > 200) { |
tim004 | 0:0a9e290df947 | 43 | if(stoped) { |
tim004 | 0:0a9e290df947 | 44 | timer.start(); |
tim004 | 0:0a9e290df947 | 45 | stoped = false; |
tim004 | 0:0a9e290df947 | 46 | } else { |
tim004 | 0:0a9e290df947 | 47 | timer.stop(); |
tim004 | 0:0a9e290df947 | 48 | stoped = true; |
tim004 | 0:0a9e290df947 | 49 | } |
tim004 | 0:0a9e290df947 | 50 | db1.reset(); |
tim004 | 0:0a9e290df947 | 51 | } |
tim004 | 0:0a9e290df947 | 52 | |
tim004 | 0:0a9e290df947 | 53 | } |
tim004 | 0:0a9e290df947 | 54 | |
tim004 | 0:0a9e290df947 | 55 | void reset(){ |
tim004 | 0:0a9e290df947 | 56 | if(db2.read_ms() > 200){ |
tim004 | 0:0a9e290df947 | 57 | timer.reset(); |
tim004 | 0:0a9e290df947 | 58 | timer.stop(); |
tim004 | 0:0a9e290df947 | 59 | stoped = true; |
tim004 | 0:0a9e290df947 | 60 | prikaz(0.00); |
tim004 | 0:0a9e290df947 | 61 | db2.reset(); |
tim004 | 0:0a9e290df947 | 62 | } |
tim004 | 0:0a9e290df947 | 63 | } |
tim004 | 0:0a9e290df947 | 64 | |
tim004 | 0:0a9e290df947 | 65 | int main() |
tim004 | 0:0a9e290df947 | 66 | { |
tim004 | 0:0a9e290df947 | 67 | db1.start(); |
tim004 | 0:0a9e290df947 | 68 | db2.start(); |
tim004 | 0:0a9e290df947 | 69 | tast1.rise(&start); |
tim004 | 0:0a9e290df947 | 70 | tast2.rise(&reset); |
tim004 | 0:0a9e290df947 | 71 | while(1){ |
tim004 | 0:0a9e290df947 | 72 | prikaz(timer.read()); |
tim004 | 0:0a9e290df947 | 73 | } |
tim004 | 0:0a9e290df947 | 74 | } |