Andrija Mijailovic 2020/0388

Dependencies:   mbed

Committer:
ma200388
Date:
Sat Nov 13 09:17:44 2021 +0000
Revision:
3:bd632f30b46b
Parent:
2:2a4f1bb68811
Andrija Mijailovic 2020/0388

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tzwell 0:cfac98129f2f 1 /*
tzwell 0:cfac98129f2f 2 * Biblioteke za uvoz:
tzwell 0:cfac98129f2f 3 */
tzwell 0:cfac98129f2f 4 #include "mbed.h"
tzwell 0:cfac98129f2f 5
tzwell 0:cfac98129f2f 6 /*
tzwell 0:cfac98129f2f 7 * Definisanje makroa:
tzwell 0:cfac98129f2f 8 */
ma200388 3:bd632f30b46b 9
ma200388 3:bd632f30b46b 10 #define PERIOD 100
ma200388 3:bd632f30b46b 11 #define DUTY_CYCLE 0.75f
ma200388 3:bd632f30b46b 12 #define ZERO 64
ma200388 3:bd632f30b46b 13 #define ONE 121
ma200388 3:bd632f30b46b 14 #define TWO 36
ma200388 3:bd632f30b46b 15 #define THREE 48
ma200388 3:bd632f30b46b 16 #define FOUR 25
ma200388 3:bd632f30b46b 17 #define FIVE 18
ma200388 3:bd632f30b46b 18 #define SIX 2
ma200388 3:bd632f30b46b 19 #define SEVEN 120
ma200388 3:bd632f30b46b 20 #define EIGHT 0
ma200388 3:bd632f30b46b 21 #define NINE 16
tzwell 0:cfac98129f2f 22 /*
tzwell 0:cfac98129f2f 23 * Globalne promenljive:
tzwell 0:cfac98129f2f 24 */
tzwell 0:cfac98129f2f 25
ma200388 3:bd632f30b46b 26 PwmOut buzz(PA_11);
ma200388 3:bd632f30b46b 27 AnalogIn pot1(PA_0);
ma200388 3:bd632f30b46b 28 AnalogIn pot2(PA_1);
ma200388 3:bd632f30b46b 29 InterruptIn sw1(PC_9);
ma200388 3:bd632f30b46b 30 DigitalOut sel1(PB_6);
ma200388 3:bd632f30b46b 31 DigitalOut sel2(PC_7);
ma200388 3:bd632f30b46b 32 BusOut display(PA_10,PA_9,PA_8,PB_10,PB_5,PB_4,PB_3);
ma200388 3:bd632f30b46b 33 static int update=0;
ma200388 3:bd632f30b46b 34 static float br=0;
tzwell 0:cfac98129f2f 35 /*
tzwell 0:cfac98129f2f 36 * Deklaracija funkcija:
tzwell 0:cfac98129f2f 37 */
tzwell 0:cfac98129f2f 38
ma200388 3:bd632f30b46b 39 void ISR_sw1(void);
ma200388 3:bd632f30b46b 40 void screen(int percent);
tzwell 0:cfac98129f2f 41 /*
tzwell 0:cfac98129f2f 42 * Glavna funkcija:
tzwell 0:cfac98129f2f 43 */
tzwell 0:cfac98129f2f 44 int main()
tzwell 0:cfac98129f2f 45 {
ma200388 3:bd632f30b46b 46 sw1.fall(&ISR_sw1);
tzwell 0:cfac98129f2f 47 while(true)
tzwell 0:cfac98129f2f 48 {
ma200388 3:bd632f30b46b 49
ma200388 3:bd632f30b46b 50 buzz.period(pot2.read()/200+0.00005);
ma200388 3:bd632f30b46b 51 buzz.write(pot1.read());
ma200388 3:bd632f30b46b 52 screen((int)br);
ma200388 3:bd632f30b46b 53 wait_ms(4);
tzwell 0:cfac98129f2f 54 }
tzwell 0:cfac98129f2f 55 }
tzwell 0:cfac98129f2f 56
tzwell 0:cfac98129f2f 57
tzwell 0:cfac98129f2f 58 /*
tzwell 0:cfac98129f2f 59 * Definicija funkcija:
ma200388 3:bd632f30b46b 60 */
ma200388 3:bd632f30b46b 61 void screen(int percent){
ma200388 3:bd632f30b46b 62
ma200388 3:bd632f30b46b 63 switch(percent-percent/10*10){
ma200388 3:bd632f30b46b 64 case 0:
ma200388 3:bd632f30b46b 65 sel1.write(1);
ma200388 3:bd632f30b46b 66 sel2.write(0);
ma200388 3:bd632f30b46b 67 display.write(ZERO);
ma200388 3:bd632f30b46b 68 break;
ma200388 3:bd632f30b46b 69 case 1:
ma200388 3:bd632f30b46b 70 sel1.write(1);
ma200388 3:bd632f30b46b 71 sel2.write(0);
ma200388 3:bd632f30b46b 72 display.write(ONE);
ma200388 3:bd632f30b46b 73 break;
ma200388 3:bd632f30b46b 74 case 2:
ma200388 3:bd632f30b46b 75 sel1.write(1);
ma200388 3:bd632f30b46b 76 sel2.write(0);
ma200388 3:bd632f30b46b 77 display.write(TWO);
ma200388 3:bd632f30b46b 78 break;
ma200388 3:bd632f30b46b 79 case 3:
ma200388 3:bd632f30b46b 80 sel1.write(1);
ma200388 3:bd632f30b46b 81 sel2.write(0);
ma200388 3:bd632f30b46b 82 display.write(THREE);
ma200388 3:bd632f30b46b 83 break;
ma200388 3:bd632f30b46b 84 case 4:
ma200388 3:bd632f30b46b 85 sel1.write(1);
ma200388 3:bd632f30b46b 86 sel2.write(0);
ma200388 3:bd632f30b46b 87 display.write(FOUR);
ma200388 3:bd632f30b46b 88 break;
ma200388 3:bd632f30b46b 89 case 5:
ma200388 3:bd632f30b46b 90 sel1.write(1);
ma200388 3:bd632f30b46b 91 sel2.write(0);
ma200388 3:bd632f30b46b 92 display.write(FIVE);
ma200388 3:bd632f30b46b 93 break;
ma200388 3:bd632f30b46b 94 case 6:
ma200388 3:bd632f30b46b 95 sel1.write(1);
ma200388 3:bd632f30b46b 96 sel2.write(0);
ma200388 3:bd632f30b46b 97 display.write(SIX);
ma200388 3:bd632f30b46b 98 break;
ma200388 3:bd632f30b46b 99 case 7:
ma200388 3:bd632f30b46b 100 sel1.write(1);
ma200388 3:bd632f30b46b 101 sel2.write(0);
ma200388 3:bd632f30b46b 102 display.write(SEVEN);
ma200388 3:bd632f30b46b 103 break;
ma200388 3:bd632f30b46b 104 case 8:
ma200388 3:bd632f30b46b 105 sel1.write(1);
ma200388 3:bd632f30b46b 106 sel2.write(0);
ma200388 3:bd632f30b46b 107 display.write(EIGHT);
ma200388 3:bd632f30b46b 108 break;
ma200388 3:bd632f30b46b 109 case 9:
ma200388 3:bd632f30b46b 110 sel1.write(1);
ma200388 3:bd632f30b46b 111 sel2.write(0);
ma200388 3:bd632f30b46b 112 display.write(NINE);
ma200388 3:bd632f30b46b 113 break;
ma200388 3:bd632f30b46b 114 }
ma200388 3:bd632f30b46b 115 wait_ms(8);
ma200388 3:bd632f30b46b 116 switch(percent/10){
ma200388 3:bd632f30b46b 117 case 0:
ma200388 3:bd632f30b46b 118 break;
ma200388 3:bd632f30b46b 119 case 1:
ma200388 3:bd632f30b46b 120 sel1.write(0);
ma200388 3:bd632f30b46b 121 sel2.write(1);
ma200388 3:bd632f30b46b 122 display.write(ONE);
ma200388 3:bd632f30b46b 123 break;
ma200388 3:bd632f30b46b 124 case 2:
ma200388 3:bd632f30b46b 125 sel1.write(0);
ma200388 3:bd632f30b46b 126 sel2.write(1);
ma200388 3:bd632f30b46b 127 display.write(TWO);
ma200388 3:bd632f30b46b 128 break;
ma200388 3:bd632f30b46b 129 case 3:
ma200388 3:bd632f30b46b 130 sel1.write(0);
ma200388 3:bd632f30b46b 131 sel2.write(1);
ma200388 3:bd632f30b46b 132 display.write(THREE);
ma200388 3:bd632f30b46b 133 break;
ma200388 3:bd632f30b46b 134 case 4:
ma200388 3:bd632f30b46b 135 sel1.write(0);
ma200388 3:bd632f30b46b 136 sel2.write(1);
ma200388 3:bd632f30b46b 137 display.write(FOUR);
ma200388 3:bd632f30b46b 138 break;
ma200388 3:bd632f30b46b 139 case 5:
ma200388 3:bd632f30b46b 140 sel1.write(0);
ma200388 3:bd632f30b46b 141 sel2.write(1);
ma200388 3:bd632f30b46b 142 display.write(FIVE);
ma200388 3:bd632f30b46b 143 break;
ma200388 3:bd632f30b46b 144 case 6:
ma200388 3:bd632f30b46b 145 sel1.write(0);
ma200388 3:bd632f30b46b 146 sel2.write(1);
ma200388 3:bd632f30b46b 147 display.write(SIX);
ma200388 3:bd632f30b46b 148 break;
ma200388 3:bd632f30b46b 149 case 7:
ma200388 3:bd632f30b46b 150 sel1.write(0);
ma200388 3:bd632f30b46b 151 sel2.write(1);
ma200388 3:bd632f30b46b 152 display.write(SEVEN);
ma200388 3:bd632f30b46b 153 break;
ma200388 3:bd632f30b46b 154 case 8:
ma200388 3:bd632f30b46b 155 sel1.write(0);
ma200388 3:bd632f30b46b 156 sel2.write(1);
ma200388 3:bd632f30b46b 157 display.write(EIGHT);
ma200388 3:bd632f30b46b 158 break;
ma200388 3:bd632f30b46b 159 case 9:
ma200388 3:bd632f30b46b 160 sel1.write(0);
ma200388 3:bd632f30b46b 161 sel2.write(1);
ma200388 3:bd632f30b46b 162 display.write(NINE);
ma200388 3:bd632f30b46b 163 break;
ma200388 3:bd632f30b46b 164 }
ma200388 3:bd632f30b46b 165 wait_ms(4);
ma200388 3:bd632f30b46b 166
ma200388 3:bd632f30b46b 167
ma200388 3:bd632f30b46b 168 }
ma200388 3:bd632f30b46b 169
ma200388 3:bd632f30b46b 170
ma200388 3:bd632f30b46b 171
ma200388 3:bd632f30b46b 172 void ISR_sw1(){
ma200388 3:bd632f30b46b 173 br=pot1.read();
ma200388 3:bd632f30b46b 174 }