Milos Novakovic 2020/0425

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
mlos55
Date:
Sat Nov 13 09:20:47 2021 +0000
Commit message:
Milos Novakovic 2020/0425

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sat Nov 13 09:20:47 2021 +0000
@@ -0,0 +1,116 @@
+// Milos Novakovic 2020/0425
+
+/*Prikazana vrijednost ne odgovara onome sto se moze cuti u prvi i poslednjih 10% jer
+piezzo zahtjeva paljenje i gasenje tj konsantno smjenjivanje 0 i 1, 
+sto npr na 99% skoro sve je visok napon i ne dobijamo zvuk*/
+
+//Uvoz biblioteka i def. direktiva
+
+#include "mbed.h"
+
+//Globalne promjenljive
+
+PwmOut buzzer(PA_11);
+AnalogIn pot2(PA_1);
+AnalogIn pot1(PA_0);
+InterruptIn sw1(PC_9);
+DigitalOut SEL2(PC_7);
+DigitalOut SEL1(PB_6);
+BusOut display1(PA_10, PA_9,PA_8,PB_10,PB_5,PB_4,PB_3);
+BusOut display2(PA_10, PA_9,PA_8,PB_10,PB_5,PB_4,PB_3);
+static float x;
+static int x1;
+static int flag=0;
+static int postotak, desetice,jedinice;
+static char i=0;
+
+
+//deklaracija pomocnih f-ja
+
+void ISR_sw1(void);
+void display(void);
+
+//glavni program
+
+int main(){
+    
+SEL1=1; SEL2=1;
+sw1.fall(&ISR_sw1);
+
+    while(1){
+         buzzer=pot1;
+         if(pot1==0) buzzer=0.01f;
+         
+         
+         
+         if(flag==1) display();
+         
+         
+         
+        x=pot2*20000;
+        if(x==0) x=0.01f*20000;
+         if(x<1000){
+             x1=1000/x;
+             buzzer.period_ms(x1);
+             }
+         else{
+             x1=1000000/x;
+             buzzer.period_us(x1);
+         }
+         
+          wait_ms(30);
+         }   
+      
+    }
+
+
+
+void ISR_sw1(){
+    flag = 1;
+}
+
+
+void display(){
+    postotak=pot1*100;
+    desetice=postotak/10;
+    jedinice=postotak-(desetice*10);
+    
+    while(i<100){     
+    SEL1=0;
+    switch(desetice){
+        
+        case 1: display2=0xF9; break;
+        case 2: display2=0xA4; break;
+        case 3: display2=0xB0; break;
+        case 4: display2=0x99; break;
+        case 5: display2=0x92; break;
+        case 6: display2=0x82; break;
+        case 7: display2=0xF8; break;
+        case 8: display2=0x80; break;
+        case 9: display2=0x90; break;
+        default: SEL1=1; break;
+    }
+     wait_ms(5);
+    SEL1=1;
+    SEL2=0;
+     switch(jedinice){
+        case 0: SEL1=1;display2=0x40; break;
+        case 1: display2=0xF9; break;
+        case 2: display2=0xA4; break;
+        case 3: display2=0xB0; break;
+        case 4: display2=0x99; break;
+        case 5: display2=0x92; break;
+        case 6: display2=0x82; break;
+        case 7: display2=0xF8; break;
+        case 8: display2=0x80; break;
+        case 9: display2=0x90; break;
+    }
+    wait_ms(5);
+    i++;
+    SEL2=1;
+    }
+    
+    SEL1=1; SEL2=1;
+    flag=0;
+    i=0;
+    }
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sat Nov 13 09:20:47 2021 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400
\ No newline at end of file