Isidora Milivojevic 2020/0214

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /* Isidora Milivojevic
00002 *  2020/0214
00003 *  ETF Beograd
00004 */
00005 
00006 // Uvoz biblioteka
00007 #include "mbed.h"
00008 
00009 // Definisanje makroa
00010 #define WAIT                                                                0.1
00011 #define ACTIVE                                                                0 
00012 #define NOT_ACTIVE                                                            1   
00013 
00014 //Globalne promenljive
00015 AnalogIn pot1(PA_0);
00016 AnalogIn pot2(PA_1);
00017 InterruptIn sw1(PC_9);
00018 PwmOut buzz(PA_11);
00019 DigitalOut select1(PC_7);
00020 DigitalOut select2(PB_6);
00021 BusOut display(PA_10, PA_9, PA_8, PB_10, PB_5, PB_4, PB_3);
00022 int j = 0;
00023 int d = 0;
00024 int digits[11] = { 0b1000000, //0
00025                        0b1111001, //1
00026                        0b0100100, //2
00027                        0b0110000, //3
00028                        0b0011001, //4
00029                        0b0010010, //5
00030                        0b0000010, //6
00031                        0b1111000, //7
00032                        0b0000000, //8
00033                        0b0010000, //9
00034                   };
00035 
00036 //Prototipi funkcija
00037 void ISR_sw1(void);
00038 
00039  //Glavna funkcija
00040 int main() {
00041     sw1.fall(&ISR_sw1);
00042     select1.write(NOT_ACTIVE);
00043     select2.write(NOT_ACTIVE);
00044     while (true){
00045         buzz.period_us(pot2.read()*2000+100); //Menjanje frekvenicje zujalice pomocu pot2
00046         buzz.write(pot1.read()); //Menjanje jacine zujalice pomocu pot1
00047         j = (int(pot1.read()*100))%10; //Jedinice jacine zvuka
00048         d = (int(pot1.read()*100))/10; //Desetice jacine zvuka
00049     }
00050 }
00051 
00052 //Prekidna rutina za pritisak tastera
00053 void ISR_sw1(){
00054     while(true){
00055         if(!d) {
00056             display.write(digits[j]);
00057             select1.write(ACTIVE);
00058             select2.write(NOT_ACTIVE);
00059         } else {
00060             display.write(digits[d]); 
00061             select1.write(NOT_ACTIVE);
00062             select2.write(ACTIVE);
00063             wait_ms(10);
00064             display.write(digits[j]);                  
00065             select1.write(ACTIVE);
00066             select2.write(NOT_ACTIVE);
00067             wait_ms(10);    
00068         }      
00069     }
00070 }