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-14
- Revision:
- 2:cb7d7e31e30e
- Parent:
- 1:ccb2f96c393a
- Child:
- 3:e533800b2ef8
File content as of revision 2:cb7d7e31e30e:
#include "mbed.h" #include "QEI.h" #define SERIAL_BAUD 115200 Serial pc(USBTX,USBRX); DigitalOut dirpin(D4); DigitalOut dirpin_2(D6); PwmOut pwmpin(D5); PwmOut pwmpin_2(D7); AnalogIn pot_1(A1); //only using one potmeter for both motors, eventually just use a signal created by program or EMG-signals QEI Encoder(D12,D13,NC,64,QEI::X4_ENCODING); //channel A=D12, channel B=D13 int main() { //float out_1=1.0f; //set potmeter signal as a predetermined digital signal pc.baud(115200); //also set baudrate to 115200 in teraterm! pc.printf("start\r\n"); pwmpin.period_us(60); //??? while(1){ float out_1 = (pot_1 * 2.0f) - 1.0f; //scales potmeter signal from 0 to 1 into -1 to 1 dirpin.write(out_1 < 0); //sets direction of motor? if negative =true (1), if positive =false (0) pwmpin = fabs (out_1); //sets speed of motor? pc.printf("%i\r\n", Encoder.getPulses()); //prints the amount of counts wait(0.1); //repeat loop every 0.01 sec } }