Created
March 2, 2023 02:49
-
-
Save CountParadox/821cc5d163a109d52e6fba2dafcad80d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <SoftwareSerial.h> | |
SoftwareSerial mySerial(1, 2); // RX, TX | |
// Pin definitions | |
// START | |
const int LED_RED_1 = 2; | |
const int LED_GREEN_1 = 3; | |
const int SWITCH_1 = 4; | |
const int LED_RED_2 = 5; | |
const int LED_GREEN_2 = 6; | |
const int SWITCH_2 = 7; | |
const int LED_RED_3 = 8; | |
const int LED_GREEN_3 = 9; | |
const int SWITCH_3 = 10; | |
const int LED_RED_4 = 11; | |
const int LED_GREEN_4 = 12; | |
const int SWITCH_4 = 13; | |
const int LED_RED_5 = A0; | |
const int LED_GREEN_5 = A1; | |
const int SWITCH_5 = A2; | |
const int LED_RED_6 = A3; | |
const int LED_GREEN_6 = A4; | |
const int SWITCH_6 = A5; | |
const int LED_RED_7 = A6; | |
const int LED_GREEN_7 = A7; | |
const int SWITCH_7 = A8; | |
const int LED_RED_8 = 14; | |
const int LED_GREEN_8 = 15; | |
const int SWITCH_8 = 16; | |
const int LED_RED_9 = 17; | |
const int LED_GREEN_9 = 18; | |
const int SWITCH_9 = 19; | |
const int LED_RED_10 = 20; | |
const int LED_GREEN_10 = 21; | |
const int SWITCH_10 = 22; | |
const int LED_RED_11 = 23; | |
const int LED_GREEN_11 = 24; | |
const int SWITCH_11 = 25; | |
const int LED_RED_12 = 26; | |
const int LED_GREEN_12 = 27; | |
const int SWITCH_12 = 28; | |
const int LED_RED_13 = 29; | |
const int LED_GREEN_13 = 30; | |
const int SWITCH_13 = 31; | |
const int LED_RED_14 = 32; | |
const int LED_GREEN_14 = 33; | |
const int SWITCH_14 = 34; | |
// END | |
// Variable definitions | |
volatile bool mute_state_1 = true; | |
volatile bool mute_state_2 = true; | |
volatile bool mute_state_3 = true; | |
volatile bool mute_state_4 = true; | |
volatile bool mute_state_5 = true; | |
volatile bool mute_state_6 = true; | |
volatile bool mute_state_7 = true; | |
volatile bool mute_state_8 = true; | |
volatile bool mute_state_9 = true; | |
volatile bool mute_state_10 = true; | |
volatile bool mute_state_11 = true; | |
volatile bool mute_state_12 = true; | |
volatile bool mute_state_13 = true; | |
volatile bool mute_state_14 = true; | |
volatile unsigned long last_interrupt_time_1 = 0; | |
volatile unsigned long last_interrupt_time_2 = 0; | |
volatile unsigned long last_interrupt_time_3 = 0; | |
volatile unsigned long last_interrupt_time_4 = 0; | |
volatile unsigned long last_interrupt_time_5 = 0; | |
volatile unsigned long last_interrupt_time_6 = 0; | |
volatile unsigned long last_interrupt_time_7 = 0; | |
volatile unsigned long last_interrupt_time_8 = 0; | |
volatile unsigned long last_interrupt_time_9 = 0; | |
volatile unsigned long last_interrupt_time_10 = 0; | |
volatile unsigned long last_interrupt_time_11 = 0; | |
volatile unsigned long last_interrupt_time_12 = 0; | |
volatile unsigned long last_interrupt_time_13 = 0; | |
volatile unsigned long last_interrupt_time_14 = 0; | |
void setup() { | |
pinMode(LED_RED_1, OUTPUT); | |
pinMode(LED_GREEN_1, OUTPUT); | |
pinMode(SWITCH_1, INPUT_PULLUP); | |
pinMode(LED_RED_2, OUTPUT); | |
pinMode(LED_GREEN_2, OUTPUT); | |
pinMode(SWITCH_2, INPUT_PULLUP); | |
// Make sure both LEDs are turned off initially | |
digitalWrite(LED_RED_1, HIGH); | |
digitalWrite(LED_GREEN_1, HIGH); | |
digitalWrite(LED_RED_2, HIGH); | |
digitalWrite(LED_GREEN_2, HIGH); | |
digitalWrite(LED_RED_3, HIGH); | |
digitalWrite(LED_GREEN_3, HIGH); | |
digitalWrite(LED_RED_4, HIGH); | |
digitalWrite(LED_GREEN_4, HIGH); | |
digitalWrite(LED_RED_5, HIGH); | |
digitalWrite(LED_GREEN_5, HIGH); | |
digitalWrite(LED_RED_6, HIGH); | |
digitalWrite(LED_GREEN_6, HIGH); | |
digitalWrite(LED_RED_7, HIGH); | |
digitalWrite(LED_GREEN_7, HIGH); | |
digitalWrite(LED_RED_8, HIGH); | |
digitalWrite(LED_GREEN_8, HIGH); | |
digitalWrite(LED_RED_9, HIGH); | |
digitalWrite(LED_GREEN_9, HIGH); | |
digitalWrite(LED_RED_10, HIGH); | |
digitalWrite(LED_GREEN_10, HIGH); | |
digitalWrite(LED_RED_11, HIGH); | |
digitalWrite(LED_GREEN_11, HIGH); | |
digitalWrite(LED_RED_12, HIGH); | |
digitalWrite(LED_GREEN_12, HIGH); | |
digitalWrite(LED_RED_13, HIGH); | |
digitalWrite(LED_GREEN_13, HIGH); | |
digitalWrite(LED_RED_14, HIGH); | |
digitalWrite(LED_GREEN_14, HIGH); | |
// Initialize serial communication | |
mySerial.begin(9600); | |
// Attach interrupt handlers for switches | |
attachInterrupt(digitalPinToInterrupt(SWITCH_1), switch_interrupt_1, CHANGE); | |
attachInterrupt(digitalPinToInterrupt(SWITCH_2), switch_interrupt_2, CHANGE); | |
attachInterrupt(digitalPinToInterrupt(SWITCH_3), switch_interrupt_3, CHANGE); | |
attachInterrupt(digitalPinToInterrupt(SWITCH_4), switch_interrupt_4, CHANGE); | |
attachInterrupt(digitalPinToInterrupt(SWITCH_5), switch_interrupt_5, CHANGE); | |
attachInterrupt(digitalPinToInterrupt(SWITCH_6), switch_interrupt_6, CHANGE); | |
attachInterrupt(digitalPinToInterrupt(SWITCH_7), switch_interrupt_7, CHANGE); | |
attachInterrupt(digitalPinToInterrupt(SWITCH_8), switch_interrupt_8, CHANGE); | |
attachInterrupt(digitalPinToInterrupt(SWITCH_9), switch_interrupt_9, CHANGE); | |
attachInterrupt(digitalPinToInterrupt(SWITCH_10), switch_interrupt_10, CHANGE); | |
attachInterrupt(digitalPinToInterrupt(SWITCH_11), switch_interrupt_11, CHANGE); | |
attachInterrupt(digitalPinToInterrupt(SWITCH_12), switch_interrupt_12, CHANGE); | |
attachInterrupt(digitalPinToInterrupt(SWITCH_13), switch_interrupt_13, CHANGE); | |
attachInterrupt(digitalPinToInterrupt(SWITCH_14), switch_interrupt_14, CHANGE); | |
} | |
void loop() { | |
// Nothing to do here | |
} | |
void switch_interrupt_1() { | |
// Check for debounce | |
unsigned long interrupt_time = millis(); | |
if (interrupt_time - last_interrupt_time_1 > 50) { | |
last_interrupt_time_1 = interrupt_time; | |
// Toggle the mute state for button 1 | |
mute_state_1 = !mute_state_1; | |
// Update the LED state for button 1 | |
digitalWrite(LED_RED_1, mute_state_1 ? LOW : HIGH); | |
digitalWrite(LED_GREEN_1, mute_state_1 ? HIGH : LOW); | |
// Send the appropriate serial command for button 1 | |
mySerial.println(mute_state_1 ? "Mic1 set mute 1 true" : "Mic1 set mute 1 false"); | |
} | |
} | |
void switch_interrupt_2() { | |
// Check for debounce | |
unsigned long interrupt_time = millis(); | |
if (interrupt_time - last_interrupt_time_2 > 50) { | |
last_interrupt_time_2 = interrupt_time; | |
// Toggle the mute state for button 2 | |
mute_state_2 = !mute_state_2; | |
// Update the LED state for button 2 | |
digitalWrite(LED_RED_2, mute_state_2 ? LOW : HIGH); | |
digitalWrite(LED_GREEN_2, mute_state_2 ? HIGH : LOW); | |
// Send the appropriate serial command for button 2 | |
mySerial.println(mute_state_2 ? "Mic2 set Mute1 true" : "Mic2 set Mute1 false"); | |
} | |
} | |
void switch_interrupt_3() { | |
// Check for debounce | |
unsigned long interrupt_time = millis(); | |
if (interrupt_time - last_interrupt_time_3 > 50) { | |
last_interrupt_time_3 = interrupt_time; | |
// Toggle the mute state for button 3 | |
mute_state_3 = !mute_state_3; | |
// Update the LED state for button 3 | |
digitalWrite(LED_RED_3, mute_state_3 ? LOW : HIGH); | |
digitalWrite(LED_GREEN_3, mute_state_3 ? HIGH : LOW); | |
// Send the appropriate serial command for button 3 | |
mySerial.println(mute_state_3 ? "Mic3 set Mute1 true" : "Mic3 set Mute1 false"); | |
} | |
} | |
void switch_interrupt_4() { | |
// Check for debounce | |
unsigned long interrupt_time = millis(); | |
if (interrupt_time - last_interrupt_time_4 > 50) { | |
last_interrupt_time_4 = interrupt_time; | |
// Toggle the mute state for button 4 | |
mute_state_4 = !mute_state_4; | |
// Update the LED state for button 4 | |
digitalWrite(LED_RED_4, mute_state_4 ? LOW : HIGH); | |
digitalWrite(LED_GREEN_4, mute_state_4 ? HIGH : LOW); | |
// Send the appropriate serial command for button 4 | |
mySerial.println(mute_state_4 ? "Mic4 set Mute1 true" : "Mic4 set Mute1 false"); | |
} | |
} | |
void switch_interrupt_5() { | |
// Check for debounce | |
unsigned long interrupt_time = millis(); | |
if (interrupt_time - last_interrupt_time_5 > 50) { | |
last_interrupt_time_5 = interrupt_time; | |
// Toggle the mute state for button 5 | |
mute_state_5 = !mute_state_5; | |
// Update the LED state for button 5 | |
digitalWrite(LED_RED_5, mute_state_5 ? LOW : HIGH); | |
digitalWrite(LED_GREEN_5, mute_state_5 ? HIGH : LOW); | |
// Send the appropriate serial command for button 5 | |
mySerial.println(mute_state_5 ? "Mic5 set Mute1 true" : "Mic5 set Mute1 false"); | |
} | |
} | |
void switch_interrupt_6() { | |
// Check for debounce | |
unsigned long interrupt_time = millis(); | |
if (interrupt_time - last_interrupt_time_6 > 50) { | |
last_interrupt_time_6 = interrupt_time; | |
// Toggle the mute state for button 6 | |
mute_state_6 = !mute_state_6; | |
// Update the LED state for button 6 | |
digitalWrite(LED_RED_6, mute_state_6 ? LOW : HIGH); | |
digitalWrite(LED_GREEN_6, mute_state_6 ? HIGH : LOW); | |
// Send the appropriate serial command for button 2 | |
mySerial.println(mute_state_6 ? "Mic6 set Mute1 true" : "Mic6 set Mute1 false"); | |
} | |
} | |
void switch_interrupt_7() { | |
// Check for debounce | |
unsigned long interrupt_time = millis(); | |
if (interrupt_time - last_interrupt_time_7 > 50) { | |
last_interrupt_time_7 = interrupt_time; | |
// Toggle the mute state for button 7 | |
mute_state_7 = !mute_state_7; | |
// Update the LED state for button 7 | |
digitalWrite(LED_RED_7, mute_state_7 ? LOW : HIGH); | |
digitalWrite(LED_GREEN_7, mute_state_7 ? HIGH : LOW); | |
// Send the appropriate serial command for button 2 | |
mySerial.println(mute_state_7 ? "Mic7 set Mute1 true" : "Mic7 set Mute1 false"); | |
} | |
} | |
void switch_interrupt_8() { | |
// Check for debounce | |
unsigned long interrupt_time = millis(); | |
if (interrupt_time - last_interrupt_time_8 > 50) { | |
last_interrupt_time_8 = interrupt_time; | |
// Toggle the mute state for button 8 | |
mute_state_8 = !mute_state_8; | |
// Update the LED state for button 8 | |
digitalWrite(LED_RED_8, mute_state_8 ? LOW : HIGH); | |
digitalWrite(LED_GREEN_8, mute_state_8 ? HIGH : LOW); | |
// Send the appropriate serial command for button 2 | |
mySerial.println(mute_state_8 ? "Mic8 set Mute1 true" : "Mic8 set Mute1 false"); | |
} | |
} | |
void switch_interrupt_9() { | |
// Check for debounce | |
unsigned long interrupt_time = millis(); | |
if (interrupt_time - last_interrupt_time_9 > 50) { | |
last_interrupt_time_9 = interrupt_time; | |
// Toggle the mute state for button 9 | |
mute_state_9 = !mute_state_9; | |
// Update the LED state for button 9 | |
digitalWrite(LED_RED_9, mute_state_9 ? LOW : HIGH); | |
digitalWrite(LED_GREEN_9, mute_state_9 ? HIGH : LOW); | |
// Send the appropriate serial command for button 2 | |
mySerial.println(mute_state_9 ? "Mic9 set Mute1 true" : "Mic9 set Mute1 false"); | |
} | |
} | |
void switch_interrupt_10() { | |
// Check for debounce | |
unsigned long interrupt_time = millis(); | |
if (interrupt_time - last_interrupt_time_10 > 50) { | |
last_interrupt_time_10 = interrupt_time; | |
// Toggle the mute state for button 10 | |
mute_state_10 = !mute_state_10; | |
// Update the LED state for button 10 | |
digitalWrite(LED_RED_10, mute_state_10 ? LOW : HIGH); | |
digitalWrite(LED_GREEN_10, mute_state_10 ? HIGH : LOW); | |
// Send the appropriate serial command for button 2 | |
mySerial.println(mute_state_10 ? "Mic10 set Mute1 true" : "Mic10 set Mute1 false"); | |
} | |
} | |
void switch_interrupt_11() { | |
// Check for debounce | |
unsigned long interrupt_time = millis(); | |
if (interrupt_time - last_interrupt_time_11 > 50) { | |
last_interrupt_time_11 = interrupt_time; | |
// Toggle the mute state for button 11 | |
mute_state_11 = !mute_state_11; | |
// Update the LED state for button 11 | |
digitalWrite(LED_RED_11, mute_state_11 ? LOW : HIGH); | |
digitalWrite(LED_GREEN_11, mute_state_11 ? HIGH : LOW); | |
// Send the appropriate serial command for button 2 | |
mySerial.println(mute_state_11 ? "Mic11 set Mute1 true" : "Mic11 set Mute1 false"); | |
} | |
} | |
void switch_interrupt_12() { | |
// Check for debounce | |
unsigned long interrupt_time = millis(); | |
if (interrupt_time - last_interrupt_time_12 > 50) { | |
last_interrupt_time_12 = interrupt_time; | |
// Toggle the mute state for button 12 | |
mute_state_12 = !mute_state_12; | |
// Update the LED state for button 12 | |
digitalWrite(LED_RED_12, mute_state_12 ? LOW : HIGH); | |
digitalWrite(LED_GREEN_12, mute_state_12 ? HIGH : LOW); | |
// Send the appropriate serial command for button 2 | |
mySerial.println(mute_state_12 ? "Mic12 set Mute1 true" : "Mic12 set Mute1 false"); | |
} | |
} | |
void switch_interrupt_13() { | |
// Check for debounce | |
unsigned long interrupt_time = millis(); | |
if (interrupt_time - last_interrupt_time_13 > 50) { | |
last_interrupt_time_13 = interrupt_time; | |
// Toggle the mute state for button 13 | |
mute_state_13 = !mute_state_13; | |
// Update the LED state for button 13 | |
digitalWrite(LED_RED_13, mute_state_13 ? LOW : HIGH); | |
digitalWrite(LED_GREEN_13, mute_state_13 ? HIGH : LOW); | |
// Send the appropriate serial command for button 13 | |
mySerial.println(mute_state_13 ? "Mic13 set Mute1 true" : "Mic13 set Mute1 false"); | |
} | |
} | |
void switch_interrupt_14() { | |
// Check for debounce | |
unsigned long interrupt_time = millis(); | |
if (interrupt_time - last_interrupt_time_14 > 50) { | |
last_interrupt_time_14 = interrupt_time; | |
// Toggle the mute state for button 14 | |
mute_state_14 = !mute_state_14; | |
// Update the LED state for button 14 | |
digitalWrite(LED_RED_14, mute_state_14 ? LOW : HIGH); | |
digitalWrite(LED_GREEN_14, mute_state_14 ? HIGH : LOW); | |
// Send the appropriate serial command for button 14 | |
mySerial.println(mute_state_14 ? "Mic14 set Mute1 true" : "Mic14 set Mute1 false"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment