-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtestFlameSensor2014
67 lines (63 loc) · 2.1 KB
/
testFlameSensor2014
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
int sensorPin[] = {A0,A1,A2,A4}; //an array of pin numbers to which sensors are attached
int readFSensor[4]; //an array that record sensor reading
int pinCount=3;
int ledPin[]={3,4,2};
boolean flame = false;
const int upperThreshold = 300;
const int lowerThreshold = 400;
void readFSensor()
{
for(int thisPin = 0; thisPin <= pinCount; thisPin++){
readFSensor[thisPin]=analogRead(sensorPin[thisPin]);}
};
void
// the setup routine runs once you press reset
void setup() {
Serial.begin(9600);
pinMode(ledPin[0],OUTPUT);
pinMode(ledPin[1],OUTPUT);
pinMode(ledPin[2],OUTPUT);
}
// the loop routine runs over and over again forever
void loop() {
//record sensor value into an array
for(int thisPin = 0; thisPin <= pinCount; thisPin++){
readFSensor[thisPin]=analogRead(sensorPin[thisPin]);
};
//test if the robot is in front of the flame
if (readFSensor[1] = readFSensor[2] and readFSensor[1]>upperThreshold and readFSensor[2]>upperThreshold){
digitalWrite(ledPin[1], HIGH);
flame=true;
};
//if left sensors sense something, light up left LED
if (readFSensor[0]>lowerThreshold) {
flame=false;
while (flame==false){
for(int thisPin = 0; thisPin <= pinCount; thisPin++){
readFSensor[thisPin]=analogRead(sensorPin[thisPin]);
};
digitalWrite(ledPin[0], HIGH);
if (readFSensor[1] = readFSensor[2] and readFSensor[1]>upperThreshold and readFSensor[2]>upperThreshold){
digitalWrite(ledPin[1], HIGH);
digitalWrite(ledPin[0], LOW);
flame=true;};
};
};
//if right sensors sense something, light up right LED
if (readFSensor[3]>lowerThreshold) {
flame=false;
while (flame==false){
for(int thisPin = 0; thisPin <= pinCount; thisPin++){
readFSensor[thisPin]=analogRead(sensorPin[thisPin]);
};
digitalWrite(ledPin[2], HIGH);
if (readFSensor[1] = readFSensor[2] and readFSensor[1]>upperThreshold and readFSensor[2]>upperThreshold){
digitalWrite(ledPin[1], HIGH);
flame=true;};
};
};
delay(2);
digitalWrite(ledPin[0],LOW);
digitalWrite(ledPin[1],LOW);
digitalWrite(ledPin[2],LOW);
}