チャタリング防止できそうなものです。

Dependents:   2019NHK_A_manual_red 2019NHK_A_manual_red 2019NHK_A_manual_blue

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers chatteringremoval.h Source File

chatteringremoval.h

00001 #ifndef CHATTERINGREMOVAL_H
00002 #define CHATTERINGREMOVAL_H
00003 
00004 #include"mbed.h"
00005 
00006 /**
00007 * @file chttaringremove.h
00008 * @brief チャタリング防止
00009 *
00010 * Example :
00011 * @code
00012 * #include "mbed.h"
00013 * #include "chatteringremoval.h"
00014 *
00015 * chatteringremoval button1(0.01);
00016 * DigitalOut led1(LED1);
00017 * Serial pc(USBTX,USBRX,115200);
00018 * DigitalIn b(USER_BUTTON);
00019 *
00020 * int main()
00021 * {
00022 *     while(true) {
00023 *         bool b_ = b;
00024 *         button1.assignvalue(b_);
00025 *         led1 = button1.getValue() % 2;
00026 *         pc.printf("%d,%d",b_,button1.getCount());
00027 *         pc.printf("\n\r");
00028 *     }
00029 * }
00030 *
00031 *
00032 * @endcode
00033 */
00034 
00035 /**
00036 * @brief チャタリング防止用のクラス
00037 */
00038 class chatteringremoval{
00039 public:
00040     /**
00041     * @brief コンストラクタ(use_pin)
00042     * @param pin Pin that can do Digitalin
00043     * @param time chatteringtime (s)
00044     */
00045     chatteringremoval(PinName pin,float time);
00046     
00047     /**
00048     * @brief コンストラクタ(not_use_pin)
00049     * @param time chatteringtime (s)
00050     */
00051     chatteringremoval(float time);
00052     
00053     /**
00054     * @brief カウントの値を取得
00055     * @return count
00056     */
00057     unsigned int getCount();
00058     
00059     /**
00060     * @brief カウントのリセット
00061     */
00062     void countreset();
00063 
00064     /**
00065     * @brief データの代入
00066     * @param data Targetdata's value
00067     */
00068     void assignvalue(bool data);
00069   
00070     /**
00071     * @brief チャタリング抑制処理後の値を取得
00072     * @return value
00073     */
00074     bool getValue();
00075 
00076 private:
00077     void threadloop();
00078     void valuecount();
00079     void checkchattering();
00080     DigitalIn d_in;
00081     //Thread thread;
00082     Timer t;
00083     unsigned int count;
00084     bool flag;
00085     bool flag_;
00086     bool value;
00087     bool _data;
00088     bool b;
00089     bool mode;
00090     float _time;
00091 };
00092 
00093 #endif