encoder met een motor

Dependencies:   MODSERIAL QEI mbed

Fork of Test_motoren_met_button_encoder by Daniqe Kottelenberg

Revision:
6:93a7d2989024
Parent:
5:bb97950558bd
Child:
7:27625939c4ed
--- a/main.cpp	Fri Sep 30 12:01:06 2016 +0000
+++ b/main.cpp	Fri Sep 30 12:36:20 2016 +0000
@@ -4,35 +4,45 @@
 //alle ingangen definieren
 DigitalIn encoder1A(D13); 
 DigitalIn encoder1B(D12);
-DigitalIn button(D11);
-DigitalOut led(D10);
+DigitalIn button_cw(D11);
+DigitalIn button_ccw(D9);
+DigitalOut ledcw(D10);
+DigitalOut ledccw(D2);
 DigitalOut motor1(D4);
 PwmOut pwm_motor1(D5);
 MODSERIAL pc(USBTX, USBRX);
 
 //constanten
-const int CW = 0; //definitie rechtsom 'lage waarde'
-const int CCW =2.5; //definitie linksom 'hoge waarde'
+const int CW = 2.5; //definitie rechtsom 'lage waarde'
+const int CCW =0; //definitie linksom 'hoge waarde'
 
 //programma
 int main ()
 {
     pc.baud(115200); //contact maken met computer
-    volatile int counts; 
+    QEI Encoder(D12,D13, NC, 32);  // maakt een encoder aan! 
+    int counts;                     //variabele counts aanmaken
     while(true)
     {
-    if (button==0)
+    if (button_cw==0)
         { //als knop is aan dan
-        led=1;
+        ledcw=1;
+        motor1= CW;
+        pwm_motor1=2.5;
+        counts = Encoder.getPulses();
+        pc.printf("encoder counts: %i \r\n", counts);                          
+     
+        }
+    else if (button_ccw==0)
+        { ledccw=1;
         motor1= CCW;
         pwm_motor1=2.5;
-        QEI Encoder(D12,D13,NC,64);
         counts = Encoder.getPulses();
-        pc.printf("encoder counts %i/r/n", counts);                          
-     
-        }
-    else{ 
-    led=!led;
+        pc.printf("encoder counts: %i \r\n", counts);       
+        }    
+    
+    else { 
+    ledcw=0; ledccw=0;
     pwm_motor1=0;
         }
     }