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@1:ccb2f96c393a, 2018-10-12 (annotated)
- Committer:
- kweisbeek
- Date:
- Fri Oct 12 08:31:16 2018 +0000
- Revision:
- 1:ccb2f96c393a
- Parent:
- 0:5d1481a32da2
- Child:
- 2:cb7d7e31e30e
hi
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
s1725696 | 0:5d1481a32da2 | 1 | #include "mbed.h" |
s1725696 | 0:5d1481a32da2 | 2 | #include "QEI.h" |
s1725696 | 0:5d1481a32da2 | 3 | |
s1725696 | 0:5d1481a32da2 | 4 | #define SERIAL_BAUD 115200 |
s1725696 | 0:5d1481a32da2 | 5 | |
s1725696 | 0:5d1481a32da2 | 6 | Serial pc(USBTX,USBRX); |
s1725696 | 0:5d1481a32da2 | 7 | int counts; |
s1725696 | 0:5d1481a32da2 | 8 | |
kweisbeek | 1:ccb2f96c393a | 9 | //Kenneth was here |
s1725696 | 0:5d1481a32da2 | 10 | DigitalOut dirpin(D4); |
s1725696 | 0:5d1481a32da2 | 11 | PwmOut pwmpin(D5); |
s1725696 | 0:5d1481a32da2 | 12 | AnalogIn pot_1(A1); |
s1725696 | 0:5d1481a32da2 | 13 | DigitalOut dirpin_2(D6); |
s1725696 | 0:5d1481a32da2 | 14 | PwmOut pwmpin_2(D7); |
s1725696 | 0:5d1481a32da2 | 15 | AnalogIn pot_2(A2); |
s1725696 | 0:5d1481a32da2 | 16 | |
s1725696 | 0:5d1481a32da2 | 17 | QEI Encoder(D12,D13,NC,64,QEI::X4_ENCODING); |
s1725696 | 0:5d1481a32da2 | 18 | |
s1725696 | 0:5d1481a32da2 | 19 | int main() |
s1725696 | 0:5d1481a32da2 | 20 | { |
s1725696 | 0:5d1481a32da2 | 21 | pc.printf("start\r\n"); |
s1725696 | 0:5d1481a32da2 | 22 | pc.baud(115200); |
s1725696 | 0:5d1481a32da2 | 23 | |
s1725696 | 0:5d1481a32da2 | 24 | pwmpin.period_us(60); |
s1725696 | 0:5d1481a32da2 | 25 | counts = Encoder.getPulses(); |
s1725696 | 0:5d1481a32da2 | 26 | |
s1725696 | 0:5d1481a32da2 | 27 | while(true){ |
s1725696 | 0:5d1481a32da2 | 28 | //motor 1 |
s1725696 | 0:5d1481a32da2 | 29 | float out_1 = pot_1 * 2.0f; |
s1725696 | 0:5d1481a32da2 | 30 | float out_2 = out_1 - 1.0f; |
s1725696 | 0:5d1481a32da2 | 31 | |
s1725696 | 0:5d1481a32da2 | 32 | dirpin.write(out_2 < 0); |
s1725696 | 0:5d1481a32da2 | 33 | |
s1725696 | 0:5d1481a32da2 | 34 | pwmpin = fabs (out_2); |
s1725696 | 0:5d1481a32da2 | 35 | |
s1725696 | 0:5d1481a32da2 | 36 | // motor 2 |
s1725696 | 0:5d1481a32da2 | 37 | float out_3 = pot_2 * 2.0f; |
s1725696 | 0:5d1481a32da2 | 38 | float out_4 = out_3 - 1.0f; |
s1725696 | 0:5d1481a32da2 | 39 | |
s1725696 | 0:5d1481a32da2 | 40 | dirpin_2.write(out_4 < 0); |
s1725696 | 0:5d1481a32da2 | 41 | |
s1725696 | 0:5d1481a32da2 | 42 | pwmpin_2 = fabs (out_4); |
s1725696 | 0:5d1481a32da2 | 43 | |
s1725696 | 0:5d1481a32da2 | 44 | pc.printf("%i\r\n", counts); |
s1725696 | 0:5d1481a32da2 | 45 | |
s1725696 | 0:5d1481a32da2 | 46 | wait(0.01); |
s1725696 | 0:5d1481a32da2 | 47 | } |
s1725696 | 0:5d1481a32da2 | 48 | } |