-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSensor.cpp
44 lines (43 loc) · 948 Bytes
/
Sensor.cpp
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
#include "Arduino.h"
#include "Sensor.h"
Sensor::Sensor()
{
this->analog = false;
this->type = 0;
this->source = 0;
}
Sensor::Sensor(byte pin)
{
this->pin = pin;
this->analog = false;
this->type = 0;
this->source = this->pin;
}
void Sensor::display() {
Serial.println("#####");
Serial.println("Sensor");
Serial.print("Pin: ");
Serial.println(this->pin);
Serial.print("Analog: ");
Serial.println(this->analog);
Serial.print("Source: ");
Serial.println(this->source);
}
int Sensor::read() {
Serial.println("Reading Pin Sensor...");
if(this->analog) {
this->value = analogRead(this->pin);
return this->value;
}
else {
this->value = digitalRead(this->pin);
return this->value;
}
}
SensorReading Sensor::reading() {
this->last_reading = SensorReading(this->type, this->value, this->pin, this->value_parsed);
return this->last_reading;
}
float Sensor::parse() {
return this->value_parsed;
}