/*
**************** 4/18/2023 ****************
*** UPDATES by [email protected] ***
*******************************************
Found the alarm and audio outputs were both pulsing instead of holding high or low.
Looks like code was resetting pins during loop.
Re-coded output control.
Truth table below isn't quite accurate anymore.
Silence button in momentary and only resets after the alarm status is cleared.
*******************************************
Read digital input for tool active/idle and tool alarm
turn on/off 3 light tower lights, green-amber-red
Green On = tool ative
Amber on = tool idle
Red on = Alarm active
-----Truth table-----
----conditions---- RED GREEN AMBER AUDIO
---------------------------------
(1) idle/no alarm | F F T F
(2) active/no alarm | F T F F
(3) Idle/alarm/audible | T F T T
(4) Idle/alarm/silent | T F T F
(5) Active/alarm/audible | T T F T
(6) Active/alarm/silent | T T F F
----------The circuit:--------------
* pcb uses a 24v relay activated by idle/active input from send indexer
* interface pin pin 20(adio-9 DO-1), the relay contacts are connected
* to arduino 5v and pin 9
*
* pcb uses 24v relay activated by system alarm adio 7 DO-14,
* the relay contacts are connected to arduino 5v and pin 10
*
* the 24V is connected to P1 pin 1 and P2 pin 7 which sends pwr to light
* tower yellow wire
*
* the AMBER led output is arduino pin 11 and drives a
* 5v relay which connects common to the light tower orange wire
*
* the GREEN led output is arduino pin 12 and drives a 5v relay which
* connects common to the light tower green wire
*
* the RED led output is arduino pin 5 and drives a 5v relay which
* connects common to the light tower red wire
*
* the AUDIO output is connected to arduino pin 6 and drives a 5v relay
* which connects common to the light tower purple wire (audio)
*
* the AUDIO silence button is connected to arduino pin 7 (input) which will
* silence the buzzer while alarm is active. A momentary switch is used, so
* when the silence button is pressed, it will silence the audible alarm
* until the alarm input goes low.
*/
// constants that won't change. They're used to set pin numbers:
const int alarmactive = 10; // the number of the alarm state pin
const int toolwentidle = 9; // the number of the idle state pin
const int amber = 11; // the number of the amber LED pin
const int green = 12; // the number of the green LED pin
const int red = 5; // the number of the red LED pin
const int audio = 6; // the number of the audible pin
const int silence = 7; // the number of the silence pin
// variables that will change:
int idlestatus = 0; // variable for active/idle status 1=idle
int alarmstatus = 0; // variable for alarm status 1=alarm
int silencestatus = 0; // variable for alarm silence status 1=silent
unsigned long heartbeat_time = 0; // Tracks time since last heartbeat toggle (on built in LED).
bool last_button_state = 0; // Tracks button state from previous loop.
bool silence_flag = 0; // Tracks weather the alarm has been silenced.
void setup() {
// initialize the LED pins as an outputs:
pinMode(green, OUTPUT);
pinMode(amber, OUTPUT);
pinMode(red, OUTPUT);
pinMode(audio, OUTPUT);
pinMode(LED_BUILTIN, OUTPUT);
// initialize the idle,alarm, and silent pins as an input:
pinMode(toolwentidle, INPUT);
pinMode(alarmactive, INPUT);
pinMode(silence, INPUT);
}
void loop() {
// Heartbeat.
if ((millis() - heartbeat_time) > 200) {
heartbeat_time = millis();
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
}
// read the state of the idle,alarm,and silence status values:
idlestatus = digitalRead(toolwentidle);
alarmstatus = digitalRead(alarmactive);
silencestatus = digitalRead(silence);
// Set silence flag if button is clicked.
if (last_button_state != silencestatus) {
if (silencestatus == 1) {
silence_flag = 1;
}
}
// Track button for next loop.
last_button_state = silencestatus;
// Clear the silence_flag if we're back to no alarms.
if (alarmstatus == LOW) {
silence_flag = 0;
}
// Set online (green) and idle (amber) lamp outputs.
digitalWrite(green, !idlestatus);
digitalWrite(amber, idlestatus);
// Set the alarm lamp output (red).
digitalWrite(red, alarmstatus);
// Set the siren output if not silenced.
if (silence_flag == 0)
// Not silenced
{
digitalWrite(audio, alarmstatus);
} else
// Silenced.
{
digitalWrite(audio, LOW);
}
}