
Dependencies: QEI RemoteIR mbed
Fork of encoder_v2 by
main.cpp@7:e10dc3cb9212, 2017-11-29 (annotated)
- Committer:
- Joshua_Cheung
- Date:
- Wed Nov 29 02:48:57 2017 +0000
- Revision:
- 7:e10dc3cb9212
- Parent:
- 2:aa961ba3199e
- Child:
- 10:707e542688dc
kinds of goes through maze, first turn
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Joshua_Cheung | 2:aa961ba3199e | 1 | /* |
kensterino | 0:b9e03a03e580 | 2 | #include "mbed.h" |
Joshua_Cheung | 7:e10dc3cb9212 | 3 | Serial pc (PA_2, PA_3); |
Joshua_Cheung | 7:e10dc3cb9212 | 4 | /* |
kensterino | 0:b9e03a03e580 | 5 | #include "QEI.h" |
kensterino | 0:b9e03a03e580 | 6 | Serial pc (PA_2, PA_3); //serial comm enabled on pins pa_2 and pa_3 |
kensterino | 0:b9e03a03e580 | 7 | QEI encoder_Right(PB_3, PA_15, NC, 360, QEI::X4_ENCODING); |
kensterino | 0:b9e03a03e580 | 8 | QEI encoder_Left(PA_1, PC_4, NC, 360, QEI::X4_ENCODING); //forward increases pulses |
Joshua_Cheung | 2:aa961ba3199e | 9 | PwmOut m_Right_B(PC_7); |
Joshua_Cheung | 2:aa961ba3199e | 10 | PwmOut m_Right_F(PB_10); |
Joshua_Cheung | 2:aa961ba3199e | 11 | PwmOut m_Left_F(PA_7); |
Joshua_Cheung | 2:aa961ba3199e | 12 | PwmOut m_Left_B(PB_6); |
Joshua_Cheung | 2:aa961ba3199e | 13 | */ |
kensterino | 0:b9e03a03e580 | 14 | |
Joshua_Cheung | 7:e10dc3cb9212 | 15 | /*//IRR = IR Reciver |
Joshua_Cheung | 7:e10dc3cb9212 | 16 | AnalogIn RS_IRR(PA_0); //Right Side |
Joshua_Cheung | 7:e10dc3cb9212 | 17 | AnalogIn RF_IRR(PA_4); //Right Front |
Joshua_Cheung | 7:e10dc3cb9212 | 18 | AnalogIn LF_IRR(PC_1); //Left Front |
Joshua_Cheung | 7:e10dc3cb9212 | 19 | AnalogIn LS_IRR(PC_0); //Left Side |
Joshua_Cheung | 7:e10dc3cb9212 | 20 | |
Joshua_Cheung | 7:e10dc3cb9212 | 21 | //IRE = IR Emitter |
Joshua_Cheung | 7:e10dc3cb9212 | 22 | DigitalOut RS_IRE(PC_10); //Right Side |
Joshua_Cheung | 7:e10dc3cb9212 | 23 | DigitalOut RF_IRE(PC_11); //Right Front |
Joshua_Cheung | 7:e10dc3cb9212 | 24 | DigitalOut LF_IRE(PB_0); //Left Front |
Joshua_Cheung | 7:e10dc3cb9212 | 25 | DigitalOut LS_IRE(PB_7); //Left Side |
Joshua_Cheung | 7:e10dc3cb9212 | 26 | |
kensterino | 0:b9e03a03e580 | 27 | //QEI functions |
kensterino | 0:b9e03a03e580 | 28 | /* |
kensterino | 0:b9e03a03e580 | 29 | void reset (void) |
kensterino | 0:b9e03a03e580 | 30 | Reset the encoder. |
kensterino | 0:b9e03a03e580 | 31 | int getCurrentState (void) |
kensterino | 0:b9e03a03e580 | 32 | Read the state of the encoder. |
kensterino | 0:b9e03a03e580 | 33 | int getPulses (void) |
kensterino | 0:b9e03a03e580 | 34 | Read the number of pulses recorded by the encoder. |
kensterino | 0:b9e03a03e580 | 35 | int getRevolutions (void) |
kensterino | 0:b9e03a03e580 | 36 | Read the number of revolutions recorded by the encoder on the index channel. |
kensterino | 0:b9e03a03e580 | 37 | */ |
Joshua_Cheung | 7:e10dc3cb9212 | 38 | |
Joshua_Cheung | 2:aa961ba3199e | 39 | /* |
kensterino | 0:b9e03a03e580 | 40 | int main() |
kensterino | 0:b9e03a03e580 | 41 | { |
Joshua_Cheung | 7:e10dc3cb9212 | 42 | while(1) |
Joshua_Cheung | 7:e10dc3cb9212 | 43 | { |
Joshua_Cheung | 7:e10dc3cb9212 | 44 | LS_IRE.write(1); |
Joshua_Cheung | 7:e10dc3cb9212 | 45 | float value = LS_IRR.read(); |
Joshua_Cheung | 7:e10dc3cb9212 | 46 | printf("IR Led: %f", value); |
Joshua_Cheung | 7:e10dc3cb9212 | 47 | wait(100); |
Joshua_Cheung | 7:e10dc3cb9212 | 48 | LS_IRE.write(0); |
kensterino | 0:b9e03a03e580 | 49 | } |
Joshua_Cheung | 2:aa961ba3199e | 50 | } |
Joshua_Cheung | 2:aa961ba3199e | 51 | */ |