1 |
#include "Adafruit_VL53L0X.h"
|
2 |
#include "Adafruit_TCS34725.h"
|
3 |
#include <Wire.h>
|
4 |
|
5 |
// address we will assign if dual sensor is present
|
6 |
#define LOX1_ADDRESS 0x30
|
7 |
#define LOX2_ADDRESS 0x31
|
8 |
|
9 |
// set the pins to shutdown
|
10 |
#define SHT_LOX1 32
|
11 |
#define SHT_LOX2 33
|
12 |
#define commonAnode true //TCS Sensor
|
13 |
const int sensor1 = 34; // Flammensensor oben
|
14 |
const int sensor2 = 35; // Flammensensor unten
|
15 |
const int RELAYGreen = 12; // Relaispin für grüne LED
|
16 |
const int RELAYOrange = 14; // Relaispin für orange LED
|
17 |
const int RELAYRed = 27; // Relaispin für rote LED
|
18 |
const int RELAYBuzzer = 26; // Relaispin für Buzzer
|
19 |
const int RELAYPump = 25; // Relaispin für Pumpe
|
20 |
int output1 = 0;
|
21 |
int output2 = 0;
|
22 |
byte gammatable[256];//TCS Sensor
|
23 |
|
24 |
// objects for the vl53l0x
|
25 |
Adafruit_VL53L0X lox1 = Adafruit_VL53L0X();
|
26 |
Adafruit_VL53L0X lox2 = Adafruit_VL53L0X();
|
27 |
Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_50MS, TCS34725_GAIN_4X);
|
28 |
|
29 |
// this holds the measurement
|
30 |
VL53L0X_RangingMeasurementData_t measure1;
|
31 |
VL53L0X_RangingMeasurementData_t measure2;
|
32 |
|
33 |
|
34 |
void setID() {
|
35 |
// all reset
|
36 |
digitalWrite(SHT_LOX1, LOW);
|
37 |
digitalWrite(SHT_LOX2, LOW);
|
38 |
delay(10);
|
39 |
// all unreset
|
40 |
digitalWrite(SHT_LOX1, HIGH);
|
41 |
digitalWrite(SHT_LOX2, HIGH);
|
42 |
delay(10);
|
43 |
|
44 |
// activating LOX1 and resetting LOX2
|
45 |
digitalWrite(SHT_LOX1, HIGH);
|
46 |
digitalWrite(SHT_LOX2, LOW);
|
47 |
|
48 |
// initing LOX1
|
49 |
if(!lox1.begin(LOX1_ADDRESS)) {
|
50 |
Serial.println(F("Failed to boot first VL53L0X"));
|
51 |
while(1);
|
52 |
}
|
53 |
delay(10);
|
54 |
|
55 |
// activating LOX2
|
56 |
digitalWrite(SHT_LOX2, HIGH);
|
57 |
delay(10);
|
58 |
|
59 |
//initing LOX2
|
60 |
if(!lox2.begin(LOX2_ADDRESS)) {
|
61 |
Serial.println(F("Failed to boot second VL53L0X"));
|
62 |
while(1);
|
63 |
}
|
64 |
}
|
65 |
|
66 |
void read_dual_sensors() {
|
67 |
|
68 |
lox1.rangingTest(&measure1, false); // pass in 'true' to get debug data printout!
|
69 |
lox2.rangingTest(&measure2, false); // pass in 'true' to get debug data printout!
|
70 |
|
71 |
// print sensor one reading
|
72 |
Serial.print(F("1: "));
|
73 |
if(measure1.RangeStatus != 4) { // if not out of range
|
74 |
Serial.print(measure1.RangeMilliMeter);
|
75 |
} else {
|
76 |
Serial.print(F("Out of range"));
|
77 |
}
|
78 |
|
79 |
Serial.print(F(" "));
|
80 |
|
81 |
// print sensor two reading
|
82 |
Serial.print(F("2: "));
|
83 |
if(measure2.RangeStatus != 4) {
|
84 |
Serial.print(measure2.RangeMilliMeter);
|
85 |
} else {
|
86 |
Serial.print(F("Out of range"));
|
87 |
}
|
88 |
|
89 |
Serial.println();
|
90 |
}
|
91 |
|
92 |
void setup() {
|
93 |
Serial.println(F("Starting..."));
|
94 |
setID();
|
95 |
if (tcs.begin()) {
|
96 |
//Serial.println("Found sensor");
|
97 |
} else {
|
98 |
Serial.println("No TCS34725 found ... check your connections");
|
99 |
while (1); // halt!
|
100 |
}
|
101 |
|
102 |
Serial.begin(9600);
|
103 |
pinMode(sensor1,INPUT); //
|
104 |
pinMode(sensor2,INPUT); //
|
105 |
pinMode(RELAYRed,OUTPUT);
|
106 |
|
107 |
// wait until serial port opens for native USB devices
|
108 |
while (! Serial) { delay(1); }
|
109 |
|
110 |
pinMode(SHT_LOX1, OUTPUT);
|
111 |
pinMode(SHT_LOX2, OUTPUT);
|
112 |
|
113 |
Serial.println(F("Shutdown pins inited..."));
|
114 |
|
115 |
digitalWrite(SHT_LOX1, LOW);
|
116 |
digitalWrite(SHT_LOX2, LOW);
|
117 |
|
118 |
Serial.println(F("Both in reset mode...(pins are low)"));
|
119 |
|
120 |
|
121 |
for (int i=0; i<256; i++) {
|
122 |
float x = i;
|
123 |
x /= 255;
|
124 |
x = pow(x, 2.5);
|
125 |
x *= 255;
|
126 |
|
127 |
if (commonAnode) {
|
128 |
gammatable[i] = 255 - x;
|
129 |
} else {
|
130 |
gammatable[i] = x;
|
131 |
}
|
132 |
//Serial.println(gammatable[i]);
|
133 |
}
|
134 |
}
|
135 |
|
136 |
void loop() {
|
137 |
|
138 |
read_dual_sensors();
|
139 |
output1 = digitalRead(sensor1);
|
140 |
output2 = digitalRead(sensor2); // Feuer?
|
141 |
if (output1==1 or output2==1) {
|
142 |
Serial.print("FIRE DETECTED!");
|
143 |
Serial.print("Output1= ");
|
144 |
Serial.print(output1);
|
145 |
Serial.print("; Output2= ");
|
146 |
Serial.print(output2);
|
147 |
Serial.print(";");
|
148 |
digitalWrite(RELAYRed,HIGH);}
|
149 |
else {digitalWrite(RELAYRed,LOW);}
|
150 |
|
151 |
delay(100);
|
152 |
float red, green, blue;
|
153 |
|
154 |
tcs.setInterrupt(false); // turn on LED
|
155 |
delay(60); // takes 50ms to read
|
156 |
tcs.getRGB(&red, &green, &blue);
|
157 |
tcs.setInterrupt(true); // turn off LED
|
158 |
|
159 |
Serial.print("R:\t"); Serial.print(int(red));
|
160 |
Serial.print("\tG:\t"); Serial.print(int(green));
|
161 |
Serial.print("\tB:\t"); Serial.print(int(blue));
|
162 |
|
163 |
// Serial.print("\t");
|
164 |
// Serial.print((int)red, HEX); Serial.print((int)green, HEX); Serial.print((int)blue, HEX);
|
165 |
Serial.print("\n");
|
166 |
}
|