From 6727eddf22fcb31434b4f216d121ba79c533507d Mon Sep 17 00:00:00 2001 From: Ghost <31184695+GHOSCHT@users.noreply.github.com> Date: Sat, 8 Aug 2020 20:09:14 +0200 Subject: [PATCH] Renaming --- Arduino/ArduinoControl.ino | 65 ++++++++++++++++++++++++++++++++ Arduino/ArduinoRelayControl.ino | 66 --------------------------------- 2 files changed, 65 insertions(+), 66 deletions(-) create mode 100644 Arduino/ArduinoControl.ino delete mode 100644 Arduino/ArduinoRelayControl.ino diff --git a/Arduino/ArduinoControl.ino b/Arduino/ArduinoControl.ino new file mode 100644 index 0000000..7fc160b --- /dev/null +++ b/Arduino/ArduinoControl.ino @@ -0,0 +1,65 @@ +#include + +const int bjtCount = 4; + +const int bjtPin[bjtCount] ={ 2, 3, 5, 6 }; +const int btnPin[bjtCount] ={ 7, 8, 9, 10 }; +byte bjtState[bjtCount] ={ HIGH, HIGH, HIGH, HIGH }; //high -> bjt "open" + +byte btnState[bjtCount]; +byte lastbtnState[bjtCount]; +String receivedData; +String pendingData; + +void setup() +{ + Serial.begin(9600); + Serial.setTimeout(5); + + for (int i = 0; i < bjtCount; i++) + { + pinMode(btnPin[i], INPUT_PULLUP); + pinMode(bjtPin[i], OUTPUT); + bjtState[i] = EEPROM.read(i); + digitalWrite(bjtPin[i], bjtState[i]); + } +} + +void loop() +{ + while (Serial.available()) + { + receivedData = Serial.readString(); //FORMAT: 0123 -> toggles all bjts | 12 -> toggles only bjts with the index 1 and 2 + Serial.flush(); + } + + for (int i = 0; i < bjtCount; i++) + { + btnState[i] = digitalRead(btnPin[i]); + + if ((btnState[i] == LOW && btnState[i] != lastbtnState[i]) || (receivedData.indexOf(String(i)) >= 0)) + { + receivedData.replace(String(i), ""); + bjtState[i] = !bjtState[i]; + } + + if (receivedData == "off") + { + bjtState[i] = LOW; + } + + if (receivedData == "on") + { + bjtState[i] = HIGH; + } + + digitalWrite(bjtPin[i], bjtState[i]); + EEPROM.update(i, bjtState[i]); + lastbtnState[i] = btnState[i]; + pendingData += bjtState[i]; + } + + Serial.println(pendingData); + pendingData = ""; + receivedData = ""; +} \ No newline at end of file diff --git a/Arduino/ArduinoRelayControl.ino b/Arduino/ArduinoRelayControl.ino deleted file mode 100644 index 54d1053..0000000 --- a/Arduino/ArduinoRelayControl.ino +++ /dev/null @@ -1,66 +0,0 @@ -#include - -const int relayCount = 4; - -const int relayPin[relayCount] ={ 2, 3, 5, 6 }; -const int btnPin[relayCount] ={ 7, 8, 9, 10 }; -byte relayState[relayCount] ={ HIGH, HIGH, HIGH, HIGH }; //high -> relay off - -byte buttonState[relayCount]; -byte lastButtonState[relayCount]; - -String receivedCom; -String statusToSend; - -void setup() -{ - Serial.begin(9600); - Serial.setTimeout(5); - - for (int i = 0; i < relayCount; i++) - { - pinMode(btnPin[i], INPUT_PULLUP); - pinMode(relayPin[i], OUTPUT); - relayState[i] = EEPROM.read(i); - digitalWrite(relayPin[i], relayState[i]); - } -} - -void loop() -{ - while (Serial.available()) - { - receivedCom = Serial.readString(); //FORMAT: 0123 -> toggles all relays | 12 -> toggles only relay with the index 1 and 2 - Serial.flush(); - } - - for (int i = 0; i < relayCount; i++) - { - buttonState[i] = digitalRead(btnPin[i]); - - if ((buttonState[i] == LOW && buttonState[i] != lastButtonState[i]) || (receivedCom.indexOf(String(i)) >= 0)) - { - receivedCom.replace(String(i), ""); - relayState[i] = !relayState[i]; - } - - if (receivedCom == "off") - { - relayState[i] = LOW; - } - - if (receivedCom == "on") - { - relayState[i] = HIGH; - } - - digitalWrite(relayPin[i], relayState[i]); - EEPROM.update(i, relayState[i]); - lastButtonState[i] = buttonState[i]; - statusToSend += relayState[i]; - } - - Serial.println(statusToSend); - statusToSend = ""; - receivedCom = ""; -} \ No newline at end of file