Basic Encoder Library for Sparkfun's Hall- Effect Encoder Kit Part# ROB-12629
Dependents: ESP8266_pid_redbot_webserver 4180_lab4_project dotbot ShadowDistance ... more
HALLFX_ENCODER.h@0:f10558519825, 2015-12-08 (annotated)
- Committer:
- electromotivated
- Date:
- Tue Dec 08 00:09:51 2015 +0000
- Revision:
- 0:f10558519825
Upload;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
electromotivated | 0:f10558519825 | 1 | #ifndef HALLFX_ENCODER_H |
electromotivated | 0:f10558519825 | 2 | #define HALLFX_ENCODER_H |
electromotivated | 0:f10558519825 | 3 | |
electromotivated | 0:f10558519825 | 4 | /* |
electromotivated | 0:f10558519825 | 5 | Basic Encoder Library for Sparkfun's Wheel Encoder Kit |
electromotivated | 0:f10558519825 | 6 | Part# ROB-12629. |
electromotivated | 0:f10558519825 | 7 | */ |
electromotivated | 0:f10558519825 | 8 | |
electromotivated | 0:f10558519825 | 9 | #include "mbed.h" |
electromotivated | 0:f10558519825 | 10 | |
electromotivated | 0:f10558519825 | 11 | class HALLFX_ENCODER{ |
electromotivated | 0:f10558519825 | 12 | public: |
electromotivated | 0:f10558519825 | 13 | /* |
electromotivated | 0:f10558519825 | 14 | Constructor for Encoder objects |
electromotivated | 0:f10558519825 | 15 | @param enc_in The mBed pin connected to encoder output |
electromotivated | 0:f10558519825 | 16 | */ |
electromotivated | 0:f10558519825 | 17 | HALLFX_ENCODER(PinName enc_in); |
electromotivated | 0:f10558519825 | 18 | /* |
electromotivated | 0:f10558519825 | 19 | read() returns total number of counts of the encoder. |
electromotivated | 0:f10558519825 | 20 | Count can be +/- and indicates the overall direction, |
electromotivated | 0:f10558519825 | 21 | (+): CW (-): CCW |
electromotivated | 0:f10558519825 | 22 | @return The toltal number of counts of the encoder. |
electromotivated | 0:f10558519825 | 23 | */ |
electromotivated | 0:f10558519825 | 24 | long read(); |
electromotivated | 0:f10558519825 | 25 | /* |
electromotivated | 0:f10558519825 | 26 | reset() clears the counter to 0. |
electromotivated | 0:f10558519825 | 27 | */ |
electromotivated | 0:f10558519825 | 28 | void reset(); |
electromotivated | 0:f10558519825 | 29 | private: |
electromotivated | 0:f10558519825 | 30 | long count; // Total number of counts since start. |
electromotivated | 0:f10558519825 | 31 | InterruptIn _enc_in;// Encoder Input/Interrupt Pin |
electromotivated | 0:f10558519825 | 32 | /* |
electromotivated | 0:f10558519825 | 33 | Increments/Decrements count on interrrupt. |
electromotivated | 0:f10558519825 | 34 | */ |
electromotivated | 0:f10558519825 | 35 | void callback(); // Interrupt callback function |
electromotivated | 0:f10558519825 | 36 | }; |
electromotivated | 0:f10558519825 | 37 | |
electromotivated | 0:f10558519825 | 38 | #endif |