Yifan DU
/
Wind_Direction
This drive is working well with "LPD3806-600BM-G5-24G", and have Simple program
Rotary_Encoder.h@3:6a91d523b146, 2019-02-19 (annotated)
- Committer:
- Yifan_Du
- Date:
- Tue Feb 19 05:31:32 2019 +0000
- Revision:
- 3:6a91d523b146
- Parent:
- 0:b2ffb830539c
Add return 'float' function
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 | 3:6a91d523b146 | 22 | 1.1 19-Feb.-2019 Add return 'float' function |
Yifan_Du | 3:6a91d523b146 | 23 | 1.0 2-Feb.-2019 Initial release. |
Yifan_Du | 0:b2ffb830539c | 24 | |
Yifan_Du | 3:6a91d523b146 | 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 | 3:6a91d523b146 | 56 | char Direction[5]; |
Yifan_Du | 3:6a91d523b146 | 57 | int Encoder_Counter; |
Yifan_Du | 3:6a91d523b146 | 58 | float Direction_Numb; |
Yifan_Du | 3:6a91d523b146 | 59 | InterruptIn Green_Pin, White_Pin; |
Yifan_Du | 0:b2ffb830539c | 60 | |
Yifan_Du | 0:b2ffb830539c | 61 | void Green_Pin_Rise(void); |
Yifan_Du | 0:b2ffb830539c | 62 | // Change 'Encoder_Direction' when detecting voltage in 'Green Pin' from LOW to HIGH. |
Yifan_Du | 0:b2ffb830539c | 63 | |
Yifan_Du | 0:b2ffb830539c | 64 | void White_Pin_Rise(void); |
Yifan_Du | 0:b2ffb830539c | 65 | // Change 'Encoder_Direction' when detecting voltage in 'White Pin' from LOW to HIGH. |
Yifan_Du | 0:b2ffb830539c | 66 | |
Yifan_Du | 3:6a91d523b146 | 67 | public: |
Yifan_Du | 3:6a91d523b146 | 68 | Rotary_Encoder(PinName White, PinName Green); |
Yifan_Du | 3:6a91d523b146 | 69 | // @Param White The pin whitch is connected to the encoder white line. |
Yifan_Du | 3:6a91d523b146 | 70 | // @Param Green The pin whitch is connected to the encoder green line. |
Yifan_Du | 3:6a91d523b146 | 71 | |
Yifan_Du | 3:6a91d523b146 | 72 | char *Show_Direction_In_char(void); |
Yifan_Du | 0:b2ffb830539c | 73 | // Return Direciton. |
Yifan_Du | 3:6a91d523b146 | 74 | |
Yifan_Du | 3:6a91d523b146 | 75 | float Calculate_Direction(void); |
Yifan_Du | 0:b2ffb830539c | 76 | }; |
Yifan_Du | 0:b2ffb830539c | 77 | |
Yifan_Du | 0:b2ffb830539c | 78 | #endif |