Dependencies:   Encoder MODSERIAL mbed

Files at this revision

API Documentation at this revision

Comitter:
CasperK
Date:
Mon Oct 01 14:27:53 2018 +0000
Commit message:
First try to get counts from motor encoder. Counter doesn't reset yet after 8400 counts.

Changed in this revision

Encoder.lib Show annotated file Show diff for this revision Revisions of this file
MODSERIAL.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
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 1907291f2887 Encoder.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Encoder.lib	Mon Oct 01 14:27:53 2018 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/users/vsluiter/code/Encoder/#18b000b443af
diff -r 000000000000 -r 1907291f2887 MODSERIAL.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MODSERIAL.lib	Mon Oct 01 14:27:53 2018 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/Sissors/code/MODSERIAL/#a3b2bc878529
diff -r 000000000000 -r 1907291f2887 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Oct 01 14:27:53 2018 +0000
@@ -0,0 +1,47 @@
+#include "mbed.h"
+#include "MODSERIAL.h"
+#include "encoder.h" //getPosition(), setPosition(), getSpeed()
+
+PwmOut pwmpin(D6);
+PwmOut led(D10);
+DigitalIn button(D2);
+DigitalOut directionpin(D7);
+Encoder motor1(D13,D12);
+MODSERIAL pc(USBTX, USBRX);
+
+int main()
+{   
+    int counts; //number of counts, 
+    const int max_counts = 8400; //maximum number of counts from the X4 encoding
+    int motor_angle;
+    pc.printf("** reset **\r\n");
+    directionpin = 1; //turn forward
+    led = 1; //turn led on
+
+/* this could be placed in the while loop
+    //"lompe" functions to let the counter count from 0-8400 and from -8400 to 0, could possibly be done better
+    if (counts > max_counts) {counts = 0;}
+    else if (counts < 0) {counts = max_counts;}
+    else if (counts < -1*max_counts) {counts = 0;}
+    
+    //converting the counts to degrees
+    degrees_per_count = 360/max_counts;   
+    motor_angle = counts*degrees_per_counts;
+*/
+    
+    while (true) {
+        //if the button is pressed, turn of the led and turn the motor
+        if (button == false){
+            pwmpin = 0.6;
+            led = 0; 
+        }
+        //if the button is not pressed, keep the led on and the motor off
+        else {
+            pwmpin = 0;
+            led = 1;
+        }
+        counts = motor1.getPosition(); //get the number of counts from the encoder. Will keep counting up/down if not reset or stopped
+        pc.printf("%i\r\n", counts); 
+        wait(0.1f);     
+    }
+}
\ No newline at end of file
diff -r 000000000000 -r 1907291f2887 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon Oct 01 14:27:53 2018 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/e95d10626187
\ No newline at end of file