チャタリング防止できそうなものです。
Dependents: 2019NHK_A_manual_red 2019NHK_A_manual_red 2019NHK_A_manual_blue
chatteringremoval.h
- Committer:
- skouki
- Date:
- 2019-08-30
- Revision:
- 1:153acc418dd4
- Parent:
- 0:443871490643
- Child:
- 2:866aa77e2fd6
File content as of revision 1:153acc418dd4:
#ifndef CHATTERINGREMOVAL_H #define CHATTERINGREMOVAL_H #include"mbed.h" /** * @file chttaringremove.h * @brief チャタリング防止 * * Example : * @code * #include "mbed.h" * #include "chatteringremoval.h" * * chatteringremoval button1(USER_BUTTON); * DigitalOut led1(LED1); * Serial pc(USBTX,USBRX,115200); * * int main() * { * button1.setInvalidationtime_ms(100); * while(true) { * led1 = button1.getCount() % 2; * pc.printf("%d",button1.getCount()); * pc.printf("\n\r"); * } * } * * @endcode */ /** * @brief チャタリング防止用のクラス */ class chatteringremoval{ public: /** * @brief コンストラクタ * @param pin Pin that can do Digitalin */ chatteringremoval(PinName pin); /** * @brief カウントの値を取得 * @return count */ 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(); private: void threadloop(); DigitalIn d_in; Thread thread; Timer t; unsigned int count; bool flag; bool _mode; unsigned long long int _time; }; #endif