-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomplements.h
107 lines (88 loc) · 2.37 KB
/
complements.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
Si necesita añadir otra clase de sensor
tienes que especificar lo siguiente:
variables privadas a las que se asignan los pines de los sensores
en la placa Arduino
Función para init este pin y configurar este pin
Función para leer los datos del sensor
*/
class PIR {
public:
void init(unsigned int pin_) {
pin = pin_;
pinMode(pin, INPUT); //,make this pin as input
}
bool readmotion() {
unsigned int state = digitalRead(pin); // read the pin state
if (state == HIGH) { // if motion detected
return true;
}
else { //if no motion detected
return false;
}
}
private:
unsigned int pin;
};
class Infrarrojo {
public:
void init(unsigned int pin_) {
pin = pin_;
pinMode(pin, INPUT); //,make this pin as input
}
bool readmotion() {
unsigned int state = digitalRead(pin); // read the pin state
if (state == HIGH) { // if motion detected
return true;
}
else { //if no motion detected
return false;
}
}
private:
unsigned int pin;
};
class Generico {
public:
void init(unsigned int pin_) {
pin = pin_;
pinMode(pin, INPUT); //,make this pin as input
}
bool readmotion() {
unsigned int state = digitalRead(pin); // read the pin state
if (state == HIGH) { // if motion detected
return true;
}
else { //if no motion detected
return false;
}
}
private:
unsigned int pin;
};
class HCSR04 {
private:
unsigned int out; //define pins
unsigned int echo;
public:
void init(int out, int echo) {
this->out = out;
this->echo = echo;
pinMode(this->out, OUTPUT); // comfigure pins
pinMode(this->echo, INPUT);
}
///////////////////////////////////////////////////dist
float dist()
{
// read distance using measuring distance algorthim of ultrasonic sensor
digitalWrite(this->out, LOW);
delayMicroseconds(2);
digitalWrite(this->out, HIGH);
delayMicroseconds(10);
digitalWrite(this->out, LOW);
noInterrupts();
float d = pulseIn(this->echo, HIGH);
interrupts();
return d / 58.0;
}
};