Vera Stakenborg / Mbed 2 deprecated Project_motor

Dependencies:   Motor_with_encoder MODSERIAL QEI mbed

Fork of Project_motor by Biorobotics Project

Files at this revision

API Documentation at this revision

Comitter:
vera1
Date:
Tue Oct 03 15:07:02 2017 +0000
Child:
1:e0f6cdefcd6e
Commit message:
motor speed control with pot meter, direction control with buttons. Led in progress.

Changed in this revision

Encoder_copy.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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Encoder_copy.lib	Tue Oct 03 15:07:02 2017 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/teams/Biorobotics-Project/code/Motor_with_encoder/#180dbd55929c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MODSERIAL.lib	Tue Oct 03 15:07:02 2017 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/Sissors/code/MODSERIAL/#a3b2bc878529
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Oct 03 15:07:02 2017 +0000
@@ -0,0 +1,60 @@
+#include "mbed.h"
+#include "MODSERIAL.h"
+#include "encoder.h"
+// this program can turn the motor clockwise or counterclockwise depending on the value p or n typed into the terminal. with 's' you can stop the motor
+
+MODSERIAL pc(USBTX,USBRX);
+PwmOut motorspeed(D5);
+DigitalOut motorposition(D4);
+DigitalOut led1(D8);
+DigitalOut led2(D7);
+AnalogIn pot(A1);
+DigitalIn button1(D9);
+DigitalIn button2(D10);
+Ticker potmeterreadout;
+//Ticker encoderreadout;
+//Encoder motor1(PTD0,PTC4); // motor 1 is from encoder, otherwise it would be a pain in the ass to change all that code to motorencoder
+
+
+float PwmPeriod = 1.0/5000.0;
+/*
+void readoutencoder()
+{
+    pc.printf("pos: %d, speed %f \r\n",motor1.getPosition(), motor1.getSpeed());
+}
+*/
+volatile float potvalue = 0.0;
+void readpot(){
+    potvalue = pot.read();
+    }
+int main()
+{
+    
+    //encoderreadout.attach(readoutencoder,0.2f);
+    pc.baud(9600);
+    potmeterreadout.attach(readpot,0.2f);
+    motorspeed.period(0.0001f);
+    //float motorspeed = 0.0f;
+    while (true) {
+        
+            led1 = potvalue;
+            motorspeed = potvalue;
+            pc.printf("reference velocity = %.2f\r\n", potvalue);     
+        
+
+            if ((button2 == 1)&&(button1 == 0)) {
+
+                motorposition = 0;         // motor turns anticlockwise
+                led2 = 0;
+                
+            }
+            if ((button2 ==0)&&(button1 ==1)){
+            
+                motorposition = 1;         // motor turns anticlockwise
+                led2 = 1;
+                }
+        //}
+
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue Oct 03 15:07:02 2017 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/users/mbed_official/code/mbed/builds/235179ab3f27
\ No newline at end of file