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:
- 14:e21cb701ccb8
- Parent:
- 13:6556cd086d07
- Child:
- 15:a52be6368cd5
- Child:
- 19:1d0b25d4d775
--- a/main.cpp Fri Oct 12 12:24:24 2018 +0000 +++ b/main.cpp Mon Oct 15 12:56:25 2018 +0000 @@ -5,6 +5,7 @@ #include "HIDScope.h" #include "BiQuad.h" +// Input AnalogIn pot1(A1); AnalogIn pot2(A2); InterruptIn button1(D0); @@ -14,13 +15,14 @@ everything will abort as soon as possible */ -DigitalIn pin8(D8); // Encoder 1 u3 +DigitalIn pin8(D8); // Encoder 1 B DigitalIn pin9(D9); // Encoder 1 A -DigitalIn pin10(D10); // Encoder 2 u3 +DigitalIn pin10(D10); // Encoder 2 B DigitalIn pin11(D11); // Encoder 2 A -DigitalIn pin12(D12); // Encoder 3 u3 +DigitalIn pin12(D12); // Encoder 3 B DigitalIn pin13(D13); // Encoder 3 A +// Output DigitalOut pin2(D2); // Motor 3 direction FastPWM pin3(D3); // Motor 3 pwm DigitalOut pin4(D4); // Motor 2 direction @@ -29,6 +31,7 @@ DigitalOut pin7(D7); // Motor 1 direction //float u1 = pot1; +MODSERIAL pc(USBTX, USBRX); Ticker motor; float u3 = 0.0; // Normalised variable for the movement of motor 3 @@ -38,24 +41,20 @@ simultaneously results for the turning speed of motor 3 in a slower movement, and eventually the motor will turn the other way around. */ - if (button1 == 1) - { if (button2 == 1) - { u3 = u3 + 0.1f; //In stapjes van 0.1 - pin3 = fabs(u3); + if (button1 == 1 && button2 == 1) + { u3 = u3 + 0.1f; //In stapjes van 0.1 if (u3>1.0f) { u3 = 1.0f; } } - } - else if (button1 == 0) - { if (button2 == 1) + + else if (button1 == 0 && button2 == 1) { u3 = u3 - 0.1f; - pin3 = fabs(u3); if (u3>1.0f) { u3 = 1.0f; } } - } + } void draai() @@ -90,11 +89,14 @@ } else { pin3 = 0; - } + } + pin3 = fabs(u3); } int main() { + pc.baud(115200); + pin5.period(1.0/10000); button1.rise(&draaibuttons); button2.rise(&draaibuttons);