//OUTPUTS
#define mdl_Y A1
#define mdl_W A2
#define stock_H 13
//INPUTS
#define tri_1 12
#define tri_2 8
#define sig_HighPass 5
#define sig_Horn 4
//INPUTS variables
bool tri_1_state, tri_2_state, highpass_state, horn_state;
bool last_tri_1_state = LOW;
bool last_tri_2_state = LOW;
bool last_highpass_state = LOW;
bool last_horn_state = LOW;
//Millis
unsigned long lastDebounceTime_tri_1 = 0;
unsigned long lastDebounceTime_tri_2 = 0;
unsigned long lastDebounceTime_highpass = 0;
unsigned long lastDebounceTime_horn = 0;
unsigned long debounceDelay = 50;
//Loop Signal Variables
bool mode_1_stat;
bool mode_2_stat;
bool highpass_stat;
bool horn_stat;
//System Logging Notes Variable
String sys_msg = "NULL";
int8_t sys_val;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(tri_1, INPUT_PULLUP);
pinMode(tri_2, INPUT_PULLUP);
pinMode(sig_HighPass, INPUT_PULLUP);
pinMode(sig_Horn, INPUT_PULLUP);
pinMode(mdl_Y, OUTPUT);
pinMode(mdl_W, OUTPUT);
pinMode(stock_H, OUTPUT);
}
void loop() {
mode_1();
mode_2();
highpass();
horn();
stock_Output();
mdl_Output();
}
void stock_Output() {
if (highpass_stat == true)
{
digitalWrite(stock_H, HIGH);
}
else if (highpass_stat == false)
{
digitalWrite(stock_H, LOW);
}
}
void mdl_Output() {
if (mode_1_stat == true)
{
//insert output configurations here
//LOW = WHITE
if (highpass_stat == false && horn_stat == false)
{
digitalWrite(mdl_Y, LOW);
digitalWrite(mdl_W, LOW);
//Serial.println("LOW");
}
//HIGH/HIGHPASS = YELLOW & WHITE
else if (highpass_stat == true && horn_stat == false)
{
digitalWrite(mdl_Y, LOW);
digitalWrite(mdl_W, HIGH);
//Serial.println("HIGH");
}
//IN HIGH/HIGHPASS and HORN is pressed, interrupts the light
else if (highpass_stat == true && horn_stat == true)
{
digitalWrite(mdl_Y, LOW);
digitalWrite(mdl_W, LOW);
//Serial.println("HIGH / HORN");
}
//HORN ONLY = YELLOW & WHITE
else if (highpass_stat == false && horn_stat == true)
{
digitalWrite(mdl_Y, LOW);
digitalWrite(mdl_W, HIGH);
//Serial.println("HORN");
}
}
else if (mode_2_stat == true)
{
//insert output configurations here
//LOW = YELLOW
//LOW = WHITE
if (highpass_stat == false && horn_stat == false)
{
digitalWrite(mdl_W, LOW);
digitalWrite(mdl_Y, HIGH);
}
//HIGH/HIGHPASS = YELLOW & WHITE
else if (highpass_stat == true && horn_stat == false)
{
digitalWrite(mdl_Y, HIGH);
digitalWrite(mdl_W, HIGH);
}
//IN HIGH/HIGHPASS and HORN is pressed, interrupts the light
else if (highpass_stat == true && horn_stat == true)
{
digitalWrite(mdl_Y, LOW);
digitalWrite(mdl_W, LOW);
}
//HORN ONLY = YELLOW & WHITE
else if (highpass_stat == false && horn_stat == true)
{
digitalWrite(mdl_Y, HIGH);
digitalWrite(mdl_W, HIGH);
}
}
else if (mode_1_stat == false || mode_2_stat == false)
{
digitalWrite(mdl_Y, LOW);
digitalWrite(mdl_W, LOW);
}
}
void mode_1() {
//reads the input
int8_t reading = !digitalRead(tri_1);
//checks if the reading is not equals to the last state
//if not, then the new state will be recorded
//up until a new state is read from the pin
if (reading != last_tri_1_state)
{
lastDebounceTime_tri_1 = millis();
}
if ((millis() - lastDebounceTime_tri_1) > debounceDelay)
{
// if the button state has changed:
if (reading != tri_1_state)
{
tri_1_state = reading;
// only toggle if the new button state is HIGH
if (tri_1_state == HIGH)
{
//insert your running conditions or signal here
mode_1_stat = true;
sys_msg = "Mode 1 activated.";
Serial.println(sys_msg);
}
else if (tri_1_state == LOW)
{
mode_1_stat = false;
sys_msg = "Mode 1 deactivated.";
Serial.println(sys_msg);
}
}
}
//saves the last current state as last state
last_tri_1_state = reading;
}
void mode_2() {
//reads the input
int8_t reading = !digitalRead(tri_2);
//checks if the reading is not equals to the last state
//if not, then the new state will be recorded
//up until a new state is read from the pin
if (reading != last_tri_2_state)
{
lastDebounceTime_tri_2 = millis();
}
if ((millis() - lastDebounceTime_tri_2) > debounceDelay)
{
// if the button state has changed:
if (reading != tri_2_state)
{
tri_2_state = reading;
// only toggle if the new button state is HIGH
if (tri_2_state == HIGH)
{
//insert your running conditions or signal here
mode_2_stat = true;
sys_msg = "Mode 2 activated.";
Serial.println(sys_msg);
}
else if (tri_2_state == LOW)
{
//insert your running conditions or signal here
mode_2_stat = false;
sys_msg = "Mode 2 deactivated.";
Serial.println(sys_msg);
}
}
}
//saves the last current state as last state
last_tri_2_state = reading;
}
void highpass() {
//reads the input
int8_t reading = !digitalRead(sig_HighPass);
//checks if the reading is not equals to the last state
//if not, then the new state will be recorded
//up until a new state is read from the pin
if (reading != last_highpass_state)
{
lastDebounceTime_highpass = millis();
}
if ((millis() - lastDebounceTime_highpass) > debounceDelay)
{
// if the button state has changed:
if (reading != highpass_state)
{
highpass_state = reading;
// only toggle if the new button state is HIGH
if (highpass_state == HIGH)
{
//insert your running conditions or signal here
highpass_stat = true;
sys_msg = "Highpass is pressed.";
Serial.println(sys_msg);
}
else if (highpass_state == LOW)
{
highpass_stat = false;
sys_msg = "Highpass is released.";
Serial.println(sys_msg);
}
}
}
//saves the last current state as last state
last_highpass_state = reading;
}
void horn() {
//reads the input
int8_t reading = !digitalRead(sig_Horn);
//checks if the reading is not equals to the last state
//if not, then the new state will be recorded
//up until a new state is read from the pin
if (reading != last_horn_state)
{
lastDebounceTime_horn = millis();
}
if ((millis() - lastDebounceTime_horn) > debounceDelay)
{
// if the button state has changed:
if (reading != horn_state)
{
horn_state = reading;
// only toggle if the new button state is HIGH
if (horn_state == HIGH)
{
//insert your running conditions or signal here
horn_stat = true;
sys_msg = "Horn is pressed.";
Serial.println(sys_msg);
}
else if (horn_state == LOW)
{
horn_stat = false;
sys_msg = "Horn is released.";
Serial.println(sys_msg);
}
}
}
//saves the last current state as last state
last_horn_state = reading;
}