pulses and Revolutions

Dependencies:   QEI TextLCD mbed

Fork of LCD by Robocon_IPS

Files at this revision

API Documentation at this revision

Comitter:
iskenny4
Date:
Tue Jun 13 08:14:10 2017 +0000
Parent:
1:98945fb46bcc
Commit message:
yeah

Changed in this revision

QEI.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 98945fb46bcc -r 38cc05580c42 QEI.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/QEI.lib	Tue Jun 13 08:14:10 2017 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/users/aberk/code/QEI/#5c2ad81551aa
diff -r 98945fb46bcc -r 38cc05580c42 main.cpp
--- a/main.cpp	Thu May 25 08:57:03 2017 +0000
+++ b/main.cpp	Tue Jun 13 08:14:10 2017 +0000
@@ -1,40 +1,40 @@
 #include "mbed.h"
 #include "TextLCD.h"
+#include "QEI.h"
 
-TextLCD lcd(PA_0,PA_1,PA_4,PB_0,PC_1,PC_0); // RS, E, D4-D7
-Serial gy25(PA_9, PA_10, 115200);
-DigitalOut rw(PA_8); // RW
+// BUTTON
+InterruptIn button(USER_BUTTON);
 
-int g[3];
-char rxC[8];
+// for debugging
+//Serial pc(USBTX, USBRX, 115200);
 
-void rxIRQ(){
-    rxC[0] = gy25.getc();
-    if (rxC[0] == 170) {
-        for (int i = 1; i < 8; i++) {
-            rxC[i] = gy25.getc();
-        }
-        if (rxC[7] == 85) {
-            for (int i = 0, j =1; i < 3; i++, j+=2) {
-                g[i] = (rxC[j]<<8 | rxC[j+1])/100;
-                if (g[i] > 475)
-                    g[i] = g[i] - 476 + 180;
-            }
-        }
-    }
+// ENCODER
+#define N 1000
+QEI wheel(PA_5, PA_6, PA_7, N, QEI::X4_ENCODING); // A, B, Z, pulses/revolution, mode
+
+// 2x16 LCD
+TextLCD lcd(PC_11,PC_10,PC_0,PC_3,PC_1,PC_2); // RS, E, D4-D7
+
+void pressed() {
+    lcd.printf("Button Pressed\n");
+    wheel.reset();
 }
 
 int main()
 {
-    gy25.format(8,SerialBase::None,1);
+    //pc.format(8,SerialBase::None,1);
+    button.fall(&pressed);
     lcd.cls();
-    lcd.printf("LCD work");
-    wait(1);
-    gy25.attach(rxIRQ, RawSerial::RxIrq);
+    lcd.locate(0,0);
+    lcd.printf("Wellcome!");
+    int p,r;
     while(1) {
+        p = wheel.getPulses();
+        r = wheel.getRevolutions();
         lcd.locate(0,1);
-        lcd.printf("%d,%d,%d",g[0],g[1],g[2]);
-        wait(0.4);
+        lcd.printf("p : %i, r : %i\n",p,r);
+        //pc.printf("p : %i, r : %i\n",p,r);
+        wait(0.1);
         lcd.cls();
     }
 }
\ No newline at end of file