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.cpp@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 | #include "HALLFX_ENCODER.h" |
electromotivated | 0:f10558519825 | 2 | |
electromotivated | 0:f10558519825 | 3 | HALLFX_ENCODER::HALLFX_ENCODER(PinName enc_in): _enc_in(enc_in){ |
electromotivated | 0:f10558519825 | 4 | _enc_in.mode(PullUp); |
electromotivated | 0:f10558519825 | 5 | // Invoke interrupt on both falling and rising edges |
electromotivated | 0:f10558519825 | 6 | _enc_in.fall(this, &HALLFX_ENCODER::callback); |
electromotivated | 0:f10558519825 | 7 | _enc_in.rise(this, &HALLFX_ENCODER::callback); |
electromotivated | 0:f10558519825 | 8 | } |
electromotivated | 0:f10558519825 | 9 | |
electromotivated | 0:f10558519825 | 10 | long HALLFX_ENCODER::read(){ |
electromotivated | 0:f10558519825 | 11 | return count; |
electromotivated | 0:f10558519825 | 12 | } |
electromotivated | 0:f10558519825 | 13 | |
electromotivated | 0:f10558519825 | 14 | void HALLFX_ENCODER::reset(){ |
electromotivated | 0:f10558519825 | 15 | count = 0; |
electromotivated | 0:f10558519825 | 16 | } |
electromotivated | 0:f10558519825 | 17 | |
electromotivated | 0:f10558519825 | 18 | void HALLFX_ENCODER::callback(){ |
electromotivated | 0:f10558519825 | 19 | count++; |
electromotivated | 0:f10558519825 | 20 | } |