Nenad Tepavac 2020/0028

Dependencies:   mbed

Committer:
ostoja
Date:
Sat Nov 06 08:41:29 2021 +0000
Revision:
0:34bc6102fcfb
Nenad Tepavac 2020/0028

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ostoja 0:34bc6102fcfb 1 /*
ostoja 0:34bc6102fcfb 2 * Nenad Tepavac 2020/0028
ostoja 0:34bc6102fcfb 3 * Etf Beograd
ostoja 0:34bc6102fcfb 4 */
ostoja 0:34bc6102fcfb 5
ostoja 0:34bc6102fcfb 6 /*
ostoja 0:34bc6102fcfb 7 * Biblioteke
ostoja 0:34bc6102fcfb 8 */
ostoja 0:34bc6102fcfb 9 #include "mbed.h"
ostoja 0:34bc6102fcfb 10
ostoja 0:34bc6102fcfb 11 /*
ostoja 0:34bc6102fcfb 12 * Makroi
ostoja 0:34bc6102fcfb 13 */
ostoja 0:34bc6102fcfb 14 #define NULA 0xC0
ostoja 0:34bc6102fcfb 15 #define KEC 0xF9
ostoja 0:34bc6102fcfb 16 #define DVA 0xA4
ostoja 0:34bc6102fcfb 17 #define TRI 0xB0
ostoja 0:34bc6102fcfb 18 #define CTR 0x99
ostoja 0:34bc6102fcfb 19 #define PET 0x92
ostoja 0:34bc6102fcfb 20 #define SES 0x82
ostoja 0:34bc6102fcfb 21 #define SEAM 0xF8
ostoja 0:34bc6102fcfb 22 #define OSAM 0x80
ostoja 0:34bc6102fcfb 23 #define DE 0x90
ostoja 0:34bc6102fcfb 24
ostoja 0:34bc6102fcfb 25
ostoja 0:34bc6102fcfb 26 BusOut display(PA_10, PA_9, PA_8,PB_10,PB_5, PB_4, PB_3, PB_6, PC_7);
ostoja 0:34bc6102fcfb 27 DigitalIn btn(BUTTON1);
ostoja 0:34bc6102fcfb 28 DigitalIn sw(PC_9);
ostoja 0:34bc6102fcfb 29
ostoja 0:34bc6102fcfb 30 DigitalIn btn2(PC_8);
ostoja 0:34bc6102fcfb 31
ostoja 0:34bc6102fcfb 32 int c = 0;
ostoja 0:34bc6102fcfb 33 int b = 0;
ostoja 0:34bc6102fcfb 34 int b2 = 0;
ostoja 0:34bc6102fcfb 35 int s = 0;
ostoja 0:34bc6102fcfb 36
ostoja 0:34bc6102fcfb 37 void increment(){
ostoja 0:34bc6102fcfb 38 c++;
ostoja 0:34bc6102fcfb 39 if(c > 15)
ostoja 0:34bc6102fcfb 40 c = 0;
ostoja 0:34bc6102fcfb 41
ostoja 0:34bc6102fcfb 42 switch(c){
ostoja 0:34bc6102fcfb 43 case 0:
ostoja 0:34bc6102fcfb 44 display.write(NULA);
ostoja 0:34bc6102fcfb 45 break;
ostoja 0:34bc6102fcfb 46 case 1:
ostoja 0:34bc6102fcfb 47 display.write(KEC);
ostoja 0:34bc6102fcfb 48 break;
ostoja 0:34bc6102fcfb 49 case 2:
ostoja 0:34bc6102fcfb 50 display.write(DVA);
ostoja 0:34bc6102fcfb 51 break;
ostoja 0:34bc6102fcfb 52 case 3:
ostoja 0:34bc6102fcfb 53 display.write(TRI);
ostoja 0:34bc6102fcfb 54 break;
ostoja 0:34bc6102fcfb 55 case 4:
ostoja 0:34bc6102fcfb 56 display.write(CTR);
ostoja 0:34bc6102fcfb 57 break;
ostoja 0:34bc6102fcfb 58 case 5:
ostoja 0:34bc6102fcfb 59 display.write(PET);
ostoja 0:34bc6102fcfb 60 break;
ostoja 0:34bc6102fcfb 61 case 6:
ostoja 0:34bc6102fcfb 62 display.write(SES);
ostoja 0:34bc6102fcfb 63 break;
ostoja 0:34bc6102fcfb 64 case 7:
ostoja 0:34bc6102fcfb 65 display.write(SEAM);
ostoja 0:34bc6102fcfb 66 break;
ostoja 0:34bc6102fcfb 67 case 8:
ostoja 0:34bc6102fcfb 68 display.write(OSAM);
ostoja 0:34bc6102fcfb 69 break;
ostoja 0:34bc6102fcfb 70 case 9:
ostoja 0:34bc6102fcfb 71 display.write(DE);
ostoja 0:34bc6102fcfb 72 break;
ostoja 0:34bc6102fcfb 73 }
ostoja 0:34bc6102fcfb 74 }
ostoja 0:34bc6102fcfb 75
ostoja 0:34bc6102fcfb 76 void decrement(){
ostoja 0:34bc6102fcfb 77 c--;
ostoja 0:34bc6102fcfb 78 c--;
ostoja 0:34bc6102fcfb 79
ostoja 0:34bc6102fcfb 80 if(c == -2)
ostoja 0:34bc6102fcfb 81 c = 14;
ostoja 0:34bc6102fcfb 82
ostoja 0:34bc6102fcfb 83 increment();
ostoja 0:34bc6102fcfb 84 }
ostoja 0:34bc6102fcfb 85
ostoja 0:34bc6102fcfb 86 int main(){
ostoja 0:34bc6102fcfb 87 display.write(NULA);
ostoja 0:34bc6102fcfb 88
ostoja 0:34bc6102fcfb 89 while(true){
ostoja 0:34bc6102fcfb 90 if(!btn){
ostoja 0:34bc6102fcfb 91 b = 1;
ostoja 0:34bc6102fcfb 92 }
ostoja 0:34bc6102fcfb 93 if(btn && b == 1){
ostoja 0:34bc6102fcfb 94 b = 0;
ostoja 0:34bc6102fcfb 95 increment();
ostoja 0:34bc6102fcfb 96 }
ostoja 0:34bc6102fcfb 97
ostoja 0:34bc6102fcfb 98 if(!sw){
ostoja 0:34bc6102fcfb 99 s = 1;
ostoja 0:34bc6102fcfb 100 }
ostoja 0:34bc6102fcfb 101 if(sw && s == 1){
ostoja 0:34bc6102fcfb 102 s = 0;
ostoja 0:34bc6102fcfb 103 increment();
ostoja 0:34bc6102fcfb 104 }
ostoja 0:34bc6102fcfb 105
ostoja 0:34bc6102fcfb 106
ostoja 0:34bc6102fcfb 107 if(btn2){
ostoja 0:34bc6102fcfb 108 b2 = 1;
ostoja 0:34bc6102fcfb 109 }
ostoja 0:34bc6102fcfb 110 if(!btn2 && b2 == 1){
ostoja 0:34bc6102fcfb 111 b2 = 0;
ostoja 0:34bc6102fcfb 112 decrement();
ostoja 0:34bc6102fcfb 113 }
ostoja 0:34bc6102fcfb 114
ostoja 0:34bc6102fcfb 115 if(c > 9){
ostoja 0:34bc6102fcfb 116 display.write(0b101111001);
ostoja 0:34bc6102fcfb 117 wait_ms(5);
ostoja 0:34bc6102fcfb 118 if(c == 10)
ostoja 0:34bc6102fcfb 119 display.write(NULA);
ostoja 0:34bc6102fcfb 120 if(c == 11)
ostoja 0:34bc6102fcfb 121 display.write(KEC);
ostoja 0:34bc6102fcfb 122 if(c == 12)
ostoja 0:34bc6102fcfb 123 display.write(DVA);
ostoja 0:34bc6102fcfb 124 if(c == 13)
ostoja 0:34bc6102fcfb 125 display.write(TRI);
ostoja 0:34bc6102fcfb 126 if(c == 14)
ostoja 0:34bc6102fcfb 127 display.write(CTR);
ostoja 0:34bc6102fcfb 128 if(c == 15)
ostoja 0:34bc6102fcfb 129 display.write(PET);
ostoja 0:34bc6102fcfb 130 wait_ms(5);
ostoja 0:34bc6102fcfb 131 }
ostoja 0:34bc6102fcfb 132 }
ostoja 0:34bc6102fcfb 133
ostoja 0:34bc6102fcfb 134 }