committing for backup

master
skybldev 3 years ago
parent 765c40dfab
commit 588b2b41a2

@ -1,3 +1,4 @@
#include "ArduinoSTL.h";
#include "tone.h";
// Miscallaneous inputs/outputs
@ -6,39 +7,32 @@
#define ARM_UNARM_BUTTON 3 // button used to arm/unarm
#define SPKR 12
// Security points
const int door1 = 4;
const int door2 = 5;
using namespace std;
// Configuration parameters
const String pass = "113"; // password
const int securityPoints = 2; // number of security points
// Configuration
const String pass = "113"; // password
const int maxWarnLevel = 250; // maximum warnLevel
const int warnDelayRef = 300; // the number to subtract warnLevel from
const int warnIncrement = 7; // increment maxLevel by this number
// 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
const int maxWarnLevel = 250; // fastest beeping speed of alarm in ms
const int warnDelayRef = 300; // initial beeping speed of alarm
const int warnIncrement = 7; // speed of alarm beeping acceleration
// Program variables
int warnLevel = 0;
int isOpen[securityPoints] = { // status of security points.
false, false};
bool isArmed = 1; // set to initialize as armed or unarmed
bool soundAlarm = 0;
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;
String readString; // temporary string to store serial input on pass entry
unsigned long currentMillis = millis();
unsigned long unarmIntTracker = 0;
unsigned long alarmIntTracker = 0;
bool flipflopUnarmState = LOW;
bool flipflopAlarmState = LOW;
unsigned long currentMillis = millis(); // reference point for timed stuff
unsigned long unarmIntTracker = 0; // ref point for unarm timing interval
unsigned long alarmIntTracker = 0; // ref point for alarm timing interval
bool flipflopUnarmState = LOW; // unarm led blinking status
bool flipflopAlarmState = LOW; // alarm led and beep blink status
// Melodies
// Sounds
int initMelody[] = {FS4, GS4, AS4, CS5, DS5, FS5};
int initDurations[] = {100, 100, 100, 100, 100, 100};
@ -52,12 +46,18 @@ int alarmNote = CS5;
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() {
Serial.begin(9600);
// Security points
pinMode(door1, INPUT_PULLUP);
pinMode(door2, INPUT_PULLUP);
// Add security points here
addSecurityPoint("Door1", 4, 1);
addSecurityPoint("Door2", 5, 1);
// Misc. inputs/outputs
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.
void playMelody(int melodyLength, int *melody, int *noteDur, int noteDelay) {
for (int i = 0; i < melodyLength; i++) {
@ -98,28 +109,27 @@ void flipLed(int ledPin, bool &state) {
}
void loop() {
// - 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.");
}
// - Iterates through all security points -
// door2
if (digitalRead(door2) == LOW && isOpen[1] == false) {
Serial.println("Door2 has opened.");
isOpen[1] = true;
if (isArmed == true) soundAlarm = 1;
} else if (digitalRead(door2) == HIGH && isOpen[1] == true) {
isOpen[1] = false;
soundAlarm = 0;
Serial.println("Door2 has closed.");
for (int i = 0; i <= SPnames.size(); i++) {
if (digitalRead(SPpins[i]) != SPnormpos[i]) {
if (SPisopen[i] == false) {
SPisopen[i] = true;
Serial.println(SPnames[i] + " has opened.");
}
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 -
@ -173,11 +183,13 @@ void loop() {
}
// - Button safety -
if (digitalRead(ARM_UNARM_BUTTON) == HIGH && unarmButtonDown == 1) {
unarmButtonDown = 0;
}
// - Ignore Serial input unless we're waiting for it -
if (waitingForPass == 0) {
while (Serial.available()) { Serial.read(); }
}

Loading…
Cancel
Save