-
Notifications
You must be signed in to change notification settings - Fork 0
/
Button.h
48 lines (44 loc) · 920 Bytes
/
Button.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
#ifndef Button_h
#define Button_h
class Button {
public:
String label;
Button( String label ){
this->label = label;
}
//TODO virtual with impl? !
virtual bool isPressed(){
Serial.println("isPressed Button");
}
};
class AnalogButton: public Button {
private:
int pin;
int minAnalogValue;
int maxAnalogValue;
public:
AnalogButton(String label, int pin, int minAnalogValue, int maxAnalogValue):Button(label){
this->pin = pin;
this->minAnalogValue = minAnalogValue;
this->maxAnalogValue = maxAnalogValue;
}
bool isPressed(){
int state = analogRead(pin);
bool result = state <= maxAnalogValue && state >= minAnalogValue;
return result;
}
};
class ClassicButton: public Button {
private:
int pin;
public:
ClassicButton(String label, int pin):Button(label){
this->pin = pin;
}
bool isPressed(){
int state = digitalRead(pin);
bool result = state == HIGH;
return result;
}
};
#endif