// https://wokwi.com/projects/409958651164173313
// Code from https://forum.arduino.cc/t/serial-input-basics-updated/382007#example-1-receiving-single-characters-5
// Other simulations https://forum.arduino.cc/t/wokwi-simulations-for-arduino-built-in-examples/1304754

/*

Example 1 - Receiving single characters
In very many cases all that is needed is to send a 
single character to the Arduino. Between the upper 
and lower case letters and the numeric characters 
there are 62 options. For example you could use 
'F' for forward, 'R' for reverse and 'S' for stop.
  
*/


// Example 1 - Receiving single characters

char receivedChar;
boolean newData = false;

void setup() {
    Serial.begin(9600);
    Serial.println("<Arduino is ready>");
}

void loop() {
    recvOneChar();
    showNewData();
}

void recvOneChar() {
    if (Serial.available() > 0) {
        receivedChar = Serial.read();
        newData = true;
    }
}

void showNewData() {
    if (newData == true) {
        Serial.print("This just in ... ");
        Serial.println(receivedChar);
        newData = false;
    }
}