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;
}
}
}