-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathDataAquisition.ino
52 lines (43 loc) · 1.46 KB
/
DataAquisition.ino
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
#include <Arduino.h>
/// This file contains some helper functions to access the attached sensors and
/// the battery voltage
// Sensor pins and interupts
#define SENS1INTER 1
#define SENS2INTER 4
#define SENS1PIN 2
#define SENS2PIN 7
#define BATTSENSPIN A5
const int sensorPins[] = {SENS1PIN, SENS2PIN};
int lastSensorValues[] = {0, 0};
/// Sets up the pins for the sensors
void enableSensors() {
pinMode(SENS2PIN, INPUT_PULLUP);
pinMode(SENS1PIN, INPUT_PULLUP);
pinMode(BATTSENSPIN, INPUT);
}
/// Returns the current battery volage in mV
int batteryVoltage() {
int volt = analogRead(BATTSENSPIN);
volt = map(volt, 0, 1024, 0, 15000) + 500; // compensate for diode drop
return volt;
}
/// Unused variables to be deleted in the next release
int lastSensor1, lastSensor2;
/// Reads the current value of the given sensor (0 or 1)
/// Also stores that value as the last known sensor value
int sensorValue(byte sensor) {
lastSensorValues[sensor] = !digitalRead(sensorPins[sensor]);
return lastSensorValues[sensor];
}
/// Checks if the sensor value of a given sensor (0 or 1) changed
/// since we checked it last time.
bool sensorValueChanged(byte sensor) {
int newValue = !digitalRead(sensorPins[sensor]);
bool isNew = newValue != lastSensorValues[sensor];
lastSensorValues[sensor] = newValue;
return isNew;
}
/// Checks if any of the two sensors changed since we checked last time
bool sensorValueChanged() {
return sensorValueChanged(0) || sensorValueChanged(1);
}