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: FastPWM mbed QEI biquadFilter HIDScope MODSERIAL
Diff: main.cpp
- Revision:
- 8:4f15670bc00b
- Parent:
- 7:7c005b3cf288
--- a/main.cpp Mon Oct 08 08:31:30 2018 +0000 +++ b/main.cpp Mon Oct 08 09:37:48 2018 +0000 @@ -1,5 +1,6 @@ #include "mbed.h" #include "FastPWM.h" +#include <math.h> Ticker motor; @@ -11,22 +12,36 @@ DigitalOut pin7(D7); // Motor 1 direction //float u1 = pot1; +//float rad1 = 1.0/4.0*PI; // Desired angle of motor 1 (needs to be calculated by the program) +//float nrad1; + void draai(){ float u1 = 2.0*(pot1 - 0.5); // Potmeter 1 connects to motor 1 - u1>0; // Determines direction of motor 1 + if (u1>0) // Determines direction of motor 1 + { pin4 = true; + } + else + { pin4 = false; + } pin5 = fabs(u1); // Determines pwm of motor 1 float u2 = 2.0*(pot2 - 0.5); // Potmeter 2 connects to motor 2 - u2>0; // Determines direction of motor 2 + if (u2>0) // Determines direction of motor 2 + { pin7 = true; + } + else + { pin7 = false; + } pin6 = fabs(u2); // Determines pwm of motor 2 } int main(){ - pin5.period_us(50); - motor.attach(draai, 0.001); - pin6.period_us(50); - motor.attach(draai, 0.001); + + while(true) - { - + { //nrad1 = rad1/PI; // Normalised desired angle of motor 1 + pin5.period_us(50); + motor.attach(draai, 0.001); + pin6.period_us(50); + motor.attach(draai, 0.001); } } \ No newline at end of file