-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSensorManagers.cpp
More file actions
160 lines (122 loc) · 4.2 KB
/
Copy pathSensorManagers.cpp
File metadata and controls
160 lines (122 loc) · 4.2 KB
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#include "HardwareSerial.h"
#include "SensorManagers.h"
//updates onces every given amount of milliseconds
#define SOIL_SENSOR_UPDATE_INTERVAL_MS 50
#define SOIL_SENSOR_THRESHOLD 500 // Adjust based on sensor values
namespace SoilSensor {
static Adafruit_seesaw sensor;
static bool sensorInitialized = false; // Track initialization status
float tempC=0;
uint16_t capread=0;
bool toggleState = false; // Current state of the toggle
bool wasTouched = false; // Tracks previous touch state
static unsigned long lastUpdateTime=0;
void setup() {
sensor = Adafruit_seesaw();
if (!sensor.begin(0x36)) {
Serial.println("ERROR! Soil sensor not found");
sensorInitialized = false; // Mark as not initialized
} else {
Serial.print("Seesaw started! Version: ");
Serial.println(sensor.getVersion(), HEX);
sensorInitialized = true; // Mark as successfully initialized
}
}
void run() {
if (sensorInitialized){
unsigned long currentMillis = millis(); // Get current time
if (currentMillis - lastUpdateTime >= SOIL_SENSOR_UPDATE_INTERVAL_MS) {
lastUpdateTime = currentMillis; // Reset timer
tempC = sensor.getTemp();
capread = sensor.touchRead(0);
if (capread > SOIL_SENSOR_THRESHOLD && !wasTouched) {
toggleState = !toggleState; // Toggle the state
wasTouched = true; // Prevent rapid toggling
}
// Detect when the touch is released
else if (capread < SOIL_SENSOR_THRESHOLD) {
wasTouched = false;
}
}
}
}
}
//SET TRUE IF YOU WANT THAT DATA COLLECTED
#define PROX_STATUS false
#define GEST_STATUS false
#define COL_STATUS true
//updates onces every given amount of milliseconds
#define PROXGESTCOL_SENSOR_UPDATE_INTERVAL_MS 30000
namespace ProxGestColSensor{
static bool sensorInitialized = false; // Track initialization status
int proximity = 0;
int r = 0, g = 0, b = 0;
static unsigned long lastUpdateTime=0;
void setup(){
if(!APDS.begin()){
Serial.println("ERROR! Failed to initializing APDS-9960(ProxGestColSensor) sensor");
}else{
sensorInitialized=true;
}
}
void run(){
if(sensorInitialized){
unsigned long currentMillis = millis(); // Get current time
if (currentMillis - lastUpdateTime >= PROXGESTCOL_SENSOR_UPDATE_INTERVAL_MS) {
lastUpdateTime = currentMillis; // Reset timer
// Check if a proximity reading is available.
if (APDS.proximityAvailable()&&PROX_STATUS) {
proximity = APDS.readProximity();
}
// // Check if a gesture reading is available
if (APDS.gestureAvailable()&&GEST_STATUS) {
int gesture = APDS.readGesture();
switch (gesture) {
case GESTURE_UP:
Serial.println("Detected UP gesture");
break;
case GESTURE_DOWN:
Serial.println("Detected DOWN gesture");
break;
case GESTURE_LEFT:
Serial.println("Detected LEFT gesture");
break;
case GESTURE_RIGHT:
Serial.println("Detected RIGHT gesture");
break;
default:
// Ignore
break;
}
}
// Check if a color reading is available
if (APDS.colorAvailable()&&COL_STATUS) {
APDS.readColor(r, g, b);
}
}
}
}
}
#define FLIGHT_SENSOR_UPDATE_INTERVAL_MS 30000
namespace TimeOfFlightSensor{
static Adafruit_VL53L0X lox = Adafruit_VL53L0X();
static bool sensorInitialized = false; // Track initialization status
VL53L0X_RangingMeasurementData_t measure;
static unsigned long lastUpdateTime=0;
void setup(){
if (!lox.begin()) {
Serial.println("ERROR! Failed to boot VL53L0X");
}else{
sensorInitialized=true;
}
}
void run(){
if(sensorInitialized){
unsigned long currentMillis = millis(); // Get current time
if (currentMillis - lastUpdateTime >= FLIGHT_SENSOR_UPDATE_INTERVAL_MS) {
lastUpdateTime = currentMillis; // Reset timer
lox.rangingTest(&measure, false); // pass in 'true' to get debug data printout!
}
}
}
}