![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Committed for sharing.
Dependencies: mbed SelfBalancingRobot_BerkYasarYavuz_AdilBerkayTemiz Motor ledControl2 HC_SR04_Ultrasonic_Library
HALLFX_ENCODER.h@10:8050817ae610, 2016-08-25 (annotated)
- Committer:
- lakshmananag
- Date:
- Thu Aug 25 22:55:36 2016 +0000
- Revision:
- 10:8050817ae610
- Parent:
- 9:67f2110fce8e
First trial
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lakshmananag | 9:67f2110fce8e | 1 | #ifndef HALLFX_ENCODER_H |
lakshmananag | 9:67f2110fce8e | 2 | #define HALLFX_ENCODER_H |
lakshmananag | 9:67f2110fce8e | 3 | |
lakshmananag | 9:67f2110fce8e | 4 | /* |
lakshmananag | 9:67f2110fce8e | 5 | Basic Encoder Library for Sparkfun's Wheel Encoder Kit |
lakshmananag | 9:67f2110fce8e | 6 | Part# ROB-12629. |
lakshmananag | 9:67f2110fce8e | 7 | */ |
lakshmananag | 9:67f2110fce8e | 8 | |
lakshmananag | 9:67f2110fce8e | 9 | #include "mbed.h" |
lakshmananag | 9:67f2110fce8e | 10 | |
lakshmananag | 9:67f2110fce8e | 11 | class HALLFX_ENCODER{ |
lakshmananag | 9:67f2110fce8e | 12 | public: |
lakshmananag | 9:67f2110fce8e | 13 | /* |
lakshmananag | 9:67f2110fce8e | 14 | Constructor for Encoder objects |
lakshmananag | 9:67f2110fce8e | 15 | @param enc_in The mBed pin connected to encoder output |
lakshmananag | 9:67f2110fce8e | 16 | */ |
lakshmananag | 9:67f2110fce8e | 17 | HALLFX_ENCODER(PinName enc_in); |
lakshmananag | 9:67f2110fce8e | 18 | /* |
lakshmananag | 9:67f2110fce8e | 19 | read() returns total number of counts of the encoder. |
lakshmananag | 9:67f2110fce8e | 20 | Count can be +/- and indicates the overall direction, |
lakshmananag | 9:67f2110fce8e | 21 | (+): CW (-): CCW |
lakshmananag | 9:67f2110fce8e | 22 | @return The toltal number of counts of the encoder. |
lakshmananag | 9:67f2110fce8e | 23 | */ |
lakshmananag | 9:67f2110fce8e | 24 | long read(); |
lakshmananag | 9:67f2110fce8e | 25 | /* |
lakshmananag | 9:67f2110fce8e | 26 | reset() clears the counter to 0. |
lakshmananag | 9:67f2110fce8e | 27 | */ |
lakshmananag | 9:67f2110fce8e | 28 | void reset(); |
lakshmananag | 9:67f2110fce8e | 29 | private: |
lakshmananag | 9:67f2110fce8e | 30 | long count; // Total number of counts since start. |
lakshmananag | 9:67f2110fce8e | 31 | InterruptIn _enc_in;// Encoder Input/Interrupt Pin |
lakshmananag | 9:67f2110fce8e | 32 | /* |
lakshmananag | 9:67f2110fce8e | 33 | Increments/Decrements count on interrrupt. |
lakshmananag | 9:67f2110fce8e | 34 | */ |
lakshmananag | 9:67f2110fce8e | 35 | void callback(); // Interrupt callback function |
lakshmananag | 9:67f2110fce8e | 36 | }; |
lakshmananag | 9:67f2110fce8e | 37 | |
lakshmananag | 9:67f2110fce8e | 38 | #endif |