committing for backup

master
skybldev 3 years ago
parent 765c40dfab
commit 588b2b41a2

@ -1,3 +1,4 @@
#include "ArduinoSTL.h";
#include "tone.h"; #include "tone.h";
// Miscallaneous inputs/outputs // Miscallaneous inputs/outputs
@ -6,39 +7,32 @@
#define ARM_UNARM_BUTTON 3 // button used to arm/unarm #define ARM_UNARM_BUTTON 3 // button used to arm/unarm
#define SPKR 12 #define SPKR 12
// Security points using namespace std;
const int door1 = 4;
const int door2 = 5;
// Configuration parameters // Configuration
const String pass = "113"; // password const String pass = "113"; // password
const int securityPoints = 2; // number of security points
const int maxWarnLevel = 250; // maximum warnLevel const int maxWarnLevel = 250; // fastest beeping speed of alarm in ms
const int warnDelayRef = 300; // the number to subtract warnLevel from const int warnDelayRef = 300; // initial beeping speed of alarm
const int warnIncrement = 7; // increment maxLevel by this number const int warnIncrement = 7; // speed of alarm beeping acceleration
// Program booleans
bool isArmed = 1; // armed status. set to initialize as armed or unarmed
bool soundAlarm = 0; // should the program sound the alarm?
bool unarmButtonDown = 0; // boolean that prevents unarm right after rearm
// until unarm button is depressed
// Program variables // Program variables
int warnLevel = 0; bool isArmed = 1; // set to initialize as armed or unarmed
int isOpen[securityPoints] = { // status of security points. bool soundAlarm = 0;
false, false}; bool unarmButtonDown = 0; // unarm after arm only until button is released
bool waitingForPass = 0;
int warnLevel = 0; // warn level of alarm
bool waitingForPass = 0; String readString; // temporary string to store serial input on pass entry
String readString;
unsigned long currentMillis = millis(); unsigned long currentMillis = millis(); // reference point for timed stuff
unsigned long unarmIntTracker = 0; unsigned long unarmIntTracker = 0; // ref point for unarm timing interval
unsigned long alarmIntTracker = 0; unsigned long alarmIntTracker = 0; // ref point for alarm timing interval
bool flipflopUnarmState = LOW; bool flipflopUnarmState = LOW; // unarm led blinking status
bool flipflopAlarmState = LOW; bool flipflopAlarmState = LOW; // alarm led and beep blink status
// Melodies // Sounds
int initMelody[] = {FS4, GS4, AS4, CS5, DS5, FS5}; int initMelody[] = {FS4, GS4, AS4, CS5, DS5, FS5};
int initDurations[] = {100, 100, 100, 100, 100, 100}; int initDurations[] = {100, 100, 100, 100, 100, 100};
@ -52,12 +46,18 @@ int alarmNote = CS5;
int noteDelay = 40; int noteDelay = 40;
// Security Point (SP) storage
vector<String> SPnames; // names
vector<int> SPpins; // pins that a Security Point is connected
vector<int> SPnormpos; // normal position of sensor, 0=closed 1=open
vector<bool> SPisopen; // whether the point is open or closed
void setup() { void setup() {
Serial.begin(9600); Serial.begin(9600);
// Security points // Add security points here
pinMode(door1, INPUT_PULLUP); addSecurityPoint("Door1", 4, 1);
pinMode(door2, INPUT_PULLUP); addSecurityPoint("Door2", 5, 1);
// Misc. inputs/outputs // Misc. inputs/outputs
pinMode(ARM_UNARM_BUTTON, INPUT_PULLUP); pinMode(ARM_UNARM_BUTTON, INPUT_PULLUP);
@ -77,6 +77,17 @@ void setup() {
} }
} }
// Adds a Security Point by adding to each of the vectors.
void addSecurityPoint(String name, int pin, bool defaultPosition) {
SPnames.push_back(name);
SPpins.push_back(pin);
SPnormpos.push_back(defaultPosition);
SPisopen.push_back(false);
pinMode(pin, INPUT_PULLUP);
Serial.println(name + " has been added.");
}
// Play an array of tones. // Play an array of tones.
void playMelody(int melodyLength, int *melody, int *noteDur, int noteDelay) { void playMelody(int melodyLength, int *melody, int *noteDur, int noteDelay) {
for (int i = 0; i < melodyLength; i++) { for (int i = 0; i < melodyLength; i++) {
@ -98,28 +109,27 @@ void flipLed(int ledPin, bool &state) {
} }
void loop() { void loop() {
// - Security Points - // - Iterates through all security points -
// door1
if (digitalRead(door1) == LOW && isOpen[0] == false) {
Serial.println("Door1 has opened.");
isOpen[0] = true;
if (isArmed == true) soundAlarm = 1;
} else if (digitalRead(door1) == HIGH && isOpen[0] == true) {
isOpen[0] = false;
soundAlarm = 0;
Serial.println("Door1 has closed.");
}
// door2 for (int i = 0; i <= SPnames.size(); i++) {
if (digitalRead(door2) == LOW && isOpen[1] == false) { if (digitalRead(SPpins[i]) != SPnormpos[i]) {
Serial.println("Door2 has opened.");
isOpen[1] = true; if (SPisopen[i] == false) {
if (isArmed == true) soundAlarm = 1; SPisopen[i] = true;
} else if (digitalRead(door2) == HIGH && isOpen[1] == true) { Serial.println(SPnames[i] + " has opened.");
isOpen[1] = false; }
soundAlarm = 0;
Serial.println("Door2 has closed."); if (isArmed == true && soundAlarm == 0) soundAlarm = 1;
} else if (digitalRead(SPpins[i]) == SPnormpos[i]) {
if (SPisopen[i] == true) {
SPisopen[i] = false;
Serial.println(SPnames[i] + " has closed.");
}
if (soundAlarm == 1) soundAlarm = 0;
}
} }
// - Arm/Unarm - // - Arm/Unarm -
@ -173,11 +183,13 @@ void loop() {
} }
// - Button safety - // - Button safety -
if (digitalRead(ARM_UNARM_BUTTON) == HIGH && unarmButtonDown == 1) { if (digitalRead(ARM_UNARM_BUTTON) == HIGH && unarmButtonDown == 1) {
unarmButtonDown = 0; unarmButtonDown = 0;
} }
// - Ignore Serial input unless we're waiting for it - // - Ignore Serial input unless we're waiting for it -
if (waitingForPass == 0) { if (waitingForPass == 0) {
while (Serial.available()) { Serial.read(); } while (Serial.available()) { Serial.read(); }
} }
@ -214,4 +226,4 @@ void loop() {
warnLevel = 0; warnLevel = 0;
noTone(SPKR); noTone(SPKR);
} }
} }

Loading…
Cancel
Save