7da2236af4
added arduino code is the read out of the sensor via an arduino. the raspicode is moved to its own section.
66 lines
1.3 KiB
C++
66 lines
1.3 KiB
C++
# arduino Duemilanove
|
|
#define IR_INPUT_PIN A0
|
|
#define IR_LED_PIN 13
|
|
|
|
#define status_red_PIN 12
|
|
#define status_yellow_PIN 11
|
|
#define status_green_PIN 10
|
|
|
|
|
|
|
|
void setup(){
|
|
Serial.begin(9600);
|
|
pinMode(IR_INPUT_PIN, INPUT);
|
|
pinMode(IR_LED_PIN, OUTPUT);
|
|
|
|
pinMode(status_red_PIN, OUTPUT);
|
|
pinMode(status_yellow_PIN, OUTPUT);
|
|
pinMode(status_green_PIN, OUTPUT);
|
|
}
|
|
|
|
|
|
int threshold = 900;
|
|
int value_b4 = 900;
|
|
|
|
int value = 0;
|
|
|
|
void loop(){
|
|
int ambient = 0;
|
|
int lit = 0;
|
|
|
|
|
|
digitalWrite(IR_LED_PIN, LOW);
|
|
delay(5); //To give ADC and LED transition time
|
|
ambient = analogRead(IR_INPUT_PIN);
|
|
|
|
digitalWrite(IR_LED_PIN, HIGH);
|
|
delay(5);
|
|
lit = analogRead(IR_INPUT_PIN);
|
|
|
|
value = ((lit - ambient) + value_b4) / 2; // small filter
|
|
|
|
Serial.print(value);
|
|
Serial.print(" ");
|
|
Serial.println(ambient);
|
|
delay(500);
|
|
|
|
if (value >= threshold) {
|
|
digitalWrite(status_red_PIN, HIGH);
|
|
digitalWrite(status_yellow_PIN, LOW);
|
|
digitalWrite(status_green_PIN, LOW);
|
|
}
|
|
|
|
//if (value < 977 && value >= 964) {
|
|
// digitalWrite(status_red_PIN, LOW);
|
|
// digitalWrite(status_yellow_PIN, HIGH);
|
|
// digitalWrite(status_green_PIN, LOW);
|
|
//}
|
|
|
|
if (value < threshold) {
|
|
digitalWrite(status_red_PIN, LOW);
|
|
digitalWrite(status_yellow_PIN, LOW);
|
|
digitalWrite(status_green_PIN, HIGH);
|
|
}
|
|
|
|
value_b4 = value;
|
|
}
|