Andrija Mijailovic 2020/0388

Dependencies:   mbed

Revision:
3:bd632f30b46b
Parent:
2:2a4f1bb68811
diff -r 2a4f1bb68811 -r bd632f30b46b main.cpp
--- a/main.cpp	Sat Nov 06 07:06:08 2021 +0000
+++ b/main.cpp	Sat Nov 13 09:17:44 2021 +0000
@@ -1,16 +1,3 @@
-/*
- * https://drive.google.com/drive/folders/1az2UIT1XcgSR50q0zc69UTegiXzlJ2Rb?usp=sharing
- * Primer treperenja diode za STM32L476RG napisan
- * koristeci mbed.h biblioteku.
- *
- * Katedra za Elektroniku i digitalne sisteme
- * Elektrotehnicki fakultet
- * Beograd 
- *
- * Oktobar 2021.
- *
- */
-
 /*
  * Biblioteke za uvoz:
  */
@@ -19,34 +6,169 @@
 /*
  * Definisanje makroa:
  */
- #define HALF_PERIOD 250
+ 
+#define PERIOD 100
+#define DUTY_CYCLE 0.75f
+#define ZERO 64
+#define ONE 121
+#define TWO 36
+#define THREE 48
+#define FOUR 25
+#define FIVE 18
+#define SIX 2
+#define SEVEN 120
+#define EIGHT 0
+#define NINE 16
 /*
  * Globalne promenljive:
  */
  
+PwmOut buzz(PA_11);
+AnalogIn pot1(PA_0);
+AnalogIn pot2(PA_1);
+InterruptIn sw1(PC_9);
+DigitalOut sel1(PB_6);
+DigitalOut sel2(PC_7);
+BusOut display(PA_10,PA_9,PA_8,PB_10,PB_5,PB_4,PB_3);
+static int update=0;
+static float br=0;
 /*
  * Deklaracija funkcija:
  */
 
-
+void ISR_sw1(void);
+void screen(int percent);
 /*
  * Glavna funkcija:
  */
 int main()
 {
-    // Inicijalizacija i funckije koje se jednom izvrsavaju:
-    DigitalOut DiodicaNaPloci (LED1);     // Kreiranje promenljive diode
-    
-    // Glavna petlja:
+    sw1.fall(&ISR_sw1);
     while(true)
     {
-        DiodicaNaPloci = !DiodicaNaPloci; // Negacija prethodne vrednosti
-        wait_ms(HALF_PERIOD);             // Cekanje
-
+        
+        buzz.period(pot2.read()/200+0.00005);
+        buzz.write(pot1.read());
+        screen((int)br);
+        wait_ms(4);
     }    
 }
 
 
 /*
  * Definicija funkcija:
- */
\ No newline at end of file
+ */
+ void screen(int percent){
+     
+     switch(percent-percent/10*10){
+            case 0:
+                sel1.write(1);
+                sel2.write(0);
+                display.write(ZERO);
+                break;
+            case 1:
+                sel1.write(1);
+                sel2.write(0);
+                display.write(ONE);
+                break;
+            case 2:
+                sel1.write(1);
+                sel2.write(0);
+                display.write(TWO);
+                break;
+            case 3:
+                sel1.write(1);
+                sel2.write(0);
+                display.write(THREE);
+                break;
+            case 4:
+                sel1.write(1);
+                sel2.write(0);
+                display.write(FOUR);
+                break;
+            case 5:
+                sel1.write(1);
+                sel2.write(0);
+                display.write(FIVE);
+                break;
+            case 6:
+                sel1.write(1);
+                sel2.write(0);
+                display.write(SIX);
+                break;
+            case 7:
+                sel1.write(1);
+                sel2.write(0);
+                display.write(SEVEN);
+                break;
+            case 8:
+                sel1.write(1);
+                sel2.write(0);
+                display.write(EIGHT);
+                break;
+            case 9:
+                sel1.write(1);
+                sel2.write(0);
+                display.write(NINE);
+                break;
+     }
+     wait_ms(8);
+    switch(percent/10){
+            case 0:
+                break;
+            case 1:
+                sel1.write(0);
+                sel2.write(1);
+                display.write(ONE);
+                break;
+            case 2:
+                sel1.write(0);
+                sel2.write(1);
+                display.write(TWO);
+                break;
+            case 3:
+                sel1.write(0);
+                sel2.write(1);
+                display.write(THREE);
+                break;
+            case 4:
+                sel1.write(0);
+                sel2.write(1);
+                display.write(FOUR);
+                break;
+            case 5:
+                sel1.write(0);
+                sel2.write(1);
+                display.write(FIVE);
+                break;
+            case 6:
+                sel1.write(0);
+                sel2.write(1);
+                display.write(SIX);
+                break;
+            case 7:
+                sel1.write(0);
+                sel2.write(1);
+                display.write(SEVEN);
+                break;
+            case 8:
+                sel1.write(0);
+                sel2.write(1);
+                display.write(EIGHT);
+                break;
+            case 9:
+                sel1.write(0);
+                sel2.write(1);
+                display.write(NINE);
+                break;
+     }
+     wait_ms(4);
+     
+     
+}
+     
+     
+     
+ void ISR_sw1(){
+     br=pot1.read();
+     }