My friend tyler is the one that got this started.
He is attempting to make a burglar alarm of sorts, basically he has a motion detector that when triggers pulls a line low, when it does, a relay is closed and a alarm sounds.
he also has a window pin that is monitored, when it goes low, another relay is closed, and a strobe light goes off.
When either alarm is triggered, a message is printed to the lcd screen, that states how many times the alarm has been set off.
The problem we are having is that the count increases the entire time the alarm is in the tripped state. Another words, if it is only tripped once, and the low condition stays the same, then it increments the count again, thus giving us a totally wrong number of times that the alarm has been tripped.
I know that we are right at figuring it out, but i have given up on it.
Here is the code we are using right now.
#include <LiquidCrystal.h>
// LiquidCrystal display with:
// rs on pin 12
// rw on pin 11
// enable on pin 10
// d4, d5, d6, d7 on pins 5, 4, 3, 2
LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);
int strobePin = 28;
int winPin = 30;
int ledPin = 13;
int inPin = 32;
int val = 0;
int Tripped = 0;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(inPin, INPUT);
pinMode(strobePin, OUTPUT);
pinMode(winPin, INPUT);
lcd.begin(2, 16); // This sets the lcd to a two line, 16char display
lcd.clear(); // clear the display
}
void loop() {
val = digitalRead(inPin);
if (val ==LOW) {
Trip(); // <--- THIS IS THE PROBLEM - it's in the wrong place or not right.
digitalWrite(ledPin, LOW);
} else {
digitalWrite(ledPin, HIGH);
// delay(25000);
}
val=digitalRead(winPin);
if(val==LOW){
digitalWrite(strobePin,LOW);
}else{
digitalWrite(strobePin,HIGH);
//delay(9000);
}
}
void Trip(){
Tripped++;
lcd.print("alarm tripped "); // Printed on default line on lcd
lcd.setCursor(0,1); // moves the cursor to the second line
lcd.print(Tripped); // prints on the second line.
lcd.print(" Times!");
lcd.home(); // Returns cursor to first line.
}
If anyone could tell us a way to change how the counter is incremented, or what we are doing wrong, please please do.
Thanks in advance.