Adna Durakovic Amra Dautbegovic

Dependencies:   mbed N5110

Revision:
1:2100cb58a020
Parent:
0:2a690dd32304
--- a/main.cpp	Mon May 05 18:02:35 2014 +0000
+++ b/main.cpp	Mon May 05 18:23:22 2014 +0000
@@ -1,57 +1,58 @@
 #include "mbed.h"
- 
-DigitalOut redovi[4]={dp2, dp1, dp28, dp6};
-DigitalIn kolone[4]={dp9, dp10, dp11, dp13};
-char znakovi[16] = {'0', '1', '2', '3', '4', '5', '6', '7','8', '9', 'A', 'B', 'C', '\n', '#', 'D'};
-Serial pc(USBTX,USBRX);
-int znak=0;
+#include "N5110.h"
+#include <string>
+
+DigitalOut enable(dp14);
+N5110 displej(dp4,dp24,dp23,dp25,dp2,dp6,dp18);
+Serial pc(USBTX, USBRX);
+
+#define DELETE_CHAR '2'
+#define BACKSPACE_CHAR '3'
+#define ENTER_CHAR '1'
+#define ROW_NUM 5
+#define xPomak 1
+#define yPomak 1
  
-int OcitajTastaturu() {
-    for (int i=0;i<3;i++) redovi[i]=0;
-    redovi[0]=1;
-    if(kolone[0]) return 1;
-        else if(kolone[1]) return 2;
-            else if(kolone[2]) return 3;
-             else if(kolone[3]) return 10; //A
+string text = "";
+string prevText = "";
+ 
+void ispisiText() {
+    displej.clear();
+    displej.setXYAddress(0, 0);
+    int x = 0, y = 0;
     
-    for (int i=0;i<3;i++) redovi[i]=0;
-    redovi[1]=1;
-    if(kolone[0]) return 4;
-        else if(kolone[1]) return 5;
-            else if(kolone[2]) return 6;
-             else if(kolone[3]) return 11; //B
-           
-
-   for (int i=0;i<3;i++) redovi[i]=0;
-   redovi[2]=1;
-   if(kolone[0]) return 7;
-        else if(kolone[1]) return 8;
-            else if(kolone[2]) return 9;
-             else if(kolone[3]) return 12; //c
- 
-   for (int i=0;i<3;i++) redovi[i]=0;
-   redovi[3]=1;
-   if(kolone[0]) return 13; //*
-        else if(kolone[1]) return 0; 
-            else if(kolone[2]) return 14; //#
-             else if(kolone[3]) return 15; //d
-        
-    return 50;
+    for(int i = 0; i < text.length(); i++) {
+        if(text[i] == ENTER_CHAR)
+            displej.setXYAddress(0, (y+yPomak) % ROW_NUM);
+        else {
+            displej.printChar(text[i]);
+            x += xPomak;
+        }
     }
  
+  displej.refresh();
+}
  
 int main() {
-   
-     
-    while(1) {
-            znak = OcitajTastaturu();
-             if(znak <= 15 && znak >=0) {
+    enable = 1;
+    displej.init();
+    displej.setXYAddress(0, 0);
+    char znak;
+    
+    while(true) {
+        prevText = text;
+        if(pc.readable()) {
+            znak = pc.getc();
+            if(znak == DELETE_CHAR)
+                text = "";
+            else if(znak == BACKSPACE_CHAR)
+                text = text.substr(0, text.length() - 1);
+            else
+                text.push_back(znak); 
+        }   
         
-           pc.putc(znakovi[znak]);
-        wait_ms(200);
-        }
-             
- }      
-        return 0;
-}
-
+        ispisiText();
+    }
+ 
+    return 0; 
+}
\ No newline at end of file