#include <SoftwareSerial.h>
SoftwareSerial BTserial(2, 3); // Eingang am Ard. | Ausgang am Ard.

int ledICH = 5;
int ledDU = 6;
int taster = 7;

String msg = "";
unsigned long t;
int state = 0;

void setup() {
  BTserial.begin(9600);
  pinMode(ledICH, OUTPUT);
  pinMode(ledDU, OUTPUT);
  pinMode(taster, INPUT);
  
  digitalWrite(ledICH, LOW);
  digitalWrite(ledDU, LOW);
}

void loop() {
  if (BTserial.available()) {
    char c = BTserial.read();
    if (c != ';') {
      msg = msg + c;
    } else {
      if (msg == "ON") {
        digitalWrite(ledICH, HIGH);
        BTserial.write("OK;");
      } else if (msg == "OFF") {
        digitalWrite(ledICH, LOW);
        BTserial.write("OK;");
      } else if (msg == "OK") {
        digitalWrite(ledDU, state);
      }
      msg = "";
    }
  }

  if (digitalRead(taster) == LOW && t < millis()) {
    t = millis() + 500;
    if (state == 0) {
      state = 1;
      BTserial.write("ON;");
    } else {
      state = 0;
      BTserial.write("OFF;");
    }
  }
}