チャタリング防止できそうなものです。
Dependents: 2019NHK_A_manual_red 2019NHK_A_manual_red 2019NHK_A_manual_blue
Diff: chatteringremoval.h
- Revision:
- 2:866aa77e2fd6
- Parent:
- 1:153acc418dd4
- Child:
- 4:3c82016a7083
diff -r 153acc418dd4 -r 866aa77e2fd6 chatteringremoval.h --- a/chatteringremoval.h Fri Aug 30 06:31:54 2019 +0000 +++ b/chatteringremoval.h Mon Sep 02 01:39:35 2019 +0000 @@ -12,20 +12,23 @@ * #include "mbed.h" * #include "chatteringremoval.h" * -* chatteringremoval button1(USER_BUTTON); +* chatteringremoval button1(0.01); * DigitalOut led1(LED1); * Serial pc(USBTX,USBRX,115200); +* DigitalIn b(USER_BUTTON); * * int main() * { -* button1.setInvalidationtime_ms(100); * while(true) { -* led1 = button1.getCount() % 2; -* pc.printf("%d",button1.getCount()); +* bool b_ = b; +* button1.assignvalue(b_); +* led1 = button1.getValue() % 2; +* pc.printf("%d,%d",b_,button1.getCount()); * pc.printf("\n\r"); * } * } * +* * @endcode */ @@ -35,10 +38,17 @@ class chatteringremoval{ public: /** - * @brief コンストラクタ + * @brief コンストラクタ(use_pin) * @param pin Pin that can do Digitalin + * @param time chatteringtime (s) */ - chatteringremoval(PinName pin); + chatteringremoval(PinName pin,float time); + + /** + * @brief コンストラクタ(not_use_pin) + * @param time chatteringtime (s) + */ + chatteringremoval(float time); /** * @brief カウントの値を取得 @@ -47,38 +57,37 @@ unsigned int getCount(); /** - * @brief チャタリング時間の設定(秒) - * @param Chattering time (seconds) - */ - void setInvalidationtime_s(unsigned int time); - - /** - * @brief チャタリング時間の設定(ミリ秒) - * @param Chattering time (milliseconds) - */ - void setInvalidationtime_ms(unsigned int time); - - /** - * @brief チャタリング時間の設定(マイクロ秒) - * @param Chattering time (microseconds) - */ - void setInvalidationtime_us(unsigned int time); - - /** * @brief カウントのリセット */ void countreset(); + /** + * @brief データの代入 + * @param data Targetdata's value + */ + void assignvalue(bool data); + + /** + * @brief チャタリング抑制処理後の値を取得 + * @return value + */ + bool getValue(); private: void threadloop(); + void valuecount(); + void checkchattering(); DigitalIn d_in; Thread thread; Timer t; unsigned int count; bool flag; - bool _mode; - unsigned long long int _time; + bool flag_; + bool value; + bool _data; + bool b; + bool mode; + float _time; }; #endif \ No newline at end of file