Curkovic projekt TVZ2021
Dependencies: mbed SeeedShieldBot BluetoothSerial
main.cpp@0:2e91a001ef93, 2022-05-05 (annotated)
- Committer:
- chule
- Date:
- Thu May 05 19:10:43 2022 +0000
- Revision:
- 0:2e91a001ef93
.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
chule | 0:2e91a001ef93 | 1 | #include "mbed.h" |
chule | 0:2e91a001ef93 | 2 | #include "Blink.h" |
chule | 0:2e91a001ef93 | 3 | //Definiranje ulaza |
chule | 0:2e91a001ef93 | 4 | InterruptIn button(USER_BUTTON); |
chule | 0:2e91a001ef93 | 5 | |
chule | 0:2e91a001ef93 | 6 | //Definiranje tajmera |
chule | 0:2e91a001ef93 | 7 | Timer debounce; |
chule | 0:2e91a001ef93 | 8 | Timer Prekid1; |
chule | 0:2e91a001ef93 | 9 | Timer Prekid2; |
chule | 0:2e91a001ef93 | 10 | Ticker flipper; |
chule | 0:2e91a001ef93 | 11 | |
chule | 0:2e91a001ef93 | 12 | //Definifanje izlaza |
chule | 0:2e91a001ef93 | 13 | LED led1(D11); |
chule | 0:2e91a001ef93 | 14 | LED led2(D12); |
chule | 0:2e91a001ef93 | 15 | LED led3(D13); |
chule | 0:2e91a001ef93 | 16 | LED led4(D14); |
chule | 0:2e91a001ef93 | 17 | LED led5(D15); |
chule | 0:2e91a001ef93 | 18 | BusOut Seg1(D2,D3,D4,D5,D6,D7,D8,D9); |
chule | 0:2e91a001ef93 | 19 | |
chule | 0:2e91a001ef93 | 20 | //Definiranje funkcija |
chule | 0:2e91a001ef93 | 21 | char SegConvert(int SegValue); |
chule | 0:2e91a001ef93 | 22 | void Binary (int g); |
chule | 0:2e91a001ef93 | 23 | void prekid(void); |
chule | 0:2e91a001ef93 | 24 | |
chule | 0:2e91a001ef93 | 25 | //Funkcija upravljanja s 7 segmentnim displeom |
chule | 0:2e91a001ef93 | 26 | char SegConvert(int SegValue) { |
chule | 0:2e91a001ef93 | 27 | char SegByte=0x00; |
chule | 0:2e91a001ef93 | 28 | switch (SegValue) { |
chule | 0:2e91a001ef93 | 29 | case 0 : SegByte = 0x3F;break; |
chule | 0:2e91a001ef93 | 30 | case 1 : SegByte = 0x06;break; |
chule | 0:2e91a001ef93 | 31 | case 2 : SegByte = 0x5B;break; |
chule | 0:2e91a001ef93 | 32 | case 3 : SegByte = 0x4F;break; |
chule | 0:2e91a001ef93 | 33 | case 4 : SegByte = 0x66;break; |
chule | 0:2e91a001ef93 | 34 | case 5 : SegByte = 0x6D;break; |
chule | 0:2e91a001ef93 | 35 | case 6 : SegByte = 0x7D;break; |
chule | 0:2e91a001ef93 | 36 | case 7 : SegByte = 0x07;break; |
chule | 0:2e91a001ef93 | 37 | case 8 : SegByte = 0x7F;break; |
chule | 0:2e91a001ef93 | 38 | case 9 : SegByte = 0x6F;break; |
chule | 0:2e91a001ef93 | 39 | } |
chule | 0:2e91a001ef93 | 40 | return SegByte; |
chule | 0:2e91a001ef93 | 41 | } |
chule | 0:2e91a001ef93 | 42 | |
chule | 0:2e91a001ef93 | 43 | //Funkcija prekida |
chule | 0:2e91a001ef93 | 44 | void prekid() |
chule | 0:2e91a001ef93 | 45 | { |
chule | 0:2e91a001ef93 | 46 | if(debounce.read_ms()>200){ |
chule | 0:2e91a001ef93 | 47 | led1.status(0); |
chule | 0:2e91a001ef93 | 48 | led2.status(0); |
chule | 0:2e91a001ef93 | 49 | led3.status(0); |
chule | 0:2e91a001ef93 | 50 | led4.status(0); |
chule | 0:2e91a001ef93 | 51 | while(Prekid1.read()<=10){ |
chule | 0:2e91a001ef93 | 52 | Prekid1.start(); |
chule | 0:2e91a001ef93 | 53 | Prekid2.start(); |
chule | 0:2e91a001ef93 | 54 | if(Prekid2.read_ms()>=500) |
chule | 0:2e91a001ef93 | 55 | { |
chule | 0:2e91a001ef93 | 56 | led1.flip(); |
chule | 0:2e91a001ef93 | 57 | Prekid2.stop(); |
chule | 0:2e91a001ef93 | 58 | Prekid2.reset(); |
chule | 0:2e91a001ef93 | 59 | } |
chule | 0:2e91a001ef93 | 60 | } |
chule | 0:2e91a001ef93 | 61 | Prekid1.stop(); |
chule | 0:2e91a001ef93 | 62 | Prekid1.reset(); |
chule | 0:2e91a001ef93 | 63 | } |
chule | 0:2e91a001ef93 | 64 | debounce.reset(); |
chule | 0:2e91a001ef93 | 65 | } |
chule | 0:2e91a001ef93 | 66 | |
chule | 0:2e91a001ef93 | 67 | //Funkcija odredivanja stanja LED |
chule | 0:2e91a001ef93 | 68 | void Binary (int g) |
chule | 0:2e91a001ef93 | 69 | { |
chule | 0:2e91a001ef93 | 70 | switch (g) { |
chule | 0:2e91a001ef93 | 71 | case 0: { |
chule | 0:2e91a001ef93 | 72 | break; |
chule | 0:2e91a001ef93 | 73 | } |
chule | 0:2e91a001ef93 | 74 | case 1: { |
chule | 0:2e91a001ef93 | 75 | led1.flip(); |
chule | 0:2e91a001ef93 | 76 | break; |
chule | 0:2e91a001ef93 | 77 | } |
chule | 0:2e91a001ef93 | 78 | case 2: { |
chule | 0:2e91a001ef93 | 79 | led2.flip(); |
chule | 0:2e91a001ef93 | 80 | break; |
chule | 0:2e91a001ef93 | 81 | } |
chule | 0:2e91a001ef93 | 82 | case 3: { |
chule | 0:2e91a001ef93 | 83 | led1.flip(); |
chule | 0:2e91a001ef93 | 84 | led2.flip(); |
chule | 0:2e91a001ef93 | 85 | break; |
chule | 0:2e91a001ef93 | 86 | } |
chule | 0:2e91a001ef93 | 87 | case 4: { |
chule | 0:2e91a001ef93 | 88 | led3.flip(); |
chule | 0:2e91a001ef93 | 89 | break; |
chule | 0:2e91a001ef93 | 90 | } |
chule | 0:2e91a001ef93 | 91 | case 5: { |
chule | 0:2e91a001ef93 | 92 | led1.flip(); |
chule | 0:2e91a001ef93 | 93 | led3.flip(); |
chule | 0:2e91a001ef93 | 94 | break; |
chule | 0:2e91a001ef93 | 95 | } |
chule | 0:2e91a001ef93 | 96 | case 6: { |
chule | 0:2e91a001ef93 | 97 | led3.flip(); |
chule | 0:2e91a001ef93 | 98 | led2.flip(); |
chule | 0:2e91a001ef93 | 99 | break; |
chule | 0:2e91a001ef93 | 100 | } |
chule | 0:2e91a001ef93 | 101 | case 7: { |
chule | 0:2e91a001ef93 | 102 | led1.flip(); |
chule | 0:2e91a001ef93 | 103 | led2.flip(); |
chule | 0:2e91a001ef93 | 104 | led3.flip(); |
chule | 0:2e91a001ef93 | 105 | break; |
chule | 0:2e91a001ef93 | 106 | } |
chule | 0:2e91a001ef93 | 107 | case 8: { |
chule | 0:2e91a001ef93 | 108 | led4.flip(); |
chule | 0:2e91a001ef93 | 109 | break; |
chule | 0:2e91a001ef93 | 110 | } |
chule | 0:2e91a001ef93 | 111 | case 9: { |
chule | 0:2e91a001ef93 | 112 | led1.flip(); |
chule | 0:2e91a001ef93 | 113 | led4.flip(); |
chule | 0:2e91a001ef93 | 114 | break; |
chule | 0:2e91a001ef93 | 115 | } |
chule | 0:2e91a001ef93 | 116 | } |
chule | 0:2e91a001ef93 | 117 | } |
chule | 0:2e91a001ef93 | 118 | |
chule | 0:2e91a001ef93 | 119 | //funkcija Ticker-a |
chule | 0:2e91a001ef93 | 120 | void flip(){ |
chule | 0:2e91a001ef93 | 121 | led5.flip(); |
chule | 0:2e91a001ef93 | 122 | } |
chule | 0:2e91a001ef93 | 123 | |
chule | 0:2e91a001ef93 | 124 | //main funkcija |
chule | 0:2e91a001ef93 | 125 | int main() |
chule | 0:2e91a001ef93 | 126 | { |
chule | 0:2e91a001ef93 | 127 | debounce.start(); |
chule | 0:2e91a001ef93 | 128 | button.rise(&prekid); |
chule | 0:2e91a001ef93 | 129 | flipper.attach(&flip,0.2); |
chule | 0:2e91a001ef93 | 130 | int i; |
chule | 0:2e91a001ef93 | 131 | while(1){ |
chule | 0:2e91a001ef93 | 132 | for (i=0;i<10;i++){ |
chule | 0:2e91a001ef93 | 133 | led1.status(0); |
chule | 0:2e91a001ef93 | 134 | led2.status(0); |
chule | 0:2e91a001ef93 | 135 | led3.status(0); |
chule | 0:2e91a001ef93 | 136 | led4.status(0); |
chule | 0:2e91a001ef93 | 137 | Seg1=SegConvert(i); |
chule | 0:2e91a001ef93 | 138 | Binary(i); |
chule | 0:2e91a001ef93 | 139 | wait_ms(1000); |
chule | 0:2e91a001ef93 | 140 | } |
chule | 0:2e91a001ef93 | 141 | } |
chule | 0:2e91a001ef93 | 142 | } |