-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSensor.cpp
More file actions
26 lines (20 loc) · 731 Bytes
/
Sensor.cpp
File metadata and controls
26 lines (20 loc) · 731 Bytes
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
#include "Sensor.h"
// Constructor
Sensor::Sensor(pin_t pin) {
_pin = pin;
// Our lines are pulled high so if the sensor is disconnected we're still good.
// This also lets us use bare sensors, rather than just the freetronics boards.
pinMode(_pin, INPUT_PULLUP);
// Test for fault. The pin should be HIGH from our pull-up. If it's low, then
// there's a short in the line and we should ignore it in the future.
_faulty = (digitalRead(_pin) == HIGH ? false : true );
}
// Returns true if the sensor is active
// Returns false if the sensor is inactive or faulty.
bool Sensor::activated() {
if (_faulty) {
return false;
}
// Sensors are pulled low when active.
return ( digitalRead(_pin) == LOW );
}