Converting a string from the serial to a char array for read-out

Hi, I have a question about converting a string and processing it per character.

Let us say one has a string of about 800 characters which I all need to read out and process. How do I determine the maximum String size, it is a memory thing?

The flow here is that the code takes action after a specific character has been detected in a switch case scenario (code not included as it seems fine) and then needs to move on to the next character after.

Currently I use these sections in my code for the functionality but it seems to be faulty.

while (Serial.available() == 0 && SRreceive == false && Busy == false) {} // nevermind
   if (Serial.available() >= 1) {
   oldmessage = MessageID + ID + ": " Serial.read(); // merge the device ID string and int with the general message
   CharacterCount = 0; // keeps track of the amount of characters in the message, obsolete
   SRsend = true;
   Busy = true;

   // the problem is probably in here:
   StringLength = oldmessage.length()+1; // int to track the length
   CharBuffer [StringLength]; // create a buffer to be filled by the string
   oldmessage.toCharArray(CharBuffer, StringLength); // move the characters into the buffer
   // strcpy(char_array, s.c_str()); // option?
   CurrentChar = 0;
   tempChar = CharBuffer[CurrentChar];

   // there is more code but I left it out for now except for the shifting up part below
    // here I try to shift the position in the array
    if (CurrentChar <= StringLength) {
    CurrentChar++;
    tempChar = CharBuffer[CurrentChar];
    goto ReadChars; // move back up the code for a new read-out of the character
    }

I spent several hours on this but I can not seem to figure it out, thanks.

Always include all code.
The part of the code you didn't post could be the cause of the problem. Think - if you knew what the problem is - you would solve it yourself

Please specify in detail - what is wrong with your code

On a standard Arduino String should be avoided, char arrays work just fine.

really?

I am unfamiliar with these strings and arrays so I am having trouble to see what is going on inside the functions. Let me post all the code. It is just a little program I am working for fun directed at one wire analog communication. I know there are other ways to solve it but it is just a little project.

Yeh I use the goto function but some frown upon it I suppose. Is that what you mean?

I am getting these errors that at some point disappeared after placing a bracket at some position but all errors returned. Nevermind those, I am mostly interested in the character transmission.

Here you go, its works in progress...

Thanks.

// An example  analog communication program using single pin transmission.
// Copyright © Wobbly, 2022.

#include "string.h"
#include "EEPROM.h" // library for the memory
#define EEPROM_SIZE 4096

// The variables and constant variables.
const int PinSR = 12; // The communication pin on a ESP32 but most microcontrollers should work
const int PinLED = 16; // LED output location

int PinSRState = LOW; // check the PinSR state

int ID = 0; // ID number used to identify the device

char BootMemory = ' '; // boot loading input
char CharBuffer = ' '; // create a buffer to save chars from the string but does it work like that?

int StringLength = 0; // log the string length

boolean SRsend = false; // flag a send for the Pin
boolean SRreceive = false; // flag a receive for the Pin
boolean Busy = false; // flag a busy in the program

int CharacterCount = 0; // count the amount of characters in a message
int CurrentChar = 0; // count the chars

String oldmessage = "Hello old world"; // the string used for the old message
String newmessage = "Hello new world"; // the string used for the new message
String MessageID = "You received a message from: "; // added string to identify the sender

char tempChar = ' ';

unsigned long HighTime = 0; // duration for the HIGH status of the pin
unsigned long ProgramMillis = 0; // defines the one minute interval time
unsigned long TotalProgramMillis = 0; // defines the total program running time
unsigned long BootMillis = 0; // defines the millis for the boot, possibly not used inside the program


void setup() {

// analogReadResolution(12); // not used here but relevant when using some sensors

Serial.begin(9600); // set the serial at speed

pinMode(PinSR, INPUT); // changed again inside the program when switching between sending and receiving
pinMode(PinLED, OUTPUT); // set to output to drive a low power indication LED

digitalWrite(PinSR, LOW); // define start position for the communication pin
digitalWrite(PinLED, LOW); // define start position for the LED pin

Serial.println("");
Serial.println("Starting the program...");
Serial.println("");

Serial.println();
Serial.println();
Serial.println("Testing program memory..."); // starting EEPROM functions
if (!EEPROM.begin(EEPROM_SIZE)) {
Serial.println("Could not initiate the memory, too bad");
Serial.println("Restarting...");
Serial.println();
ESP.restart(); // restart funtion
}

newmessage = EEPROM.readString(6);
delay(1000);

Serial.println();
Serial.println("Your last message was: ");
Serial.println(newmessage);
Serial.println();

delay(10);

ID = 0;
ID = EEPROM.readInt(1); // 1 is the address for the ID, increments of 5 are used, a float is 4 Bytes in size

delay(10);

if (ID >= 9999) {
  ID = 0000;
  Serial.println("");
  Serial.println("The device ID number was reset to 0000");
  Serial.println("");
  }

delay(10);

Serial.println("");
Serial.print("The device ID number currently is: ");
Serial.println(ID);
Serial.println("");

BeginInput:

micros() = 0; // reset the counter for microseconds
millis() = 0; // reset the counter for milliseconds

BootMillis = 0;

Serial.println();
Serial.println("Would you like to set a new ID number? If so press 'y' if not press 'n'...");
Serial.println();

  while (Serial.available() == 0) {BootMillis = millis();}
    if (BootMillis >= 60000) {
    BootMillis = 0;
    millis() = 0; // reset the counter for milliseconds
    Serial.println();
    Serial.println("60 seconds timed-out... A new ID number was not set...");
    Serial.println();
    goto escapeSetup;
    }
  
  if (Serial.available() > 0) {
     BootMemory = Serial.read();
     BootMillis = 0;
     millis() = 0; // reset the counter for milliseconds
     
     if (BootMemory == 'y') {
     BootMemory = ' ';
     Serial.println();
     Serial.println("Please input a new four-digit ID number: ");
     
      ReInput:
      while (Serial.available() == 0) {BootMillis = millis();}
      if (BootMillis >= 60000) {
      BootMillis = 0;
      millis() = 0; // reset the counter for milliseconds
      Serial.println();
      Serial.println("60 seconds timed-out... A new ID number was not set...");
      Serial.println();
      goto escapeSetup;
      }

      if (Serial.available() <= 3) {
      Serial.println();
      Serial.println("Please input a four-digit ID number, not any smaller than four digits:");
      BootMillis = 0;
      millis() = 0; // reset the counter for milliseconds
      goto ReInput;
      }
      
      if (Serial.available() == 4) {
      ID = Serial.read();
      EEPROM.writeInt(1, ID);
      EEPROM.commit();
      delay(10);
      Serial.println();
      Serial.print("The new ID number is: ");
      Serial.println(ID);
      Serial.println();
      goto escapeSetup;
      }

      if (Serial.available() >= 5) {
      Serial.println();
      Serial.println("Please put a four-digit ID number, not any larger than four digits:");
      BootMillis = 0;
      millis() = 0; // reset the counter for milliseconds
      goto ReInput;
      }
     }

     if (BootMemory == 'n') {
      BootMemory = ' ';
      Serial.println();
      Serial.println("Proceeding with the old ID number... ");
      Serial.println();
      goto escapeSetup;
      }

     if (BootMemory != 'n' || != 'y') {
      Serial.println();
      Serial.println("Input unknow, please try again...");
      Serial.println();
      BootMemory = ' ';
      goto BeginInput;
      }

 }

     escapeSetup:
      
     Serial.println();
     Serial.println("Exiting setup... ");
     Serial.println();

     Serial.println("");
     Serial.println("Welcome to the Wobbly demonstration communication program!");
     Serial.println("");

     Serial.println("");
     Serial.println("Message length is limited to the maximum length for the String variable, which is 800 characters minus the ID number opening message.");
     Serial.println("");

     Serial.println("");
     Serial.println("Not every character was coded. More characters, word or even complete function recognization can be added through additional code.");
     Serial.println("Use TABS for letter input as seen below. The currently coded characters are:");
     Serial.println("A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, -, ., , ?, -, =, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9");
     Serial.println("");

     BootMemory = ' ';

     BootMillis = 0;
     ProgramMillis = 0;
     TotalProgramMillis = 0;
     
     micros() = 0; // reset the counter for microseconds
     millis() = 0; // reset the counter for milliseconds

     pinMode (PinSR, INPUT);

     SRsend = false; 
     SRreceive = false;

     digitalWrite(PinSR, LOW);
     digitalWrite(PinLED, LOW);
     
     PinSRState = LOW;
     
}

void loop() {

PinSRState = digitalRead(PinSR);

while (PinSRState == LOW && Busy == false && SRsend == false && SRreceive == false) {ProgramMillis = millis();}

if (ProgramMillis >= 60000 && Busy == false && PinSRState == LOW && SRsend == false && SRreceive == false) {
    Serial.println();
    Serial.println("No message activity for 60 seconds...");
    Serial.print("The program has been running for ");
    Serial.print(TotalProgramMillis/1000);
    Serial.print(" seconds");
    Serial.println();
    millis() = 0;
    TotalProgramMillis = TotalProgramMillis + ProgramMillis;
    ProgramMillis = 0;
    }

while (Serial.available() == 0 && SRreceive == false && Busy == false) {}
   if (Serial.available() >= 1) {
   oldmessage = MessageID + ID + ": " Serial.read();
   CharacterCount = 0;
   SRsend = true;
   Busy = true;

   StringLength = oldmessage.length()+1;
   CharBuffer [StringLength];
   oldmessage.toCharArray(CharBuffer, StringLength);
   // strcpy(char_array, s.c_str());
   CurrentChar = 0;
   tempChar = CharBuffer[CurrentChar];

   pinMode (PinSR, OUTPUT);
   
   delay(10);
   
   Serial.println();
   Serial.println("Sending message... Please wait...");
   Serial.println();

   digitalWrite(PinSR, HIGH); // send the opening signal
   delayMicroseconds(3460);
   digitalWrite(PinSR, LOW);
   delayMicroseconds(100);

   ReadChars:
   
   switch (tempChar) {
    
    case ('A'):
      digitalWrite(PinSR,  HIGH);
      delayMicroseconds(100); // set these values to change the speed of the connection, decreasing the signal width will improve connection speed but limits here depend on the microprocessor used
      digitalWrite(PinSR,  LOW);
      delayMicroseconds(100); // the LOW time is not counted or logged and to increase speed it is set at 100 microseconds for all characters, lower it to increase speed but risk lower stability or failure
      break;
    case ('B'):
      digitalWrite(PinSR,  HIGH);
      delayMicroseconds(180); // a relatively wide interval of 80 microseconds between characters was chosen to improve transmission stability, lower these will increase space for programming characters
      digitalWrite(PinSR,  LOW);
      delayMicroseconds(100);
      break;
    case ('C'):
      digitalWrite(PinSR,  HIGH);
      delayMicroseconds(260);
      digitalWrite(PinSR,  LOW);
      delayMicroseconds(100);
      break;
    case ('D'):
      digitalWrite(PinSR,  HIGH);
      delayMicroseconds(340);
      digitalWrite(PinSR,  LOW);
      delayMicroseconds(100);
      break;
    case ('E'):
      digitalWrite(PinSR,  HIGH);
      delayMicroseconds(420);
      digitalWrite(PinSR,  LOW);
      delayMicroseconds(100);
      break;
    case ('F'):
      digitalWrite(PinSR,  HIGH);
      delayMicroseconds(500);
      digitalWrite(PinSR,  LOW);
      delayMicroseconds(100);
      break;
    case ('G'):
      digitalWrite(PinSR,  HIGH);
      delayMicroseconds(580);
      digitalWrite(PinSR,  LOW);
      delayMicroseconds(100);
      break;
    case ('H'):
      digitalWrite(PinSR,  HIGH);
      delayMicroseconds(660);
      digitalWrite(PinSR,  LOW);
      delayMicroseconds(100);
      break;
    case ('I'):
      digitalWrite(PinSR,  HIGH);
      delayMicroseconds(740);
      digitalWrite(PinSR,  LOW);
      delayMicroseconds(100);
      break;
    case ('J'):
      digitalWrite(PinSR,  HIGH);
      delayMicroseconds(820);
      digitalWrite(PinSR,  LOW);
      delayMicroseconds(100);
      break;
    case ('K'):
      digitalWrite(PinSR,  HIGH);
      delayMicroseconds(900);
      digitalWrite(PinSR,  LOW);
      delayMicroseconds(100);
      break;
    case ('L'):
      digitalWrite(PinSR,  HIGH);
      delayMicroseconds(980);
      digitalWrite(PinSR,  LOW);
      delayMicroseconds(100);
      break;
    case ('M'):
      digitalWrite(PinSR,  HIGH);
      delayMicroseconds(1060);
      digitalWrite(PinSR,  LOW);
      delayMicroseconds(100);
      break;
    case ('N'):
      digitalWrite(PinSR,  HIGH);
      delayMicroseconds(1140);
      digitalWrite(PinSR,  LOW);
      delayMicroseconds(100);
      break;
    case ('O'):
      digitalWrite(PinSR,  HIGH);
      delayMicroseconds(1220);
      digitalWrite(PinSR,  LOW);
      delayMicroseconds(100);
      break;
    case ('P'):
      digitalWrite(PinSR,  HIGH);
      delayMicroseconds(1300);
      digitalWrite(PinSR,  LOW);
      delayMicroseconds(100);
      break;
    case ('Q'):
      digitalWrite(PinSR,  HIGH);
      delayMicroseconds(1380);
      digitalWrite(PinSR,  LOW);
      delayMicroseconds(100);
      break;
    case ('R'):
      digitalWrite(PinSR,  HIGH);
      delayMicroseconds(1460);
      digitalWrite(PinSR,  LOW);
      delayMicroseconds(100);
      break;
    case ('S'):
      digitalWrite(PinSR,  HIGH);
      delayMicroseconds(1540);
      digitalWrite(PinSR,  LOW);
      delayMicroseconds(100);
      break;
    case ('T'):
      digitalWrite(PinSR,  HIGH);
      delayMicroseconds(1620);
      digitalWrite(PinSR,  LOW);
      delayMicroseconds(100);
      break;
    case ('U'):
      digitalWrite(PinSR,  HIGH);
      delayMicroseconds(1700);
      digitalWrite(PinSR,  LOW);
      delayMicroseconds(100);
      break;
    case ('V'):
      digitalWrite(PinSR,  HIGH);
      delayMicroseconds(1780);
      digitalWrite(PinSR,  LOW);
      delayMicroseconds(100);
      break;
    case ('W'):
      digitalWrite(PinSR,  HIGH);
      delayMicroseconds(1860);
      digitalWrite(PinSR,  LOW);
      delayMicroseconds(100);
      break;
    case ('X'):
      digitalWrite(PinSR,  HIGH);
      delayMicroseconds(1940);
      digitalWrite(PinSR,  LOW);
      delayMicroseconds(100);
      break;
    case ('Y'):
      digitalWrite(PinSR,  HIGH);
      delayMicroseconds(2020);
      digitalWrite(PinSR,  LOW);
      delayMicroseconds(100);
      break;
    case ('Z'):
      digitalWrite(PinSR,  HIGH);
      delayMicroseconds(2100);
      digitalWrite(PinSR,  LOW);
      delayMicroseconds(100);
      break;
    case ('-'):
      digitalWrite(PinSR,  HIGH);
      delayMicroseconds(2180);
      digitalWrite(PinSR,  LOW);
      delayMicroseconds(100);
      break;
    case ('.'):
      digitalWrite(PinSR,  HIGH);
      delayMicroseconds(2260);
      digitalWrite(PinSR,  LOW);
      delayMicroseconds(100);
      break;
    case (' '):
      digitalWrite(PinSR,  HIGH);
      delayMicroseconds(2340);
      digitalWrite(PinSR,  LOW);
      delayMicroseconds(100);
      break;
    case ('?'):
      digitalWrite(PinSR,  HIGH);
      delayMicroseconds(2420);
      digitalWrite(PinSR,  LOW);
      delayMicroseconds(100);
      break;
    case ('='):
      digitalWrite(PinSR,  HIGH);
      delayMicroseconds(2500);
      digitalWrite(PinSR,  LOW);
      delayMicroseconds(100);
      break;
    case ('0'):
      digitalWrite(PinSR,  HIGH);
      delayMicroseconds(2580);
      digitalWrite(PinSR,  LOW);
      delayMicroseconds(100);
      break;
    case ('1'):
      digitalWrite(PinSR,  HIGH);
      delayMicroseconds(2660);
      digitalWrite(PinSR,  LOW);
      delayMicroseconds(100);
      break;
    case ('2'):
      digitalWrite(PinSR,  HIGH);
      delayMicroseconds(2740);
      digitalWrite(PinSR,  LOW);
      delayMicroseconds(100);
      break;
    case ('3'):
      digitalWrite(PinSR,  HIGH);
      delayMicroseconds(2820);
      digitalWrite(PinSR,  LOW);
      delayMicroseconds(100);
      break;
    case ('4'):
      digitalWrite(PinSR,  HIGH);
      delayMicroseconds(2900);
      digitalWrite(PinSR,  LOW);
      delayMicroseconds(100);
      break;
    case ('5'):
      digitalWrite(PinSR,  HIGH);
      delayMicroseconds(2980);
      digitalWrite(PinSR,  LOW);
      delayMicroseconds(100);
      break;
    case ('6'):
      digitalWrite(PinSR,  HIGH);
      delayMicroseconds(3060);
      digitalWrite(PinSR,  LOW);
      delayMicroseconds(100);
      break;
    case ('7'):
      digitalWrite(PinSR,  HIGH);
      delayMicroseconds(3140);
      digitalWrite(PinSR,  LOW);
      delayMicroseconds(100);
      break;
    case ('8'):
      digitalWrite(PinSR,  HIGH);
      delayMicroseconds(3220);
      digitalWrite(PinSR,  LOW);
      delayMicroseconds(100);
      break;
    case ('9'):
      digitalWrite(PinSR,  HIGH);
      delayMicroseconds(3300);
      digitalWrite(PinSR,  LOW);
      delayMicroseconds(100);
      break;

    digitalWrite(PinSR,  HIGH); // send the character signal
    delayMicroseconds(3380);
    digitalWrite(PinSR,  LOW);
    delayMicroseconds(100);

    CharacterCount = CharacterCount + 1; // count the characters
      
    default:
      // if nothing else matches, do the default
      // default is optional

    if (CurrentChar <= StringLength) {
    CurrentChar++;
    tempChar = CharBuffer[CurrentChar];
    goto ReadChars;
    }

    if (CurrentChar >> StringLength) {
    digitalWrite(PinSR,  HIGH);
    delayMicroseconds(3460);
    digitalWrite(PinSR,  LOW);
    delayMicroseconds(100);
    CharacterCount = 0;
    pinMode(PinSR, INPUT);
    digitalWrite(PinSR,  LOW);
    SRsend = false;
    Busy = false;
    oldmessage = "";
    CurrentChar = 0;
    tempChar = ' ';
    Serial.println();
    Serial.println("The message was sent...");
    Serial.println();
    micros() = 0;
    }
    
    break;
   }
   
  }

if (PinSRState == HIGH && SRsend == false) {
    micros() = 0;
    HighTime = 0; // reset the HIGH time
    Busy = true;
    digitalWrite(PinLED, HIGH);
    }

if (PinSRState == LOW && Busy == true && SRsend == false) {
    digitalWrite(PinLED, LOW);
    HighTime = micros(); // start counting the HIGH time

switch (HighTime) {
    
    case (<= 59): {}
      tempChar = ' ';
      break;
    case (>= 60 && <= 140):
      tempChar = 'A';
      break;
    case (>= 141 && <= 220):
      tempChar = 'B';
      break;
    case (>= 221 && <= 300):
      tempChar = 'C';
      break;
    case (>= 301 && <= 380):
      tempChar = 'D';
      break;
    case (>= 381 && <= 460):
      tempChar = 'E';
      break;
    case (>= 461 && <= 540):
      tempChar = 'F';
      break;
    case (>= 541 && <= 620):
      tempChar = 'G';
      break;
    case (>= 621 && <= 700):
      tempChar = 'H';
      break;
    case (>= 701 && <= 780):
      tempChar = 'I';
      break;
    case (>= 781 && <= 860):
      tempChar = 'J';
      break;
    case (>= 861 && <= 940):
      tempChar = 'K';
      break;
    case (>= 941 && <= 1020):
      tempChar = 'L';
      break;
    case (>= 1021 && <= 1100):
      tempChar = 'M';
      break;
    case (>= 1101 && <= 1180):
      tempChar = 'N';
      break;
    case (>= 1181 && <= 1260):
      tempChar = 'O';
      break;
    case (>= 1261 && <= 1340): // 1300
      tempChar = 'P';
      break;
    case (>= 1341 && <= 1420):
      tempChar = 'Q';
      break;
    case (>= 1421 && <= 1500):
      tempChar = 'R';
      break;
    case (>= 1501 && <= 1580):
      tempChar = 'S';
      break;
    case (>= 1581 && <= 1660):
      tempChar = 'T';
      break;
    case (>= 1661 && <= 1740): // 1700
      tempChar = 'U';
      break;
    case (>= 1741 && <= 1820):
      tempChar = 'V';
      break;
    case (>= 1821 && <= 1900):
      tempChar = 'W';
      break;
    case (>= 1901 && <= 1980):
      tempChar = 'X';
      break;
    case (>= 1981 && <= 2060):
      tempChar = 'Y';
      break;
    case (>= 2061 && <= 2140): // 2100
      tempChar = 'Z';
      break;
    case (>= 2141 && <= 2220):
      tempChar = '-';
      break;
    case (>= 2221 && <= 2300):
      tempChar = '.';
      break;
    case (>= 2301 && <= 2380):
      tempChar = ' ';
      break;
    case (>= 2381 && <= 2460):
      tempChar = '?';
      break;
    case (>= 2461 && <= 2540):
      tempChar = '=';
      break;
    case (>= 2541 && <= 2620):
      tempChar = '0';
      break;
    case (>= 2621 && <= 2700):
      tempChar = '1';
      break;
    case (>= 2701 && <= 2780):
      tempChar = '2';
      break;
    case (>= 2781 && <= 2860):
      tempChar = '3';
      break;
    case (>= 2861 && <= 2940):
      tempChar = '4';
      break;
    case (>= 2941 && <= 3020):
      tempChar = '5';
      break;
    case (>= 3021 && <= 3100):
      tempChar = '6';
      break;
    case (>= 3101 && <= 3180):
      tempChar = '7';
      break;
    case (>= 3181 && <= 3260):
      tempChar = '8';
      break;
    case (>= 3261 && <= 3340): // 3300
      tempChar = '9';
      break;

    default:
      // if nothing else matches, do the default
      // default is optional

    case (>= 3341 && <= 3420 && SRreceive == true): // character end transmission
      oldmessage.concat(tempChar);
      CharacterCount = CharacterCount + 1; // count the characters
      break;

    case (>= 3421 && <= 3500 && SRreceive == false): // message opening signal
      CharacterCount = 0;
      SRreceive = true;
      break;

    case (>= 3421 && <= 3500 && SRreceive == true): // message closing signal
      newmessage = oldmessage;
      Serial.println();
      Serial.println();
      Serial.print("A message was received made from ");
      Serial.print(CharacterCount);
      Serial.println(" characters:");
      Serial.println(newmessage); // and print them all together
      Serial.println();
      EEPROM.writeString(6, newmessage);
      EEPROM.commit();
      oldmessage = "";
      delay(1000);
      Serial.println();
      Serial.println("Waiting to send or receive a new message...");
      Serial.println();
      CharacterCount = 0;
      SRreceive = false;
      Busy = false;
      break;
      
    
    break;
   }
  
 }
}

That function is not in the built-in EEPROM.h so you must be using a third-party EEPROM library. Where did you get it?

Are you running this on an ESP32 or ESP8266? I don't think they have EEPROM so the "EEPROM" you are using must be emulated somehow.

Does this mean 'read characters from EEPROM starting at address 6 until you reach a null character`?

You can't set a function to a value. If you want to start a timer, record the start time:

    static unsigned long startMillis = 0;
    static unsigned long startMicros = 0;

    startMillis = millis();
    startMicro = micros();

When you want to know the elapsed time, subtract the start time from the current time:

    unsigned long elapsedMillis = millis() - startMillis;
    unsigned long elapsedMicros = micros() - startMicros;

Each 'case' must be an integer constant (or, with a compiler extension, a range of integer constants). You should change these to a series of 'if/else'' statements.

Bad Syntax. You mean:
if (BootMemory != 'n' || BootMemory != 'y') {
WARNING: This will ALWAYS be true since if it is == 'n' it will always be != 'y' and vice-verse. It can't "not one or not the other". Did you want "is neither"? That would be:
if (BootMemory != 'n' && BootMemory != 'y') {

Here is your sketch with enough syntax errors removed to compiler without error.

// An example  analog communication program using single pin transmission.
// Copyright © Wobbly, 2022.


#include <EEPROM.h> // library for the memory
#define EEPROM_SIZE 4096

// The variables and constant variables.
const int PinSR = 12; // The communication pin on a ESP32 but most microcontrollers should work
const int PinLED = 16; // LED output location

int PinSRState = LOW; // check the PinSR state

int ID = 0; // ID number used to identify the device

char BootMemory = ' '; // boot loading input
char CharBuffer = ' '; // create a buffer to save chars from the string but does it work like that?

int StringLength = 0; // log the string length

boolean SRsend = false; // flag a send for the Pin
boolean SRreceive = false; // flag a receive for the Pin
boolean Busy = false; // flag a busy in the program

int CharacterCount = 0; // count the amount of characters in a message
int CurrentChar = 0; // count the chars

String oldmessage = "Hello old world"; // the string used for the old message
String newmessage = "Hello new world"; // the string used for the new message
String MessageID = "You received a message from: "; // added string to identify the sender

char tempChar = ' ';

unsigned long HighTime = 0; // duration for the HIGH status of the pin
unsigned long ProgramMillis = 0; // defines the one minute interval time
unsigned long TotalProgramMillis = 0; // defines the total program running time
unsigned long BootMillis = 0; // defines the millis for the boot, possibly not used inside the program

unsigned long startMillis;
unsigned long startMicros;

void setup()
{

  // analogReadResolution(12); // not used here but relevant when using some sensors

  Serial.begin(9600); // set the serial at speed

  pinMode(PinSR, INPUT); // changed again inside the program when switching between sending and receiving
  pinMode(PinLED, OUTPUT); // set to output to drive a low power indication LED

  digitalWrite(PinSR, LOW); // define start position for the communication pin
  digitalWrite(PinLED, LOW); // define start position for the LED pin

  Serial.println("");
  Serial.println("Starting the program...");
  Serial.println("");

  Serial.println();
  Serial.println();
  Serial.println("Testing program memory..."); // starting EEPROM functions
  //  if (!EEPROM.begin(EEPROM_SIZE))
  {
    Serial.println("Could not initiate the memory, too bad");
    Serial.println("Restarting...");
    Serial.println();
    //    ESP.restart(); // restart funtion
  }

  //  newmessage = EEPROM.readString(6);
  delay(1000);

  Serial.println();
  Serial.println("Your last message was: ");
  Serial.println(newmessage);
  Serial.println();

  delay(10);

  ID = 0;
  //  ID = EEPROM.readInt(1); // 1 is the address for the ID, increments of 5 are used, a float is 4 Bytes in size

  delay(10);

  if (ID >= 9999)
  {
    ID = 0000;
    Serial.println("");
    Serial.println("The device ID number was reset to 0000");
    Serial.println("");
  }

  delay(10);

  Serial.println("");
  Serial.print("The device ID number currently is: ");
  Serial.println(ID);
  Serial.println("");

BeginInput:

  startMicros = micros();; // reset the counter for microseconds
  startMillis = millis(); // reset the counter for milliseconds

  BootMillis = 0;

  Serial.println();
  Serial.println("Would you like to set a new ID number? If so press 'y' if not press 'n'...");
  Serial.println();

  while (Serial.available() == 0)
  {
    BootMillis = millis();
  }
  if (BootMillis >= 60000)
  {
    BootMillis = 0;
    startMillis = millis(); // reset the counter for milliseconds
    Serial.println();
    Serial.println("60 seconds timed-out... A new ID number was not set...");
    Serial.println();
    goto escapeSetup;
  }

  if (Serial.available() > 0)
  {
    BootMemory = Serial.read();
    BootMillis = 0;
    startMillis = millis(); // reset the counter for milliseconds

    if (BootMemory == 'y')
    {
      BootMemory = ' ';
      Serial.println();
      Serial.println("Please input a new four-digit ID number: ");

ReInput:
      while (Serial.available() == 0)
      {
        BootMillis = millis();
      }
      if (BootMillis >= 60000)
      {
        BootMillis = 0;
        startMillis = millis(); // reset the counter for milliseconds
        Serial.println();
        Serial.println("60 seconds timed-out... A new ID number was not set...");
        Serial.println();
        goto escapeSetup;
      }

      if (Serial.available() <= 3)
      {
        Serial.println();
        Serial.println("Please input a four-digit ID number, not any smaller than four digits:");
        BootMillis = 0;
        startMillis = millis(); // reset the counter for milliseconds
        goto ReInput;
      }

      if (Serial.available() == 4)
      {
        ID = Serial.read();
        //        EEPROM.writeInt(1, ID);
        //        EEPROM.commit();
        delay(10);
        Serial.println();
        Serial.print("The new ID number is: ");
        Serial.println(ID);
        Serial.println();
        goto escapeSetup;
      }

      if (Serial.available() >= 5)
      {
        Serial.println();
        Serial.println("Please put a four-digit ID number, not any larger than four digits:");
        BootMillis = 0;
        startMillis = millis();
        goto ReInput;
      }
    }

    if (BootMemory == 'n')
    {
      BootMemory = ' ';
      Serial.println();
      Serial.println("Proceeding with the old ID number... ");
      Serial.println();
      goto escapeSetup;
    }

    if (BootMemory != 'n' && BootMemory != 'y')
    {
      Serial.println();
      Serial.println("Input unknow, please try again...");
      Serial.println();
      BootMemory = ' ';
      goto BeginInput;
    }

  }

escapeSetup:

  Serial.println();
  Serial.println("Exiting setup... ");
  Serial.println();

  Serial.println("");
  Serial.println("Welcome to the Wobbly demonstration communication program!");
  Serial.println("");

  Serial.println("");
  Serial.println("Message length is limited to the maximum length for the String variable, which is 800 characters minus the ID number opening message.");
  Serial.println("");

  Serial.println("");
  Serial.println("Not every character was coded. More characters, word or even complete function recognization can be added through additional code.");
  Serial.println("Use TABS for letter input as seen below. The currently coded characters are:");
  Serial.println("A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, -, ., , ?, -, =, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9");
  Serial.println("");

  BootMemory = ' ';

  BootMillis = 0;
  ProgramMillis = 0;
  TotalProgramMillis = 0;

  startMicros = micros();// reset the counter for microseconds
  startMillis = millis(); // reset the counter for milliseconds

  pinMode (PinSR, INPUT);

  SRsend = false;
  SRreceive = false;

  digitalWrite(PinSR, LOW);
  digitalWrite(PinLED, LOW);

  PinSRState = LOW;

}

void loop()
{

  PinSRState = digitalRead(PinSR);

  while (PinSRState == LOW && Busy == false && SRsend == false && SRreceive == false)
  {
    ProgramMillis = millis();
  }

  if (ProgramMillis >= 60000 && Busy == false && PinSRState == LOW && SRsend == false && SRreceive == false)
  {
    Serial.println();
    Serial.println("No message activity for 60 seconds...");
    Serial.print("The program has been running for ");
    Serial.print(TotalProgramMillis / 1000);
    Serial.print(" seconds");
    Serial.println();
    startMillis = millis();
    TotalProgramMillis = TotalProgramMillis + ProgramMillis;
    ProgramMillis = 0;
  }

  while (Serial.available() == 0 && SRreceive == false && Busy == false) {}
  if (Serial.available() >= 1)
  {
    oldmessage = MessageID + ID + ": " + Serial.read();
    CharacterCount = 0;
    SRsend = true;
    Busy = true;

    StringLength = oldmessage.length() + 1;
    char CharBuffer[StringLength];
    oldmessage.toCharArray(CharBuffer, StringLength);
    // strcpy(char_array, s.c_str());
    CurrentChar = 0;
    tempChar = CharBuffer[CurrentChar];

    pinMode (PinSR, OUTPUT);

    delay(10);

    Serial.println();
    Serial.println("Sending message... Please wait...");
    Serial.println();

    digitalWrite(PinSR, HIGH); // send the opening signal
    delayMicroseconds(3460);
    digitalWrite(PinSR, LOW);
    delayMicroseconds(100);

ReadChars:

    switch (tempChar)
    {

      case ('A'):
        digitalWrite(PinSR,  HIGH);
        delayMicroseconds(100); // set these values to change the speed of the connection, decreasing the signal width will improve connection speed but limits here depend on the microprocessor used
        digitalWrite(PinSR,  LOW);
        delayMicroseconds(100); // the LOW time is not counted or logged and to increase speed it is set at 100 microseconds for all characters, lower it to increase speed but risk lower stability or failure
        break;
      case ('B'):
        digitalWrite(PinSR,  HIGH);
        delayMicroseconds(180); // a relatively wide interval of 80 microseconds between characters was chosen to improve transmission stability, lower these will increase space for programming characters
        digitalWrite(PinSR,  LOW);
        delayMicroseconds(100);
        break;
      case ('C'):
        digitalWrite(PinSR,  HIGH);
        delayMicroseconds(260);
        digitalWrite(PinSR,  LOW);
        delayMicroseconds(100);
        break;
      case ('D'):
        digitalWrite(PinSR,  HIGH);
        delayMicroseconds(340);
        digitalWrite(PinSR,  LOW);
        delayMicroseconds(100);
        break;
      case ('E'):
        digitalWrite(PinSR,  HIGH);
        delayMicroseconds(420);
        digitalWrite(PinSR,  LOW);
        delayMicroseconds(100);
        break;
      case ('F'):
        digitalWrite(PinSR,  HIGH);
        delayMicroseconds(500);
        digitalWrite(PinSR,  LOW);
        delayMicroseconds(100);
        break;
      case ('G'):
        digitalWrite(PinSR,  HIGH);
        delayMicroseconds(580);
        digitalWrite(PinSR,  LOW);
        delayMicroseconds(100);
        break;
      case ('H'):
        digitalWrite(PinSR,  HIGH);
        delayMicroseconds(660);
        digitalWrite(PinSR,  LOW);
        delayMicroseconds(100);
        break;
      case ('I'):
        digitalWrite(PinSR,  HIGH);
        delayMicroseconds(740);
        digitalWrite(PinSR,  LOW);
        delayMicroseconds(100);
        break;
      case ('J'):
        digitalWrite(PinSR,  HIGH);
        delayMicroseconds(820);
        digitalWrite(PinSR,  LOW);
        delayMicroseconds(100);
        break;
      case ('K'):
        digitalWrite(PinSR,  HIGH);
        delayMicroseconds(900);
        digitalWrite(PinSR,  LOW);
        delayMicroseconds(100);
        break;
      case ('L'):
        digitalWrite(PinSR,  HIGH);
        delayMicroseconds(980);
        digitalWrite(PinSR,  LOW);
        delayMicroseconds(100);
        break;
      case ('M'):
        digitalWrite(PinSR,  HIGH);
        delayMicroseconds(1060);
        digitalWrite(PinSR,  LOW);
        delayMicroseconds(100);
        break;
      case ('N'):
        digitalWrite(PinSR,  HIGH);
        delayMicroseconds(1140);
        digitalWrite(PinSR,  LOW);
        delayMicroseconds(100);
        break;
      case ('O'):
        digitalWrite(PinSR,  HIGH);
        delayMicroseconds(1220);
        digitalWrite(PinSR,  LOW);
        delayMicroseconds(100);
        break;
      case ('P'):
        digitalWrite(PinSR,  HIGH);
        delayMicroseconds(1300);
        digitalWrite(PinSR,  LOW);
        delayMicroseconds(100);
        break;
      case ('Q'):
        digitalWrite(PinSR,  HIGH);
        delayMicroseconds(1380);
        digitalWrite(PinSR,  LOW);
        delayMicroseconds(100);
        break;
      case ('R'):
        digitalWrite(PinSR,  HIGH);
        delayMicroseconds(1460);
        digitalWrite(PinSR,  LOW);
        delayMicroseconds(100);
        break;
      case ('S'):
        digitalWrite(PinSR,  HIGH);
        delayMicroseconds(1540);
        digitalWrite(PinSR,  LOW);
        delayMicroseconds(100);
        break;
      case ('T'):
        digitalWrite(PinSR,  HIGH);
        delayMicroseconds(1620);
        digitalWrite(PinSR,  LOW);
        delayMicroseconds(100);
        break;
      case ('U'):
        digitalWrite(PinSR,  HIGH);
        delayMicroseconds(1700);
        digitalWrite(PinSR,  LOW);
        delayMicroseconds(100);
        break;
      case ('V'):
        digitalWrite(PinSR,  HIGH);
        delayMicroseconds(1780);
        digitalWrite(PinSR,  LOW);
        delayMicroseconds(100);
        break;
      case ('W'):
        digitalWrite(PinSR,  HIGH);
        delayMicroseconds(1860);
        digitalWrite(PinSR,  LOW);
        delayMicroseconds(100);
        break;
      case ('X'):
        digitalWrite(PinSR,  HIGH);
        delayMicroseconds(1940);
        digitalWrite(PinSR,  LOW);
        delayMicroseconds(100);
        break;
      case ('Y'):
        digitalWrite(PinSR,  HIGH);
        delayMicroseconds(2020);
        digitalWrite(PinSR,  LOW);
        delayMicroseconds(100);
        break;
      case ('Z'):
        digitalWrite(PinSR,  HIGH);
        delayMicroseconds(2100);
        digitalWrite(PinSR,  LOW);
        delayMicroseconds(100);
        break;
      case ('-'):
        digitalWrite(PinSR,  HIGH);
        delayMicroseconds(2180);
        digitalWrite(PinSR,  LOW);
        delayMicroseconds(100);
        break;
      case ('.'):
        digitalWrite(PinSR,  HIGH);
        delayMicroseconds(2260);
        digitalWrite(PinSR,  LOW);
        delayMicroseconds(100);
        break;
      case (' '):
        digitalWrite(PinSR,  HIGH);
        delayMicroseconds(2340);
        digitalWrite(PinSR,  LOW);
        delayMicroseconds(100);
        break;
      case ('?'):
        digitalWrite(PinSR,  HIGH);
        delayMicroseconds(2420);
        digitalWrite(PinSR,  LOW);
        delayMicroseconds(100);
        break;
      case ('='):
        digitalWrite(PinSR,  HIGH);
        delayMicroseconds(2500);
        digitalWrite(PinSR,  LOW);
        delayMicroseconds(100);
        break;
      case ('0'):
        digitalWrite(PinSR,  HIGH);
        delayMicroseconds(2580);
        digitalWrite(PinSR,  LOW);
        delayMicroseconds(100);
        break;
      case ('1'):
        digitalWrite(PinSR,  HIGH);
        delayMicroseconds(2660);
        digitalWrite(PinSR,  LOW);
        delayMicroseconds(100);
        break;
      case ('2'):
        digitalWrite(PinSR,  HIGH);
        delayMicroseconds(2740);
        digitalWrite(PinSR,  LOW);
        delayMicroseconds(100);
        break;
      case ('3'):
        digitalWrite(PinSR,  HIGH);
        delayMicroseconds(2820);
        digitalWrite(PinSR,  LOW);
        delayMicroseconds(100);
        break;
      case ('4'):
        digitalWrite(PinSR,  HIGH);
        delayMicroseconds(2900);
        digitalWrite(PinSR,  LOW);
        delayMicroseconds(100);
        break;
      case ('5'):
        digitalWrite(PinSR,  HIGH);
        delayMicroseconds(2980);
        digitalWrite(PinSR,  LOW);
        delayMicroseconds(100);
        break;
      case ('6'):
        digitalWrite(PinSR,  HIGH);
        delayMicroseconds(3060);
        digitalWrite(PinSR,  LOW);
        delayMicroseconds(100);
        break;
      case ('7'):
        digitalWrite(PinSR,  HIGH);
        delayMicroseconds(3140);
        digitalWrite(PinSR,  LOW);
        delayMicroseconds(100);
        break;
      case ('8'):
        digitalWrite(PinSR,  HIGH);
        delayMicroseconds(3220);
        digitalWrite(PinSR,  LOW);
        delayMicroseconds(100);
        break;
      case ('9'):
        digitalWrite(PinSR,  HIGH);
        delayMicroseconds(3300);
        digitalWrite(PinSR,  LOW);
        delayMicroseconds(100);
        break;

      default:
        // if nothing else matches, do the default
        // default is optional

        if (CharacterCount <= StringLength)
        {
          CharacterCount++;
          tempChar = CharBuffer[CharacterCount];
          goto ReadChars;
        }

        if (CurrentChar >> StringLength)
        {
          digitalWrite(PinSR,  HIGH);
          delayMicroseconds(3460);
          digitalWrite(PinSR,  LOW);
          delayMicroseconds(100);
          CharacterCount = 0;
          pinMode(PinSR, INPUT);
          digitalWrite(PinSR,  LOW);
          SRsend = false;
          Busy = false;
          oldmessage = "";
          CurrentChar = 0;
          tempChar = ' ';
          Serial.println();
          Serial.println("The message was sent...");
          Serial.println();
          startMicros = micros();
        }

        break;
    }

  }

  if (PinSRState == HIGH && SRsend == false)
  {
    startMicros = micros();
    HighTime = 0; // reset the HIGH time
    Busy = true;
    digitalWrite(PinLED, HIGH);
  }

  if (PinSRState == LOW && Busy == true && SRsend == false)
  {
    digitalWrite(PinLED, LOW);
    HighTime = micros(); // start counting the HIGH time

    if (HighTime <= 59)
    {
      tempChar = ' ';
    }
    else if (HighTime >= 60 && HighTime <= 140)
    {
      tempChar = 'A';
    }
    else if (HighTime >= 141 && HighTime <= 220)
    {
      tempChar = 'B';
    }
    else if (HighTime >= 221 && HighTime <= 300)
    {
      tempChar = 'C';
    }
    else if (HighTime >= 301 && HighTime <= 380)
    {
      tempChar = 'D';
    }
    else if (HighTime >= 381 && HighTime <= 460)
    {
      tempChar = 'E';
    }
    else if (HighTime >= 461 && HighTime <= 540)
    {
      tempChar = 'F';
    }
    else if (HighTime >= 541 && HighTime <= 620)
    {
      tempChar = 'G';
    }
    else if (HighTime >= 621 && HighTime <= 700)
    {
      tempChar = 'H';
    }
    else if (HighTime >= 701 && HighTime <= 780)
    {
      tempChar = 'I';
    }
    else if (HighTime >= 781 && HighTime <= 860)
    {
      tempChar = 'J';
    }
    else if (HighTime >= 861 && HighTime <= 940)
    {
      tempChar = 'K';
    }
    else if (HighTime >= 941 && HighTime <= 1020)
    {
      tempChar = 'L';
    }
    else if (HighTime >= 1021 && HighTime <= 1100)
    {
      tempChar = 'M';
    }
    else if (HighTime >= 1101 && HighTime <= 1180)
    {
      tempChar = 'N';
    }
    else if (HighTime >= 1181 && HighTime <= 1260)
    {
      tempChar = 'O';
    }
    else if (HighTime >= 1261 && HighTime <= 1340)    // 1300
    {
      tempChar = 'P';
    }
    else if (HighTime >= 1341 && HighTime <= 1420)
    {
      tempChar = 'Q';
    }
    else if (HighTime >= 1421 && HighTime <= 1500)
    {
      tempChar = 'R';
    }
    else if (HighTime >= 1501 && HighTime <= 1580)
    {
      tempChar = 'S';
    }
    else if (HighTime >= 1581 && HighTime <= 1660)
    {
      tempChar = 'T';
    }
    else if (HighTime >= 1661 && HighTime <= 1740)    // 1700
    {
      tempChar = 'U';
    }
    else if (HighTime >= 1741 && HighTime <= 1820)
    {
      tempChar = 'V';
    }
    else if (HighTime >= 1821 && HighTime <= 1900)
    {
      tempChar = 'W';
    }
    else if (HighTime >= 1901 && HighTime <= 1980)
    {
      tempChar = 'X';
    }
    else if (HighTime >= 1981 && HighTime <= 2060)
    {
      tempChar = 'Y';
    }
    else if (HighTime >= 2061 && HighTime <= 2140)    // 2100
    {
      tempChar = 'Z';
    }
    else if (HighTime >= 2141 && HighTime <= 2220)
    {
      tempChar = '-';
    }
    else if (HighTime >= 2221 && HighTime <= 2300)
    {
      tempChar = '.';
    }
    else if (HighTime >= 2301 && HighTime <= 2380)
    {
      tempChar = ' ';
    }
    else if (HighTime >= 2381 && HighTime <= 2460)
    {
      tempChar = '?';
    }
    else if (HighTime >= 2461 && HighTime <= 2540)
    {
      tempChar = '=';
    }
    else if (HighTime >= 2541 && HighTime <= 2620)
    {
      tempChar = '0';
    }
    else if (HighTime >= 2621 && HighTime <= 2700)
    {
      tempChar = '1';
    }
    else if (HighTime >= 2701 && HighTime <= 2780)
    {
      tempChar = '2';
    }
    else if (HighTime >= 2781 && HighTime <= 2860)
    {
      tempChar = '3';
    }
    else if (HighTime >= 2861 && HighTime <= 2940)
    {
      tempChar = '4';
    }
    else if (HighTime >= 2941 && HighTime <= 3020)
    {
      tempChar = '5';
    }
    else if (HighTime >= 3021 && HighTime <= 3100)
    {
      tempChar = '6';
    }
    else if (HighTime >= 3101 && HighTime <= 3180)
    {
      tempChar = '7';
    }
    else if (HighTime >= 3181 && HighTime <= 3260)
    {
      tempChar = '8';
    }
    else if (HighTime >= 3261 && HighTime <= 3340)    // 3300
    {
      tempChar = '9';
    }
    else if (HighTime >= 3341 && HighTime <= 3420 && SRreceive == true)   // character end transmission
    {
      oldmessage.concat(tempChar);
      CharacterCount = CharacterCount + 1; // count the characters
    }
    else if (HighTime >= 3421 && HighTime <= 3500 && SRreceive == false)   // message opening signal
    {
      CharacterCount = 0;
      SRreceive = true;
    }
    else if (HighTime >= 3421 && HighTime <= 3500 && SRreceive == true)   // message closing signal
    {
      newmessage = oldmessage;
      Serial.println();
      Serial.println();
      Serial.print("A message was received made from ");
      Serial.print(CharacterCount);
      Serial.println(" characters:");
      Serial.println(newmessage); // and print them all together
      Serial.println();
      //            EEPROM.writeString(6, newmessage);
      //            EEPROM.commit();
      oldmessage = "";
      delay(1000);
      Serial.println();
      Serial.println("Waiting to send or receive a new message...");
      Serial.println();
      CharacterCount = 0;
      SRreceive = false;
      Busy = false;
    }
  }
}
  1. I don't think this does what you think it does:
  micros() = 0; // reset the counter for microseconds
  millis() = 0; // reset the counter for milliseconds
  1. If you ever get into this while loop you will never exit:
  while (PinSRState == LOW && Busy == false && SRsend == false && SRreceive == false) {
    ProgramMillis = millis();
  }
  1. This will not compile:

oldmessage = MessageID + ID + ": " Serial.read();

  1. You specify no type here:

CharBuffer [StringLength];

  1. Why are you writing to an input?
  pinMode(PinSR, INPUT); // changed again inside the program when switching between sending and receiving
  digitalWrite(PinSR, LOW); // define start position for the communication pin

The code between the last break and default case will never run.

">>" is not a compare operator, it is right binary shift

Thanks for the extensive answers guys, not sure yet about the string and chars though. Does that mean it should function like I currently use the functions? Probably not... Anyway.

Let me see. Ehm. I got that library from the included standard examples. As far as I know they both contain flash which is then apparantly emulated as EEPROM. Not sure but it works fine although not an expert here either.

Does this mean 'read characters from EEPROM starting at address 6 until you reach a null character`?

Yes because I currently do not know the size of the message but I could add that, good point.

Not sure what the problem is with the timing functions but let me check your comments. I defined unsigned long(s) on top.

unsigned long HighTime = 0; // duration for the HIGH status of the pin
unsigned long ProgramMillis = 0; // defines the one minute interval time
unsigned long TotalProgramMillis = 0; // defines the total program running time
unsigned long BootMillis = 0; // defines the millis for the boot, possibly not used inside the program

Ok thanks. Let me try to convert it to if/else. Normally I like the clarity of switch case coding but I did not realize the limitation you mention.

Yes it will true in case of a 'o' or 'p', thanks:

if (BootMemory != 'n' && BootMemory != 'y') {

What am I missing, does it not just reset the counters? Oh my.

  micros() = 0; // reset the counter for microseconds
  millis() = 0; // reset the counter for milliseconds

Not sure now why that loop will not exit but let me check with some effort.

I did think there might be a problem with this way of coding it but as said I lack experience with strings. Any suggestions here?

oldmessage = MessageID + ID + ": " Serial.read();

The CharBuffer is defined up top but it is also faulty like this I suppose? It always is more difficult...

char CharBuffer = ' '; // create the a buffer to save the chars from the string

Writing to the INPUT to force a low starting position as it can float I thought. But normally you do not write to an INPUT, I understand that. If you digitalRead it I am not sure what it returns without being forced LOW. Not even sure if you can actually write to a INPUT like this. It is not great that is for sure.

Thanks for all the pointers.

If you make it for fun - why you won’t spend some time and at least a little understand these strings and arrays... as a result, you will be able to write code faster and easier and not shut up because of small errors
And finally, it’s so interesting to learn new things

First - you cant reset the millis and micros counters.
and the next - you don't know the syntax at all...

I haven't seen such mess in the code for a long time. Sorry

You are right but I spend little time coding and mostly with large time intervals due to other stuff, so I get rusty in between. I do mostly like it when I code but I need to have the time as working stuff out eats it very quickly. Let me try to find some more reference if I can.

The strings and arrays might not be the best approach even if I can make it to work.

Therefore I am searching for which direction to take in working out a solution to what I require.

I started yesterday on it and it is a bit messy, sure. It will take some time. Sometimes I just put ideas in so I do not forget and check the rest later. Not a professional here, for me (sadly for some) it is more about working out concepts than coding syntax but you are right.

First - you cant reset the millis and micros counters.

Thought I could reset those, I forgot sorry, then I need to add something in to remember the values.

Thanks again for your time.

I think you hardly achieve "concepts" without knowing the right syntax.
But knowing it, you will be able to write shorter and more understandable code.

For example, all this options from 'A' to 'Z'

can easily be replaced with this 5 lines:

      int first_delay = 100 + 80 * (tempChar - 'A');
      digitalWrite(PinSR,  HIGH);
      delayMicroseconds(first_delay);
      digitalWrite(PinSR,  LOW);
      delayMicroseconds(100);

The digits can be processed in the same way, only the signs will be a little more complicated.

Why would I need to avoid a String and what would be the problem with the goto you point to?

because is can fragment the minimal heap and lead to malfunctioning.

it is very bad programming style (when not absolutely necessary),
and often foreshadows other programming deficits.

because is can fragment the minimal heap and lead to malfunctioning.

This I also picked-up somewhere else today. I do clear all the String variables after use. You could instead use an array? What is the best method in terms of speed and efficiency? The messages might be large and I need to be able to process them with specific requirements.

it is very bad programming style (when not absolutely necessary),
and often foreshadows other programming deficits.

That is said, I know but why is the option there? If used carefully and checked well it should not give problems? Anyway I could change it up to some boolean functions but it might complicate things at this point.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.