enter key


everybody I had a question for you, about how to link the enter key to code


One possible approach to look for the new line and carriage return.

    if (c == '\n') {  //looks for end of data packet marker 
      Serial.read(); //gets rid of following \r

That does not seem to check that the following character is available before discarding it. Also, the actual end-of-line sequence is user selectable in the IDE and may not include \r or \n, but when they're both present the conventional end-of-line sequence is \r\n, not the other way round.

Rather than explicitly discarding the 'other' character in the newline sequence, I'd suggest reading every character, compare it against either \r or \n (depending which you have configured your serial client to send) and ignore whichever of those two you aren't using (if you're treating \r as end-of-line then ignore \n, and vice versa).

thanks i will see if that works

Interesting that the Serial.read(); in the below code does not remove the /n from the serial buffer.

String readString;

void setup() {
  Serial.println("serial delimit test 1.0"); // so I can keep track of what is loaded

void loop() {

  if (Serial.available())  {
    char c = Serial.read();  //gets one byte from serial buffer
    Serial.println(c, DEC);
    if (c == '\r') {  //looks for end of data packet marker 
      Serial.read(); //gets rid of following \n ????
      Serial.println(readString); //prints string to serial port out
      readString=""; //clears variable for new input      
    else {     
      readString += c; //makes the string readString

My friend told me that ox13 was it but he doesn’t now a ton about the arduino code

Carriage-return is 13 decimal, and line-feed is 10 decimal.