encoder library
main.cpp@1:5dde31466ecb, 2021-05-30 (annotated)
- Committer:
- Yamanobe
- Date:
- Sun May 30 07:32:02 2021 +0000
- Revision:
- 1:5dde31466ecb
aa
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Yamanobe | 1:5dde31466ecb | 1 | #include "mbed.h" |
Yamanobe | 1:5dde31466ecb | 2 | #include "Encoder.h" |
Yamanobe | 1:5dde31466ecb | 3 | //#include "core_cm3.h" |
Yamanobe | 1:5dde31466ecb | 4 | |
Yamanobe | 1:5dde31466ecb | 5 | Encoder encoder(A0, A1); |
Yamanobe | 1:5dde31466ecb | 6 | Encoder encoder2(A2, A3); |
Yamanobe | 1:5dde31466ecb | 7 | Serial pc(USBTX,USBRX); |
Yamanobe | 1:5dde31466ecb | 8 | |
Yamanobe | 1:5dde31466ecb | 9 | int main() { |
Yamanobe | 1:5dde31466ecb | 10 | /*NVIC_SetPriority(EINT0_IRQn,0); |
Yamanobe | 1:5dde31466ecb | 11 | NVIC_SetPriority(EINT1_IRQn,1); |
Yamanobe | 1:5dde31466ecb | 12 | NVIC_SetPriority(EINT2_IRQn,2); |
Yamanobe | 1:5dde31466ecb | 13 | NVIC_SetPriority(EINT3_IRQn,3); |
Yamanobe | 1:5dde31466ecb | 14 | NVIC_SetPriority(TIMER0_IRQn,4); |
Yamanobe | 1:5dde31466ecb | 15 | NVIC_SetPriority(TIMER1_IRQn,5); |
Yamanobe | 1:5dde31466ecb | 16 | NVIC_SetPriority(TIMER2_IRQn,6); |
Yamanobe | 1:5dde31466ecb | 17 | NVIC_SetPriority(TIMER3_IRQn,7);*/ |
Yamanobe | 1:5dde31466ecb | 18 | encoder.setup(2000,0); |
Yamanobe | 1:5dde31466ecb | 19 | pc.baud(460800); |
Yamanobe | 1:5dde31466ecb | 20 | while(1) { |
Yamanobe | 1:5dde31466ecb | 21 | encoder.calculate(); |
Yamanobe | 1:5dde31466ecb | 22 | encoder2.calculate(); |
Yamanobe | 1:5dde31466ecb | 23 | pc.printf("%d, %d\r\n", int(encoder.getData(COUNT)), int(encoder2.getData(COUNT))); |
Yamanobe | 1:5dde31466ecb | 24 | wait_ms(10); |
Yamanobe | 1:5dde31466ecb | 25 | //pc.printf("COUNT_%f\tROTATION_%f\tRPM_%frpm\tDISTANCE_%fmm\tANGLE_%f\tPOSITION_%f\r\n",encoder.getData(COUNT),encoder.getData(ROTATION),encoder.getData(RPM),encoder.getData(DISTANCE),encoder.getData(ANGLE),encoder.getData(POSITION)); |
Yamanobe | 1:5dde31466ecb | 26 | } |
Yamanobe | 1:5dde31466ecb | 27 | } |