#define KSerial Serial2
#define TestSerial Serial1
#define K_Baud 10400
#define K_RX GPIO_NUM_16
#define K_TX GPIO_NUM_17
#define K_RX_Empty GPIO_NUM_7
bool K_Active = false;
uint8_t buttonPin = 19;
uint8_t button2Pin = 20;
bool SerialEcho = false;
void setup() {
pinMode(buttonPin, INPUT_PULLUP);
pinMode(button2Pin, INPUT_PULLUP);
pinMode(LED_BUILTIN, OUTPUT);
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32-S3!");
TestSerial.begin(K_Baud, GPIO_NUM_6, GPIO_NUM_7);
InitKline();
}
void loop() {
delay(10); // this speeds up the simulation
ReadKLine();
ReadTest();
int buttonValue = digitalRead(buttonPin);
if (buttonValue == LOW) {
KlinePrintln("Hallo Welt");
Serial.println("Button pressed");
delay(500);
}
if (digitalRead(button2Pin) == LOW) {
Serial.println("Button2 pressed");
TestSerial.println("Data...");
delay(500);
}
}
void InitKline() {
if(SerialEcho && K_Active)
return;
KSerial.begin(K_Baud, SERIAL_8N1, K_RX, K_TX, false);
K_Active = true;
}
void KlineStopReceiving() {
if(SerialEcho)
return;
KSerial.begin(K_Baud, SERIAL_8N1, K_RX_Empty, K_TX, false);
}
void KlinePrint(const String &text) {
KSerial.print(text);
}
void KlinePrintln(const String &text) {
KlineStopReceiving();
KSerial.println(text);
//KSerial.flush();
InitKline();
}
void ReadKLine() {
if (!K_Active)
return;
if(KSerial.available()){
Serial.print("KLine: ");
while (KSerial.available()) {
char c = KSerial.read();
Serial.print(c);
}
}
}
void ReadTest() {
if(TestSerial.available()){
Serial.print("Test: ");
while (TestSerial.available()) {
char c = TestSerial.read();
Serial.write(c);
}
//Serial.println();
}
}