Simplify
//Global Variables
const int pwron = 12; // On Relay declaration
const int pwroff = 13; // Off relay declaration
bool projectorOn = false;
//----------------------------------------------------------------
void setup() {
Serial.begin(9600); // Declaring and Setting the serial Baud rate
pinMode(pwron, INPUT_PULLUP); // Setting the on relay as an input
pinMode(pwroff, INPUT_PULLUP); // Setting the off relay as an input
}
//----------------------------------------------------------------
void loop() {
if (digitalRead(pwron) == LOW && projectorOn == false) {
ProjectorOnCommand(); // Turn Projector on
projectorOn = true;
}
if (digitalRead(pwroff) == LOW && projectorOn == true) {
ProjectorOffCommand(); // Turn Projector off
projectorOn = false;
}
}
//----------------------------------------------------------------
void ProjectorOnCommand() {
Serial.println("~0000 1");
delay(1000);
}
//----------------------------------------------------------------
void ProjectorOffCommand() {
Serial.println("~0000 0");
delay(1000);
}