Benjamin Ramić
/
LV2_Grupa8_Tim8_Zadatak2
Benjamin Hrustemović Benjamin Ramić
main.cpp@0:d063a3cae27e, 2016-03-14 (annotated)
- Committer:
- 2016US_BenjaminRamic
- Date:
- Mon Mar 14 20:13:04 2016 +0000
- Revision:
- 0:d063a3cae27e
LV2_US_Grupa8_Tim8
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
2016US_BenjaminRamic | 0:d063a3cae27e | 1 | #include "mbed.h" |
2016US_BenjaminRamic | 0:d063a3cae27e | 2 | #define dp23 P0_0 |
2016US_BenjaminRamic | 0:d063a3cae27e | 3 | |
2016US_BenjaminRamic | 0:d063a3cae27e | 4 | DigitalIn taster1(dp1); |
2016US_BenjaminRamic | 0:d063a3cae27e | 5 | DigitalIn taster2(dp2); |
2016US_BenjaminRamic | 0:d063a3cae27e | 6 | |
2016US_BenjaminRamic | 0:d063a3cae27e | 7 | BusOut lediceDisplej (dp26, dp27, dp5, dp6, dp28, dp4, dp18); |
2016US_BenjaminRamic | 0:d063a3cae27e | 8 | int izlazi[] = {121, 36, 48, 25, 18, 2, 120, 0, 16, 64}; |
2016US_BenjaminRamic | 0:d063a3cae27e | 9 | BusOut ukljuci(dp23, dp24, dp25); |
2016US_BenjaminRamic | 0:d063a3cae27e | 10 | |
2016US_BenjaminRamic | 0:d063a3cae27e | 11 | int taster1Prethodno = 0; |
2016US_BenjaminRamic | 0:d063a3cae27e | 12 | int taster2Prethodno = 0; |
2016US_BenjaminRamic | 0:d063a3cae27e | 13 | int broj = 0; |
2016US_BenjaminRamic | 0:d063a3cae27e | 14 | DigitalOut enable(dp14); |
2016US_BenjaminRamic | 0:d063a3cae27e | 15 | |
2016US_BenjaminRamic | 0:d063a3cae27e | 16 | void prikazi(int segment, int cifra) |
2016US_BenjaminRamic | 0:d063a3cae27e | 17 | { |
2016US_BenjaminRamic | 0:d063a3cae27e | 18 | if (segment==1) ukljuci=6; |
2016US_BenjaminRamic | 0:d063a3cae27e | 19 | if (segment==2) ukljuci=5; |
2016US_BenjaminRamic | 0:d063a3cae27e | 20 | if (segment==3) ukljuci=3; |
2016US_BenjaminRamic | 0:d063a3cae27e | 21 | //ukljuci = segment; |
2016US_BenjaminRamic | 0:d063a3cae27e | 22 | lediceDisplej = cifra; |
2016US_BenjaminRamic | 0:d063a3cae27e | 23 | } |
2016US_BenjaminRamic | 0:d063a3cae27e | 24 | |
2016US_BenjaminRamic | 0:d063a3cae27e | 25 | void ocitaj() |
2016US_BenjaminRamic | 0:d063a3cae27e | 26 | { |
2016US_BenjaminRamic | 0:d063a3cae27e | 27 | if (taster1Prethodno == 0 && taster1 == 1) |
2016US_BenjaminRamic | 0:d063a3cae27e | 28 | { |
2016US_BenjaminRamic | 0:d063a3cae27e | 29 | broj++; |
2016US_BenjaminRamic | 0:d063a3cae27e | 30 | if(broj > 999) |
2016US_BenjaminRamic | 0:d063a3cae27e | 31 | broj = 0; |
2016US_BenjaminRamic | 0:d063a3cae27e | 32 | }else if(taster2Prethodno == 0 && taster2 == 1) |
2016US_BenjaminRamic | 0:d063a3cae27e | 33 | { |
2016US_BenjaminRamic | 0:d063a3cae27e | 34 | broj--; |
2016US_BenjaminRamic | 0:d063a3cae27e | 35 | if(broj < 0) |
2016US_BenjaminRamic | 0:d063a3cae27e | 36 | broj = 999; |
2016US_BenjaminRamic | 0:d063a3cae27e | 37 | } |
2016US_BenjaminRamic | 0:d063a3cae27e | 38 | |
2016US_BenjaminRamic | 0:d063a3cae27e | 39 | taster1Prethodno = taster1; |
2016US_BenjaminRamic | 0:d063a3cae27e | 40 | taster2Prethodno = taster2; |
2016US_BenjaminRamic | 0:d063a3cae27e | 41 | } |
2016US_BenjaminRamic | 0:d063a3cae27e | 42 | |
2016US_BenjaminRamic | 0:d063a3cae27e | 43 | |
2016US_BenjaminRamic | 0:d063a3cae27e | 44 | void osvjezi() |
2016US_BenjaminRamic | 0:d063a3cae27e | 45 | { |
2016US_BenjaminRamic | 0:d063a3cae27e | 46 | int i = 3; |
2016US_BenjaminRamic | 0:d063a3cae27e | 47 | int privremeni = broj; |
2016US_BenjaminRamic | 0:d063a3cae27e | 48 | do |
2016US_BenjaminRamic | 0:d063a3cae27e | 49 | { |
2016US_BenjaminRamic | 0:d063a3cae27e | 50 | int cifra = privremeni%10; |
2016US_BenjaminRamic | 0:d063a3cae27e | 51 | privremeni/=10; |
2016US_BenjaminRamic | 0:d063a3cae27e | 52 | prikazi(i, cifra); |
2016US_BenjaminRamic | 0:d063a3cae27e | 53 | i--; |
2016US_BenjaminRamic | 0:d063a3cae27e | 54 | wait(0.2); |
2016US_BenjaminRamic | 0:d063a3cae27e | 55 | }while(privremeni > 0); |
2016US_BenjaminRamic | 0:d063a3cae27e | 56 | } |
2016US_BenjaminRamic | 0:d063a3cae27e | 57 | int main() { |
2016US_BenjaminRamic | 0:d063a3cae27e | 58 | enable = 1; |
2016US_BenjaminRamic | 0:d063a3cae27e | 59 | |
2016US_BenjaminRamic | 0:d063a3cae27e | 60 | lediceDisplej = 25; |
2016US_BenjaminRamic | 0:d063a3cae27e | 61 | wait(1); |
2016US_BenjaminRamic | 0:d063a3cae27e | 62 | lediceDisplej = 0; |
2016US_BenjaminRamic | 0:d063a3cae27e | 63 | wait(1); |
2016US_BenjaminRamic | 0:d063a3cae27e | 64 | lediceDisplej = 25; |
2016US_BenjaminRamic | 0:d063a3cae27e | 65 | wait(1); |
2016US_BenjaminRamic | 0:d063a3cae27e | 66 | lediceDisplej = 0; |
2016US_BenjaminRamic | 0:d063a3cae27e | 67 | wait(1); |
2016US_BenjaminRamic | 0:d063a3cae27e | 68 | lediceDisplej = 25; |
2016US_BenjaminRamic | 0:d063a3cae27e | 69 | wait(1); |
2016US_BenjaminRamic | 0:d063a3cae27e | 70 | lediceDisplej = 0; |
2016US_BenjaminRamic | 0:d063a3cae27e | 71 | wait(1); |
2016US_BenjaminRamic | 0:d063a3cae27e | 72 | lediceDisplej = 25; |
2016US_BenjaminRamic | 0:d063a3cae27e | 73 | |
2016US_BenjaminRamic | 0:d063a3cae27e | 74 | while(1) |
2016US_BenjaminRamic | 0:d063a3cae27e | 75 | { |
2016US_BenjaminRamic | 0:d063a3cae27e | 76 | ocitaj(); |
2016US_BenjaminRamic | 0:d063a3cae27e | 77 | wait(2); |
2016US_BenjaminRamic | 0:d063a3cae27e | 78 | osvjezi(); |
2016US_BenjaminRamic | 0:d063a3cae27e | 79 | } |
2016US_BenjaminRamic | 0:d063a3cae27e | 80 | |
2016US_BenjaminRamic | 0:d063a3cae27e | 81 | |
2016US_BenjaminRamic | 0:d063a3cae27e | 82 | } |