/*
-----------JTM Light Tower Momentary switch----------------
created 2022
by JTM Technologies, inc.
<http://www.jtmtechnologies.com>
modified 9/14, 2022
by Lowell Dodge
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 silence button status, toggles
int is_first_loop = 1; // variable for indicating if it is the first run of loop
int idle_state = 0;
int alarm_state = 0;
int silence_state = 0;
int idle_toggled = 0;
int alarm_toggled = 0;
int silence_toggled = 0;
void setup()
{
// initialize the LED pins as an outputs:
pinMode(green, OUTPUT);
pinMode(amber, OUTPUT);
pinMode(red, OUTPUT);
pinMode(audio, OUTPUT);
// initialize the idle, alarm, and silent pins as an input:
pinMode(toolwentidle, INPUT);
pinMode(alarmactive, INPUT);
pinMode(silence, INPUT);
}
void loop()
{
// read the state of the idle, alarm, and silence status values:
idlestatus = digitalRead(toolwentidle);
if (idlestatus != idle_state)
{
idle_toggled = 1;
idle_state = idlestatus;
}
alarmstatus = digitalRead(alarmactive);
if (alarmstatus != alarm_state)
{
alarm_toggled = 1;
alarm_state = alarmstatus;
}
silencestatus = digitalRead(silence);
if (silencestatus != silence_state)
{
silence_toggled = 1;
silence_state = silencestatus;
}
if (idle_toggled || is_first_loop)
{
digitalWrite(green, !idle_state);
digitalWrite(amber, idle_state);
}
if (alarm_toggled || is_first_loop)
{
digitalWrite(red, alarm_state);
digitalWrite(audio, alarm_state);
}
if (silence_toggled)
{
digitalWrite(audio, LOW);
}
idle_toggled = 0;
alarm_toggled = 0;
silence_toggled = 0;
is_first_loop = 0;
}