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:
- 46:7c14fc3caf52
- Parent:
- 21:363271dcfe1f
--- a/main.cpp Mon Oct 22 14:50:31 2018 +0000 +++ b/main.cpp Wed Oct 31 17:38:52 2018 +0000 @@ -30,7 +30,7 @@ FastPWM pin5(D5); // Motor 2 pwm FastPWM pin6(D6); // Motor 1 pwm DigitalOut pin7(D7); // Motor 1 direction -//float u1 = pot1; +//double u1 = pot1; // Utilisation of libraries MODSERIAL pc(USBTX, USBRX); @@ -40,23 +40,23 @@ Ticker motor; // Global variables -const float pi = 3.14159265358979; -float u3 = 0.0; // Normalised variable for the movement of motor 3 +const double pi = 3.14159265358979; +double u3 = 0.0; // Normalised variable for the movement of motor 3 // Functions void Encoderinput() { int counts1; int counts2; int counts3; - float angle1; - float angle2; - float angle3; + double angle1; + double angle2; + double angle3; counts1 = Encoder1.getPulses(); counts2 = Encoder2.getPulses(); counts3 = Encoder3.getPulses(); - angle1 = ((float)counts1*2.0*pi)/4200.0; - angle2 = ((float)counts2*2.0*pi)/4200.0; - angle3 = ((float)counts3*2.0*pi)/4200.0; + angle1 = ((double)counts1*2.0*pi)/4200.0; + angle2 = ((double)counts2*2.0*pi)/4200.0; + angle3 = ((double)counts3*2.0*pi)/4200.0; pc.printf("Counts3: %i Angle3: %f Counts2: %i Angle2: %f\r\n",counts3,angle3,counts2,angle2); } @@ -68,16 +68,16 @@ and eventually the motor will turn the other way around. */ if (button1 == 1 && button2 == 1) - { u3 = u3 + 0.1f; //In stapjes van 0.1 - if (u3>1.0f) - { u3 = 1.0f; + { u3 = u3 + 0.1; //In stapjes van 0.1 + if (u3>1.0) + { u3 = 1.0; } } else if (button1 == 0 && button2 == 1) - { u3 = u3 - 0.1f; - if (u3>1.0f) - { u3 = 1.0f; + { u3 = u3 - 0.1; + if (u3>1.0) + { u3 = 1.0; } } } @@ -88,7 +88,7 @@ shield for the moving direction and speed of motor 3. */ { - float u1 = 2.0*(pot1 - 0.5); // Normalised variable for the movement of motor 1 + double u1 = 2.0*(pot1 - 0.5); // Normalised variable for the movement of motor 1 if (u1>0) { pin4 = true; } @@ -97,7 +97,7 @@ } pin5 = fabs(u1); - float u2 = 2.0*(pot2 - 0.5); // Normalised variable for the movement of motor 2 + double u2 = 2.0*(pot2 - 0.5); // Normalised variable for the movement of motor 2 if (u2<0) { pin7 = true; }