Revision:
0:1ae25267abc0
Child:
1:b9458512717a
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Keypad.cpp	Mon May 03 21:40:24 2021 +0000
@@ -0,0 +1,105 @@
+#include "Keypad.h"
+#include "mbed.h"
+
+    Keypad::Keypad(PinName row1, PinName row2, PinName row3, PinName row4,PinName col1, PinName col2, PinName col3, PinName col4)
+        : _col(col1,col2,col3,col4), _row(row1,row2,row3,row4){}
+        
+    Timer t;
+        
+    void Keypad::visokoStanje()
+    {
+        _col = 0b1111;
+    }
+
+    void Keypad::prviStupac()
+    {
+        _col = 0b1110;
+    }
+
+    void Keypad::drugiStupac()
+    {
+        _col = 0b1101;
+    }
+
+    void Keypad::treciStupac()
+    {
+        _col = 0b1011;
+    }
+    
+     void Keypad::cetvrtiStupac()
+    {
+        _col = 0b0111;
+    }
+
+    char Keypad::keyscan()
+    {
+        t.stop();
+        t.reset();
+        char out = 'a';
+        bool state = true;
+        visokoStanje();
+        wait_ms(5);
+        t.start();
+
+        while(state == true && t.read()<30) {
+            prviStupac();
+            wait_ms(5);
+            if(_row == 0b1110) {
+                out = '1';
+                state = false;
+            } else if (_row == 0b1101) {
+                out = '4';
+                state = false;
+            } else if (_row == 0b1011) {
+                out = '7';
+                state = false;
+            } else if (_row == 0b0111) {
+                out = 'b';
+                state = false;
+            }
+
+            drugiStupac();
+            wait_ms(5);
+            if(_row == 0b1110) {
+                out = '2';
+                state = false;
+            } else if (_row == 0b1101) {
+                out = '5';
+                state = false;
+            } else if (_row == 0b1011) {
+                out = '8';
+                state = false;
+            } else if (_row == 0b0111) {
+                out = '0';
+                state = false;
+            }
+
+            treciStupac();
+            wait_ms(5);
+            if(_row == 0b1110) {
+                out = '3';
+                state = false;
+            } else if (_row == 0b1101) {
+                out = '6';
+                state = false;
+            } else if (_row == 0b1011) {
+                out = '9';
+                state = false;
+            } else if (_row == 0b0111) {
+                state = false;
+                return out;
+            }
+        }
+        
+        if(t.read()>=29){
+            t.stop();
+            t.reset();
+            out ='c';
+            return out;
+            }
+
+        visokoStanje();
+        return out;
+    }
+    
+