#include <LiquidCrystal_I2C.h>
#include <HardwareSerial.h>
/*
Wokwi Custom UART Chip example
The chip implements a simple ROT13 letter substitution cipher:
https://en.wikipedia.org/wiki/ROT13
See https://link.wokwi.com/custom-chips-alpha for more info about custom chips
*/
/*
void setup() {
Serial.begin(9600);
Serial.println("ABC123");
}
void loop(){
if (Serial.available()) {
Serial.print((char)Serial.read());
}
delay(100);
}
*/
#define TIMEOUT 5000
unsigned long update = millis();
void readStream(HardwareSerial port, String outString, byte read);
enum : int {WRITE, READ};
void setup() {
Serial.begin(9600);
//Serial.println("Connection ready for UART chip:");
Serial2.begin(9600); // Serial1 is connected to the custom chip
//Serial2.print("A");
delay(2000);
readStream(Serial2, "A", WRITE);
//while (Serial2.available()) Serial.print(Serial2.read());
//readStream(Serial2, "", READ);
}
void readStream(HardwareSerial port, String outString="", byte read=0) {
String inString = "";
if (!read) {
//if (outString.length() > 0)
port.print("a"); //port.flush();
//Serial.print("WROTE: "), Serial.println(outString);
} else {
update = millis();
while (port.available() == 0 || (millis()-update) < TIMEOUT) {
if (port.available()) {
while (port.available()) inString += port.read();
Serial.print("READ : "), Serial.println(inString);
}
}
}
}
void loop() {
while (Serial2.available()) Serial.print((char)Serial2.read());
//delay(100);
}