Rotary encoder library. Uses interrupts for reading rotation,
Fork of RPG by
RPG.h@3:e041653b7338, 2017-05-21 (annotated)
- Committer:
- kryksyh
- Date:
- Sun May 21 15:20:46 2017 +0000
- Revision:
- 3:e041653b7338
- Parent:
- 2:94d27805abda
Docs fixed
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kryksyh | 3:e041653b7338 | 1 | /* |
canderson199 | 0:4a7e5f6a59a4 | 2 | * ============================================================================= |
kryksyh | 2:94d27805abda | 3 | * Rotary Pulse Generator class (Version 1.0.0) |
canderson199 | 0:4a7e5f6a59a4 | 4 | * ============================================================================= |
canderson199 | 0:4a7e5f6a59a4 | 5 | * Copyright (c) 2012 Christopher Anderson |
kryksyh | 2:94d27805abda | 6 | * Copyright (c) 2017 Dmitry Makarenko |
canderson199 | 0:4a7e5f6a59a4 | 7 | * |
canderson199 | 0:4a7e5f6a59a4 | 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
canderson199 | 0:4a7e5f6a59a4 | 9 | * of this software and associated documentation files (the "Software"), to deal |
canderson199 | 0:4a7e5f6a59a4 | 10 | * in the Software without restriction, including without limitation the rights |
canderson199 | 0:4a7e5f6a59a4 | 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
canderson199 | 0:4a7e5f6a59a4 | 12 | * copies of the Software, and to permit persons to whom the Software is |
canderson199 | 0:4a7e5f6a59a4 | 13 | * furnished to do so, subject to the following conditions: |
canderson199 | 0:4a7e5f6a59a4 | 14 | * |
canderson199 | 0:4a7e5f6a59a4 | 15 | * The above copyright notice and this permission notice shall be included in |
canderson199 | 0:4a7e5f6a59a4 | 16 | * all copies or substantial portions of the Software. |
canderson199 | 0:4a7e5f6a59a4 | 17 | * |
canderson199 | 0:4a7e5f6a59a4 | 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
canderson199 | 0:4a7e5f6a59a4 | 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
canderson199 | 0:4a7e5f6a59a4 | 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
canderson199 | 0:4a7e5f6a59a4 | 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
canderson199 | 0:4a7e5f6a59a4 | 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
canderson199 | 0:4a7e5f6a59a4 | 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
canderson199 | 0:4a7e5f6a59a4 | 24 | * THE SOFTWARE. |
canderson199 | 0:4a7e5f6a59a4 | 25 | * ============================================================================= |
canderson199 | 0:4a7e5f6a59a4 | 26 | */ |
canderson199 | 0:4a7e5f6a59a4 | 27 | |
canderson199 | 0:4a7e5f6a59a4 | 28 | #ifndef MBED_RPG_H |
canderson199 | 0:4a7e5f6a59a4 | 29 | #define MBED_RPG_H |
canderson199 | 0:4a7e5f6a59a4 | 30 | |
canderson199 | 0:4a7e5f6a59a4 | 31 | #include "mbed.h" |
canderson199 | 0:4a7e5f6a59a4 | 32 | |
canderson199 | 1:0b389c2c21b5 | 33 | /** |
kryksyh | 3:e041653b7338 | 34 | * Rotary Pulse Generator class |
kryksyh | 3:e041653b7338 | 35 | * |
kryksyh | 3:e041653b7338 | 36 | */ |
kryksyh | 3:e041653b7338 | 37 | |
kryksyh | 3:e041653b7338 | 38 | /** |
canderson199 | 1:0b389c2c21b5 | 39 | * Constructor(Channel A input pin, Channel B input pin, Pushbutton input pin) |
canderson199 | 1:0b389c2c21b5 | 40 | */ |
canderson199 | 0:4a7e5f6a59a4 | 41 | class RPG{ |
kryksyh | 2:94d27805abda | 42 | |
canderson199 | 0:4a7e5f6a59a4 | 43 | public: |
canderson199 | 0:4a7e5f6a59a4 | 44 | RPG(PinName pA, PinName pB, PinName pPB); |
canderson199 | 0:4a7e5f6a59a4 | 45 | |
canderson199 | 0:4a7e5f6a59a4 | 46 | //Get Direction |
canderson199 | 0:4a7e5f6a59a4 | 47 | int dir(); |
kryksyh | 2:94d27805abda | 48 | |
canderson199 | 0:4a7e5f6a59a4 | 49 | //Check Push Button |
canderson199 | 0:4a7e5f6a59a4 | 50 | bool pb(); |
canderson199 | 0:4a7e5f6a59a4 | 51 | |
canderson199 | 0:4a7e5f6a59a4 | 52 | |
canderson199 | 0:4a7e5f6a59a4 | 53 | private: |
kryksyh | 2:94d27805abda | 54 | |
kryksyh | 2:94d27805abda | 55 | // Channel A |
kryksyh | 2:94d27805abda | 56 | InterruptIn IA; |
kryksyh | 2:94d27805abda | 57 | |
kryksyh | 2:94d27805abda | 58 | // Channel B |
kryksyh | 2:94d27805abda | 59 | DigitalIn B; |
kryksyh | 2:94d27805abda | 60 | |
kryksyh | 2:94d27805abda | 61 | //Push button |
canderson199 | 0:4a7e5f6a59a4 | 62 | DigitalIn PB; |
kryksyh | 2:94d27805abda | 63 | |
kryksyh | 2:94d27805abda | 64 | // Rotation counter (positive value - cw rotation, negative - ccw) |
kryksyh | 2:94d27805abda | 65 | int m_dir; |
kryksyh | 2:94d27805abda | 66 | |
kryksyh | 2:94d27805abda | 67 | // Interrupt handler for channel A, IH for CB is not required |
kryksyh | 2:94d27805abda | 68 | void onA(); |
canderson199 | 0:4a7e5f6a59a4 | 69 | }; |
canderson199 | 0:4a7e5f6a59a4 | 70 | #endif |