Motor speed controlled by potmeter
Dependencies: mbed QEI HIDScope biquadFilter MODSERIAL FastPWM
Diff: main.cpp
- Revision:
- 9:c9cff697f4ab
- Parent:
- 5:78a5043b6658
- Child:
- 10:76dfdbdd20cd
--- a/main.cpp Thu Sep 19 14:51:53 2019 +0000 +++ b/main.cpp Thu Oct 03 13:05:48 2019 +0000 @@ -1,30 +1,35 @@ #include "mbed.h" //#include "HIDScope.h" -//#include "QEI.h" +#include "QEI.h" #include "MODSERIAL.h" //#include "BiQuad.h" #include "FastPWM.h" -PwmOut led(D3); +DigitalOut motor1(D4); +PwmOut e1(D5); +PwmOut e2(D6); +DigitalOut motor2(D7); + +DigitalIn encoder1a(D12); +DigitalIn encoder1b(D13); AnalogIn pot1(A1); -AnalogIn but1(A2); -AnalogIn but2(A3); - +AnalogIn pot2(A2); MODSERIAL pc(USBTX, USBRX); int main() { - pc.baud(115200); - pc.printf("\r\nStarting...\r\n\r\n"); - + pc.baud(115200); + pc.printf("\r\nStarting...\r\n\r\n"); +QEI enc1(D12,D13,NC,64,QEI::X4_ENCODING); + + while(true) + { - while (true) { - - - pc.printf("%f",pot1.read()); - led.write(pot1.read()); - - wait_ms(100); + pc.printf("%i ",enc1.getPulses()); + pc.printf("%i ",enc1.getRevolutions()); + pc.printf("%f\r\n",pot1.read()); + wait_ms(100); } -} + +} \ No newline at end of file