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: BMT-K9-Regelaar MODSERIAL mbed
Fork of BMT-K9-Regelaar by
Revision 0:7bc93f851767, committed 2013-10-08
- Comitter:
- vsluiter
- Date:
- Tue Oct 08 21:57:18 2013 +0000
- Child:
- 1:9d05c0236c7e
- Commit message:
- start
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Encoder.lib Tue Oct 08 21:57:18 2013 +0000 @@ -0,0 +1,1 @@ +https://mbed.org/users/vsluiter/code/Encoder/#2dd7853c911a
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MODSERIAL.lib Tue Oct 08 21:57:18 2013 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/Sissors/code/MODSERIAL/#b04ce87dc424
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Tue Oct 08 21:57:18 2013 +0000
@@ -0,0 +1,56 @@
+#include "mbed.h"
+#include "encoder.h"
+#include "MODSERIAL.h"
+
+/** Coerce -> float in, and coerce if less than min, or larger than max **/
+void coerce(float * in, float min, float max);
+AnalogIn potmeter(PTC2);
+volatile bool looptimerflag;
+
+
+void setlooptimerflag(void)
+{
+ looptimerflag = true;
+}
+
+
+int main() {
+ Encoder motor1(PTD0,PTC9);
+ MODSERIAL pc(USBTX,USBRX);
+ PwmOut pwm_motor(PTA12);
+ DigitalOut motordir(PTD3);
+ float setpoint;
+ float new_pwm;
+ pc.baud(115200);
+ Ticker looptimer;
+ looptimer.attach(setlooptimerflag,0.01);
+ pc.printf("bla");
+ while(1) {
+ while(!looptimerflag);
+ looptimerflag = false;
+ setpoint = (potmeter.read())*2000;
+ pc.printf("s: %f, %d \n\r", setpoint, motor1.getPosition());
+ if(motor1.getPosition() > setpoint)
+ new_pwm = 0.5;
+ else
+ new_pwm = -0.5;
+
+ if(new_pwm > 0)
+ motordir = 0;
+ else
+ motordir = 1;
+ pwm_motor.write(abs(new_pwm));
+ }
+}
+
+
+//coerces value 'in' to min or max when exceeding those values
+//if you'd like to understand the statement below take a google for
+//'ternary operators'.
+void coerce(float * in, float min, float max)
+{
+ *in > min ? *in < max? : *in = max: *in = min;
+}
+
+
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Tue Oct 08 21:57:18 2013 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/a9913a65894f \ No newline at end of file
