mikroupravljaci konsturkcijski rad

Dependencies:   mbed Ledica

Revision:
0:f5eb09f250ae
diff -r 000000000000 -r f5eb09f250ae main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri May 07 08:44:34 2021 +0000
@@ -0,0 +1,67 @@
+#include "mbed.h"
+#include "Ledica.h"
+
+Indicator crvena (D11);
+Indicator zelena (D12);
+
+InterruptIn senzor_ulaz(D9);
+InterruptIn senzor_izlaz(D10);
+
+BusOut Disp(D2,D3,D4,D5,D6,D7,D8); 
+char SegConvert(char SegValue); 
+int br=0,t=0;
+
+Ticker tik1;
+
+void tiker1()
+{
+    t=t+1;
+}
+
+void ulaz()
+{
+    if(br<9)
+    br++;;
+    if(br==9);
+}
+
+void izlaz()
+{
+    if(br>=0)
+    br--;;
+}
+
+char SegConvert(char SegValue) { 
+char SegByte=0x00;
+switch (SegValue) { //DPGFEDCBA
+case 0 : SegByte = 0x3F;break; // 00111111 binary
+case 1 : SegByte = 0x06;break; // 00000110 binary
+case 2 : SegByte = 0x5B;break; // 01011011 binary
+case 3 : SegByte = 0x4F;break; // 01001111 binary
+case 4 : SegByte = 0x66;break; // 01100110 binary
+case 5 : SegByte = 0x6D;break; // 01101101 binary
+case 6 : SegByte = 0x7D;break; // 01111101 binary
+case 7 : SegByte = 0x07;break; // 00000111 binary
+case 8 : SegByte = 0x7F;break; // 01111111 binary
+case 9 : SegByte = 0x6F;break; // 01101111 binary
+}
+return SegByte;
+}
+
+int main() {
+    tik1.attach(&tiker1, 0.01);
+    while(1) {
+        senzor_ulaz.fall(&ulaz);
+        senzor_izlaz.fall(&izlaz);
+        Disp=SegConvert(br);
+        if(br>=0 && br<=8)
+        zelena.light_on(t, 0, 100);
+        if(br==8 )
+        crvena.light_on(t, 0, 100);
+        if(br==9 ){
+        crvena.light_on(t, 0, 5);
+        }
+        if(t>=100)
+        t=0;
+    }
+}