This drive is working well with "LPD3806-600BM-G5-24G", and have Simple program, external pull-up resistance is required
注意:需要外置上拉电阻。
Rotary_Encoder.h@0:b2ffb830539c, 2019-02-02 (annotated)
- Committer:
- Yifan_Du
- Date:
- Sat Feb 02 21:19:30 2019 +0000
- Revision:
- 0:b2ffb830539c
Driver and sample program for rotary encoder. it is working well with"LDP3806-600BM-G5-24G".
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Yifan_Du | 0:b2ffb830539c | 1 | /* |
Yifan_Du | 0:b2ffb830539c | 2 | Copyright (c) 2019 Yifan DU |
Yifan_Du | 0:b2ffb830539c | 3 | |
Yifan_Du | 0:b2ffb830539c | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy |
Yifan_Du | 0:b2ffb830539c | 5 | of this software and associated documentation files (the "Software"), to deal |
Yifan_Du | 0:b2ffb830539c | 6 | in the Software without restriction, including without limitation the rights |
Yifan_Du | 0:b2ffb830539c | 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
Yifan_Du | 0:b2ffb830539c | 8 | copies of the Software, and to permit persons to whom the Software is |
Yifan_Du | 0:b2ffb830539c | 9 | furnished to do so, subject to the following conditions: |
Yifan_Du | 0:b2ffb830539c | 10 | |
Yifan_Du | 0:b2ffb830539c | 11 | The above copyright notice and this permission notice shall be included in |
Yifan_Du | 0:b2ffb830539c | 12 | all copies or substantial portions of the Software. |
Yifan_Du | 0:b2ffb830539c | 13 | |
Yifan_Du | 0:b2ffb830539c | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
Yifan_Du | 0:b2ffb830539c | 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
Yifan_Du | 0:b2ffb830539c | 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
Yifan_Du | 0:b2ffb830539c | 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
Yifan_Du | 0:b2ffb830539c | 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
Yifan_Du | 0:b2ffb830539c | 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
Yifan_Du | 0:b2ffb830539c | 20 | THE SOFTWARE. |
Yifan_Du | 0:b2ffb830539c | 21 | |
Yifan_Du | 0:b2ffb830539c | 22 | |
Yifan_Du | 0:b2ffb830539c | 23 | 1.0 2-Feb.-2019 - Initial release. |
Yifan_Du | 0:b2ffb830539c | 24 | |
Yifan_Du | 0:b2ffb830539c | 25 | ***************************************************************** |
Yifan_Du | 0:b2ffb830539c | 26 | Attention: This drive is working well with "LPD3806-600GM-G5-24G' |
Yifan_Du | 0:b2ffb830539c | 27 | ***************************************************************** |
Yifan_Du | 0:b2ffb830539c | 28 | @code |
Yifan_Du | 0:b2ffb830539c | 29 | #include "mbed.h" |
Yifan_Du | 0:b2ffb830539c | 30 | #include "Rotary_Encoder.h" |
Yifan_Du | 0:b2ffb830539c | 31 | |
Yifan_Du | 0:b2ffb830539c | 32 | Rotary_Encoder Encoder(PA_0, PA_1); |
Yifan_Du | 0:b2ffb830539c | 33 | |
Yifan_Du | 0:b2ffb830539c | 34 | int main(void) |
Yifan_Du | 0:b2ffb830539c | 35 | { |
Yifan_Du | 0:b2ffb830539c | 36 | while(1) |
Yifan_Du | 0:b2ffb830539c | 37 | { |
Yifan_Du | 0:b2ffb830539c | 38 | printf("Direction: %s\r\n", Encoder.Calculate_Direction()); |
Yifan_Du | 0:b2ffb830539c | 39 | printf("\r\n"); |
Yifan_Du | 0:b2ffb830539c | 40 | |
Yifan_Du | 0:b2ffb830539c | 41 | wait(0.2); |
Yifan_Du | 0:b2ffb830539c | 42 | } |
Yifan_Du | 0:b2ffb830539c | 43 | } |
Yifan_Du | 0:b2ffb830539c | 44 | @endcode |
Yifan_Du | 0:b2ffb830539c | 45 | ***************************************************************** |
Yifan_Du | 0:b2ffb830539c | 46 | */ |
Yifan_Du | 0:b2ffb830539c | 47 | |
Yifan_Du | 0:b2ffb830539c | 48 | #ifndef _ROTARY_ENCODER_H_ |
Yifan_Du | 0:b2ffb830539c | 49 | #define _ROTARY_ENCODER_H_ |
Yifan_Du | 0:b2ffb830539c | 50 | |
Yifan_Du | 0:b2ffb830539c | 51 | #include "mbed.h" |
Yifan_Du | 0:b2ffb830539c | 52 | |
Yifan_Du | 0:b2ffb830539c | 53 | class Rotary_Encoder |
Yifan_Du | 0:b2ffb830539c | 54 | { |
Yifan_Du | 0:b2ffb830539c | 55 | private: |
Yifan_Du | 0:b2ffb830539c | 56 | char Direction[5]; |
Yifan_Du | 0:b2ffb830539c | 57 | int Encoder_Counter; |
Yifan_Du | 0:b2ffb830539c | 58 | InterruptIn Green_Pin, White_Pin; |
Yifan_Du | 0:b2ffb830539c | 59 | |
Yifan_Du | 0:b2ffb830539c | 60 | public: |
Yifan_Du | 0:b2ffb830539c | 61 | Rotary_Encoder(PinName White, PinName Green); |
Yifan_Du | 0:b2ffb830539c | 62 | // @Param White The pin whitch is connected to the encoder white line. |
Yifan_Du | 0:b2ffb830539c | 63 | // @Param Green The pin whitch is connected to the encoder green line. |
Yifan_Du | 0:b2ffb830539c | 64 | |
Yifan_Du | 0:b2ffb830539c | 65 | void Green_Pin_Rise(void); |
Yifan_Du | 0:b2ffb830539c | 66 | // Change 'Encoder_Direction' when detecting voltage in 'Green Pin' from LOW to HIGH. |
Yifan_Du | 0:b2ffb830539c | 67 | |
Yifan_Du | 0:b2ffb830539c | 68 | void White_Pin_Rise(void); |
Yifan_Du | 0:b2ffb830539c | 69 | // Change 'Encoder_Direction' when detecting voltage in 'White Pin' from LOW to HIGH. |
Yifan_Du | 0:b2ffb830539c | 70 | |
Yifan_Du | 0:b2ffb830539c | 71 | char *Calculate_Direction(void); |
Yifan_Du | 0:b2ffb830539c | 72 | // Return Direciton. |
Yifan_Du | 0:b2ffb830539c | 73 | }; |
Yifan_Du | 0:b2ffb830539c | 74 | |
Yifan_Du | 0:b2ffb830539c | 75 | #endif |