-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathswitch.h
66 lines (62 loc) · 1.76 KB
/
switch.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*!
* @file switch v1.0
* @Copyright © 2018 Aoi Yamanishi
* @date 2018.11.16
*
* Released under the MIT license.
* see https://opensource.org/licenses/MIT
*/
#ifndef SWITCH_H
#define SWITCH_H
#include "deftype.h"
#include "mbed.h"
class Switch{
private:
DigitalIn _SWInput; //SWが付いているmbedのピン番号
PinMode _iniSet; //PullUp, PullDown, PullNone
bool SWcheck; //SWも連続入力防止用
bool old_SW; //1つ前の入力状態を保持
bool skip_flg; //スイッチ入力後チャタリング対策に一定時間無視する為のフラグ
void skip_Func(){
wait(0.05);
skip_flg = false;
}
public:
Switch(PinName pin, PinMode pull) : _SWInput(pin,pull), _iniSet(pull){
//_SWInput.mode(pull);
SWcheck = false;
old_SW = false;
skip_flg = false;
}
//入力状態の確認
bool update(void){
if(_iniSet == PullUp || _iniSet == PullNone){ //勝手に、突貫でPullNoneのモードも追加
if(!skip_flg){
if(!_SWInput && !old_SW){
old_SW = true;
return true;
}else if(_SWInput && old_SW){
old_SW = false;
return false;
}
skip_flg = true;
skip_Func();
}
return false;
}else{
if(!skip_flg){
if(_SWInput && !old_SW){
old_SW = true;
return true;
}else if(!_SWInput && old_SW){
old_SW = false;
return false;
}
skip_flg = true;
skip_Func();
}
return false;
}
}
};
#endif