groep 16 / Mbed OS MoveMotors

Dependencies:   QEI MODSERIAL

Revision:
1:363c5230fe25
Parent:
0:6986a58c4515
Child:
2:f832050b1b4a
diff -r 6986a58c4515 -r 363c5230fe25 main.cpp
--- a/main.cpp	Fri Oct 04 08:25:00 2019 +0000
+++ b/main.cpp	Fri Oct 04 09:26:44 2019 +0000
@@ -7,33 +7,49 @@
 #include "MODSERIAL.h"
 
 
-DigitalOut M1(D4);
-DigitalOut M2(D7);
-PwmOut E1(D5);
-PwmOut E2(D6);
-AnalogIn Pot1(A0);
-AnalogIn Pot2(A1);
-DigitalIn M1A(D2);
-DigitalIn M1B(D3);
+DigitalOut M1(D4);  //Direction control
+DigitalOut M2(D7);  //Direction control
+PwmOut E1(D5);      //Speed control
+PwmOut E2(D6);      //Speed control
+InterruptIn Btn1(A0);  //Potentionmeter
+InterruptIn Btn2(A1);  //Potentionmeter
+DigitalIn M1A(D2);  //Encoder
+DigitalIn M1B(D3);  //Encoder
 
-float potVal1;
-float potVal2;
+//float potVal1;
+//float potVal2;
 int EncA1;
 int EncB1;
 int counts = 0;
+int speedCount = 0;
 
 //Ticker readEnc
 
 MODSERIAL pc(USBTX, USBRX);
 
-
+void speedUp(){
+    speedCount++;
+}
+void speedDown(){
+    speedCount--;
+}
 
 
 // main() runs in its own thread in the OS
 int main(){
     pc.baud(9600);
+    Btn1.rise(&speedUp);
+    Btn2.rise(&speedDown);
     while(true){
-        potVal1 = Pot1.read();
+        if(speedCount > 0){
+            M1 = 1;
+            E1 = speedCount/10;
+            }
+        else{
+            M1 = 0;
+            E1 = -speedCount/10;
+            }                
+        /*potVal1 = Pot1.read();
         potVal2 = Pot2.read();
         if (potVal1 > 0.5){
             M1 = 1;
@@ -49,6 +65,6 @@
             M2 = 0;
             E2 = -(potVal2-0.5);
         }
-        pc.printf("Pot1: %f \t Pot2: %f \n\r", potVal1, potVal2);
+        pc.printf("Pot1: %f \t Pot2: %f \n\r", potVal1, potVal2);*/
     }
 }