// Test sketch to test bug in Tinkercad
// See: https://forum.arduino.cc/t/toint-is-not-working-properly/898028

void setup()
{
    Serial.begin(115200);
    Serial.println( "The sketch has started");   // <--- added for Wokwi
}

void loop()
{
    int gof = 0;
    delay(100);
    String readString = "";
    String Q;

    while (Serial.available())
    {
        delay(4);
        if (Serial.available() > 0)
        {
            char c = Serial.read();
            if (isControl(c))
            {
                break;
            }
            readString += c;
            gof = 1;
        }
    }
    if (gof == 1)
    {
        if (checkStringIsNumerical(readString))
        {
            if ((readString.toInt() >= 0) && (readString.toInt() <= 255))
            {
              int pol = readString.toInt();
              Serial.println((String) "Input is : " + readString);
              Serial.println((String) "Numeric value is : " + pol);
              Serial.println("-------------------");
            }
        }
    }
}

bool checkStringIsNumerical(String myString)
{
    bool Isnum = false;
    uint16_t Numbers = 0;

    for (uint16_t i = 0; i < myString.length(); i++)
    {
        if (myString[i] >= '0' && myString[i] <= '9')
        {
            Numbers++;
        }
    }

    if (Numbers == myString.length())
    {
        Isnum = true;
    }
    else
    {
        Isnum = false;
    }
    return Isnum;
}