Filip Babic 2020/0511

Dependencies:   mbed

Committer:
babic_f
Date:
Sat Nov 13 09:18:22 2021 +0000
Revision:
0:260af6793844
Filip Babic 2020/0511

Who changed what in which revision?

UserRevisionLine numberNew contents of line
babic_f 0:260af6793844 1 /*
babic_f 0:260af6793844 2 * Biblioteke za uvoz:
babic_f 0:260af6793844 3 */
babic_f 0:260af6793844 4 #include "mbed.h"
babic_f 0:260af6793844 5
babic_f 0:260af6793844 6 /*
babic_f 0:260af6793844 7 * Definisanje makroa:
babic_f 0:260af6793844 8 */
babic_f 0:260af6793844 9 #define BUZZ_PERIOD 7
babic_f 0:260af6793844 10 #define BUZZ_ON 1
babic_f 0:260af6793844 11 #define BUZZ_OFF 0
babic_f 0:260af6793844 12 #define BUZZ_DUTY_CYCLE 0.5
babic_f 0:260af6793844 13 #define PERIOD 0.1
babic_f 0:260af6793844 14 #define PERIOD_MS 12
babic_f 0:260af6793844 15
babic_f 0:260af6793844 16 /*
babic_f 0:260af6793844 17 * Instanciranje:
babic_f 0:260af6793844 18 */
babic_f 0:260af6793844 19 AnalogIn pot1(PA_0);
babic_f 0:260af6793844 20 AnalogIn pot2(PA_1);
babic_f 0:260af6793844 21 PwmOut buzz(PA_11);
babic_f 0:260af6793844 22 BusOut display(PA_10, PA_9, PA_8, PB_10, PB_5, PB_4, PB_3);
babic_f 0:260af6793844 23 DigitalOut select1(PB_6);
babic_f 0:260af6793844 24 DigitalOut select2(PC_7);
babic_f 0:260af6793844 25 InterruptIn SW1(PC_9);
babic_f 0:260af6793844 26
babic_f 0:260af6793844 27
babic_f 0:260af6793844 28 /*
babic_f 0:260af6793844 29 * Globalne promenljive:
babic_f 0:260af6793844 30 */
babic_f 0:260af6793844 31 double pot1_val, pot2_val;
babic_f 0:260af6793844 32 double pot1_percent, pot2_percent;
babic_f 0:260af6793844 33 double dig1, dig2;
babic_f 0:260af6793844 34
babic_f 0:260af6793844 35
babic_f 0:260af6793844 36 static int digits[] = { // G, F, E, D, C, B, A
babic_f 0:260af6793844 37 0xC0, // NULA
babic_f 0:260af6793844 38 0xF9, // JEDAN
babic_f 0:260af6793844 39 0xA4, // DVA
babic_f 0:260af6793844 40 0xB0, // TRI
babic_f 0:260af6793844 41 0x99, // CETIRI
babic_f 0:260af6793844 42 0x92, // PET
babic_f 0:260af6793844 43 0x82, // SEST
babic_f 0:260af6793844 44 0xF8, // SEDAM
babic_f 0:260af6793844 45 0x80, // OSAM
babic_f 0:260af6793844 46 0x90, // DEVET
babic_f 0:260af6793844 47 0xFF // UGASI
babic_f 0:260af6793844 48 };
babic_f 0:260af6793844 49
babic_f 0:260af6793844 50 /*
babic_f 0:260af6793844 51 * Deklaracija funkcija:
babic_f 0:260af6793844 52 */
babic_f 0:260af6793844 53 void ISR_sw1(void);
babic_f 0:260af6793844 54
babic_f 0:260af6793844 55 /*
babic_f 0:260af6793844 56 * Glavna funkcija:
babic_f 0:260af6793844 57 */
babic_f 0:260af6793844 58 int main(){
babic_f 0:260af6793844 59
babic_f 0:260af6793844 60 // NAPOMENA: Radi sa ubodenim JP1
babic_f 0:260af6793844 61 static char ButtonPressed = 0;
babic_f 0:260af6793844 62
babic_f 0:260af6793844 63
babic_f 0:260af6793844 64
babic_f 0:260af6793844 65 select1.write(1);
babic_f 0:260af6793844 66 select2.write(0);
babic_f 0:260af6793844 67 display.write(digits[10]);
babic_f 0:260af6793844 68
babic_f 0:260af6793844 69 while(true){
babic_f 0:260af6793844 70 // Ocitavanje vrednosti potenciometara(0 - 1)
babic_f 0:260af6793844 71 pot1_val = pot1.read();
babic_f 0:260af6793844 72 pot2_val = pot2.read();
babic_f 0:260af6793844 73
babic_f 0:260af6793844 74 // Promena frekvencije potenciometrom 2
babic_f 0:260af6793844 75 buzz.period((1.0/300) * pot2_val);
babic_f 0:260af6793844 76
babic_f 0:260af6793844 77 //Promena jacine zvuka potenciometrom 1
babic_f 0:260af6793844 78 buzz.write(BUZZ_DUTY_CYCLE * pot1_val);
babic_f 0:260af6793844 79 wait_ms(BUZZ_PERIOD);
babic_f 0:260af6793844 80
babic_f 0:260af6793844 81 // Vrednosti potenciometara u procentima
babic_f 0:260af6793844 82 pot1_percent = pot1_val * 100.0;
babic_f 0:260af6793844 83 pot2_percent = pot2_val * 100.0;
babic_f 0:260af6793844 84
babic_f 0:260af6793844 85 /* IDEJA KOJA NIJE HTELA DA RADI ZBOG dig1 i dig2 :(
babic_f 0:260af6793844 86 // Vrednosti cifara displeja
babic_f 0:260af6793844 87 dig1 = (int)(pot1_percent - (pot1_percent % 10.0)) / 10;
babic_f 0:260af6793844 88 dig2 = (int)pot1_percent % 10;
babic_f 0:260af6793844 89
babic_f 0:260af6793844 90 // Pritisak dugmeta
babic_f 0:260af6793844 91 //sw1.fall(&ISR_sw1);
babic_f 0:260af6793844 92 if(!SW1){
babic_f 0:260af6793844 93 if(ButtonPressed){
babic_f 0:260af6793844 94 while(true){
babic_f 0:260af6793844 95 select1.write(0);
babic_f 0:260af6793844 96 display.write(digits[dig1]);
babic_f 0:260af6793844 97 wait_ms(PERIOD_MS);
babic_f 0:260af6793844 98 select1.write(1);
babic_f 0:260af6793844 99 select2.write(0);
babic_f 0:260af6793844 100 display.write(digits[dig2]);
babic_f 0:260af6793844 101 wait_ms(PERIOD_MS);
babic_f 0:260af6793844 102 }
babic_f 0:260af6793844 103 }
babic_f 0:260af6793844 104 }
babic_f 0:260af6793844 105 else{
babic_f 0:260af6793844 106 ButtonPressed = 1;
babic_f 0:260af6793844 107 }
babic_f 0:260af6793844 108
babic_f 0:260af6793844 109 wait(PERIOD);*/
babic_f 0:260af6793844 110 }
babic_f 0:260af6793844 111
babic_f 0:260af6793844 112 }
babic_f 0:260af6793844 113
babic_f 0:260af6793844 114 /*
babic_f 0:260af6793844 115 * Definicija funkcija:
babic_f 0:260af6793844 116 */
babic_f 0:260af6793844 117 void ISR_sw1()
babic_f 0:260af6793844 118 {
babic_f 0:260af6793844 119 buzz.write(0);
babic_f 0:260af6793844 120 }