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
main.cpp
- Committer:
- kweisbeek
- Date:
- 2018-10-12
- Revision:
- 1:ccb2f96c393a
- Parent:
- 0:5d1481a32da2
- Child:
- 2:cb7d7e31e30e
File content as of revision 1:ccb2f96c393a:
#include "mbed.h" #include "QEI.h" #define SERIAL_BAUD 115200 Serial pc(USBTX,USBRX); int counts; //Kenneth was here 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); } }