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: QEI mbed HIDScope
Diff: main.cpp
- Revision:
- 0:5d1481a32da2
- Child:
- 1:ccb2f96c393a
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri Oct 12 08:26:51 2018 +0000 @@ -0,0 +1,48 @@ +#include "mbed.h" +#include "QEI.h" + +#define SERIAL_BAUD 115200 + +Serial pc(USBTX,USBRX); +int counts; + + +DigitalOut dirpin(D4); +PwmOut pwmpin(D5); +AnalogIn pot_1(A1); +DigitalOut dirpin_2(D6); +PwmOut pwmpin_2(D7); +AnalogIn pot_2(A2); + + QEI Encoder(D12,D13,NC,64,QEI::X4_ENCODING); + +int main() +{ + pc.printf("start\r\n"); + pc.baud(115200); + + pwmpin.period_us(60); + counts = Encoder.getPulses(); + + while(true){ + //motor 1 + float out_1 = pot_1 * 2.0f; + float out_2 = out_1 - 1.0f; + + dirpin.write(out_2 < 0); + + pwmpin = fabs (out_2); + + // motor 2 + float out_3 = pot_2 * 2.0f; + float out_4 = out_3 - 1.0f; + + dirpin_2.write(out_4 < 0); + + pwmpin_2 = fabs (out_4); + + pc.printf("%i\r\n", counts); + + wait(0.01); + } +} \ No newline at end of file