Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: Motor_with_encoder MODSERIAL QEI mbed
Fork of Project_motor by
Revision 0:bc949f735b8d, committed 2017-10-03
- 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
--- /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
