Led through ethernet

Hello, I already asked a similar question, but I still don’t know the answer. In my code I have 2 lines that I don’t understand because of the numbers after the String parts. I don’t get what would happen if I took the numbers away or changed them. Here are the two lines :

String readString = String(30);
String state = String(3);

And here is my entire code :

#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // MAC
IPAddress ip(x); // IP url

EthernetServer server(x); // Lancement de la librairie Ethernet et de l'ip:port

int LED8 = 8; // LED sur la pin 8
String readString = String(30); // 
String state = String(3); // 

void setup() {
  
  Ethernet.begin(mac, ip); // Lancement de la connexion Ethernet
  server.begin(); // Lancement du serveur
  
  pinMode(LED8,OUTPUT); // LED 8 en sortie
  
  digitalWrite(LED8,LOW); // La LED est éteinte au début
  state= "&eacute;teinte"; // L'état de la LED affichée sur la page internet au début
  
}

void loop() {                 // La boucle
  EthernetClient client = server.available();  // En attente de requêtes
  if (client) {
    boolean currentLineIsBlank = true; // Requête HTTP
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        
        if (readString.length() < 30) { 
          readString.concat(c); // Combinaison des strings
        }
        
        if (c == '\n' && currentLineIsBlank) { // Finalisation de la requête HTTP
          
          
          int LED = readString.indexOf("LED="); // Savoir si allumer ou éteindre a été pressé
          
          if(readString.substring(LED,LED+5) == "LED=T") {  // Si "allumer" est pressé,
            digitalWrite(LED8,HIGH);                        // allumer la LED
            state = "allum&eacute;e";                       // Etat
          }
          
          else if (readString.substring(LED,LED+5) == "LED=F") {   // Si "éteindre" est pressé,
            digitalWrite(LED8,LOW);                                // éteindre la LED
            state = "&eacute;teinte";                              // Etat
          }
          
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println();
          client.println("<html>");
          client.println("<head>");
          client.println("<title>LED par Ethernet</title>"); //Titre (onglet)
          client.println("</head>");
          client.println("<body width=100% height=100%>");
          client.println("<center>");
          client.println("<h1>LED par Ethernet</h1>"); // Titre
          client.print("

");
          client.print("La LED est ");
          client.print(state);
          client.print("



");
          client.println("<input type=submit value=&Eacute;teindre style=width:200px;height:75px onClick=location.href=\"./?LED=F\">"); // Bouton éteindre
          client.println("<input type=submit value=Allumer style=width:200px;height:75px onClick=location.href=\"./?LED=T\">"); // Bouton allumer
          client.println("</center>");
          client.println("</body>");
          client.println("</html");
       
          break;
        }
        if (c == '\n') {
          currentLineIsBlank = true;
        } 
        else if (c != '\r') {
          currentLineIsBlank = false;
        }
      }
    }
    delay(1); // Le navigateur a le temps de recevoir l'information
    
    readString = "";
    
    client.stop(); // Arrêter la connexion
    
  }
}

It would be nice if someone could tell me what the numbers do in the code. What would change if I changed them. At the beginning I thought the String(3) meant that only 3 characters would show up in the state part, because the states were “on” and “off” but I speak french so I changed them to “éteindre” and “allumer” and they still fully show up. Could someone help me?

Thank you

Cocaix

?

?

Hello, I already asked a similar question, but I still don't know the answer. In my code I have 2 lines that I don't understand because of the numbers after the String parts. I don't get what would happen if I took the numbers away or changed them. Here are the two lines :

You've already been told that that code is crap. Get over it.

The numbers in parentheses are the initial value to assign to the String instance. They make no sense.

They USED to, in an OLD version of the String class, define the amount of space to reserve for storage for the String. They no longer do. Now, they are just plain stupid. Get over it.

Thank you, If I get what you mean, I can simply delete the values in the parantheses because they are no longer usefull but completly unecessary in this version of the String class. I didn't get what you meant in the first place, sorry.

If I get what you mean, I can simply delete the values in the parantheses because they are no longer usefull but completly unecessary in this version of the String class.

As I told you in the other thread, you can get rid of more than the value in the parentheses.

Here's why.

String readString = String(30);

This calls the String constructor to create an instance of the string class, with the initial value "30", at some address with no name. It also calls the String constructor to create an instance of the String class, with the default initial value (an empty string), at some address, with the name readString. Next, it calls the equal operator to copy the value of the unnamed instance to the named instance. Finally, it calls the destructor to get rid of the unnamed instance.

String readString = String();

This does all the same stuff, except the unnamed instance's initial value is an empty string.

String readString(30);

This is the preferred way to create an instance of the String class with an initial value. The int argument constructor is called, and has an initial value to assign to the string. No need to create an unnamed instance, to copy its value, or to destruct the instance.

However, since that assigns a useless value to the instance, you should use the no argument constructor, instead:

String readString;

Is there a way of flipping the sequence to:
Once your hand gets closer to the senser the light slowly illuminates on and
once the hand backs off the light slowly turns off?