Skip to content

Instantly share code, notes, and snippets.

@CountParadox
Created February 24, 2023 05:02
Show Gist options
  • Save CountParadox/fe358f773fa09249bb8e9d2299dd7a0b to your computer and use it in GitHub Desktop.
Save CountParadox/fe358f773fa09249bb8e9d2299dd7a0b to your computer and use it in GitHub Desktop.
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 1); // RX, TX
const int LED1_RED = 20;
const int LED1_GREEN = 21;
const int SWITCH_1 = 16;
const int LED2_RED = 7;
const int LED2_GREEN = 8;
const int SWITCH_2 = 9;
bool state1 = false;
bool state2 = false;
volatile bool switch1_state = false;
volatile bool switch2_state = false;
unsigned long last_interrupt_time1 = 0;
unsigned long last_interrupt_time2 = 0;
void switch1_ISR() {
if (millis() - last_interrupt_time1 > 50) {
switch1_state = !switch1_state;
last_interrupt_time1 = millis();
}
}
void switch2_ISR() {
if (millis() - last_interrupt_time2 > 50) {
switch2_state = !switch2_state;
last_interrupt_time2 = millis();
}
}
void setup() {
pinMode(LED1_RED, OUTPUT);
pinMode(LED1_GREEN, OUTPUT);
pinMode(SWITCH_1, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(SWITCH_1), switch1_ISR, CHANGE);
pinMode(LED2_RED, OUTPUT);
pinMode(LED2_GREEN, OUTPUT);
pinMode(SWITCH_2, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(SWITCH_2), switch2_ISR, CHANGE);
digitalWrite(LED1_RED, HIGH);
digitalWrite(LED1_GREEN, HIGH);
digitalWrite(LED2_RED, HIGH);
digitalWrite(LED2_GREEN, HIGH);
mySerial.begin(9600);
}
void loop() {
if (switch1_state != state1) {
state1 = switch1_state;
if (state1) {
digitalWrite(LED1_RED, LOW);
digitalWrite(LED1_GREEN, HIGH);
mySerial.println("MIC1 set mute 1 true");
} else {
digitalWrite(LED1_RED, HIGH);
digitalWrite(LED1_GREEN, LOW);
mySerial.println("MIC1 set mute 1 false");
}
}
if (switch2_state != state2) {
state2 = switch2_state;
if (state2) {
digitalWrite(LED2_RED, LOW);
digitalWrite(LED2_GREEN, HIGH);
mySerial.println("MIC2 set mute 1 false");
} else {
digitalWrite(LED2_RED, HIGH);
digitalWrite(LED2_GREEN, LOW);
mySerial.println("MIC2 set mute 1 true");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment