Switch to select eeprom memory 1 or memory 2

Hi

Can anyone please help, I have tried a couple of ways and I am getting stuck.
What would be the best way to do the following:-

I have a sketch that works good and saves to eeprom & reads the eeprom memory ok.
See attached file.

I now want to have two separate memory locations and use a switch input to select which memory to store and read depending on the position of the switch. and start up with the last used memory.

ie:
switch input HIGH = write to eeprom 1, read from eeprom 1.

switch input LOW = write to eeprom 2, read from eeprom 2.

This is the memory part of the code with just one memory location.

// Write the frequency to memory if not stored and 2 seconds have passed since the last frequency change.
if(memstatus == 0){
if(timepassed+2000 < millis()){
storeMEM();
}
}

}

void storeMEM(){
//Write each frequency section to a EPROM slot. Yes, it's cheating but it works!
EEPROM.write(0,millions);
EEPROM.write(1,hundredthousands);
EEPROM.write(2,tenthousands);
EEPROM.write(3,thousands);
EEPROM.write(4,hundreds);
EEPROM.write(5,tens);
EEPROM.write(6,ones);
memstatus = 1; // Let program know memory has been written

AD9850_LCD_ROTARY_WMENUS.ino (5.86 KB)

I now want to have two separate memory locations

Instead of the 7 you have now?

Or do you mean two sets of seven?

You do NOT need to hardcode the addresses.

byte startAddress = 0;

if(digitalRead(somePin) == HIGH)
   startAddress = 10;

storeMem(startAddress);

void storeMEM(byte startAddress)
{
  //Write each frequency section to a EPROM slot.  Yes, it's cheating but it works!
   EEPROM.write(startAddress, millions);
   EEPROM.write(startAddress+1, hundredthousands);
   EEPROM.write(startAddress+2, tenthousands);
   EEPROM.write(startAddress+3, thousands);
   EEPROM.write(startAddress+4, hundreds);       
   EEPROM.write(startAddress+5, tens);
   EEPROM.write(startAddress+6, ones);   
   memstatus = 1;  // Let program know memory has been written

Notice how a little white space makes the code a LOT more readable.

hi Pauls
Thank you for your quick reply.

Q - Instead of the 7 you have now? Or do you mean two sets of seven?

A - Two sets of seven memory locations

Hi Pauls

If I change to the following as you suggested, how do I code the read eeprom please?
And how would I save & read the second memory location when pin=LOW

byte startAddress = 0;

if(digitalRead(somePin) == HIGH)
startAddress = 10;

storeMem(startAddress);

void storeMEM(byte startAddress)
{
//Write each frequency section to a EPROM slot. Yes, it's cheating but it works!
EEPROM.write(startAddress, millions);
EEPROM.write(startAddress+1, hundredthousands);
EEPROM.write(startAddress+2, tenthousands);
EEPROM.write(startAddress+3, thousands);
EEPROM.write(startAddress+4, hundreds);
EEPROM.write(startAddress+5, tens);
EEPROM.write(startAddress+6, ones);
memstatus = 1; // Let program know memory has been written

And how would I save & read the second memory location when pin=LOW

What range of addresses are used now in the code when the pin is LOW ? Hint : what is the value of startAddress when the pin is LOW and when it is HIGH ?

how do I code the read eeprom please?

Go on. Have a wild guess.

UKHeliBob:
What range of addresses are used now in the code when the pin is LOW ? Hint : what is the value of startAddress when the pin is LOW and when it is HIGH ?
Go on. Have a wild guess.

I am stuck at getting the smartaddress at one location to compile when the pin is HIGH.

Error Message -

'startAddress' was not declared in this scope

EEPROM.read(startAddress, millions);

^

temp_sketch.ino:81: error: a function-definition is not allowed here before '{' token

void loop() {

Without seeing your code it is impossible to provide any help. Post it and the full error message here and use code tags when you do.

See read this before posting a programming question

Hi UKHelibob

The original code was attached to the first post.

Modified code - see attached file.

This is the error report for the modified code with the suggested "storeMem(startAddress)"


Arduino: 1.8.5 (Windows 10), Board: "Arduino/Genuino Uno"

C:\Program Files (x86)\Arduino\arduino-builder -dump-prefs -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\asuspc\Documents\Arduino\libraries -fqbn=arduino:avr:uno -vid-pid=0X2341_0X0043 -ide-version=10805 -build-path C:\Users\asuspc\AppData\Local\Temp\arduino_build_15856 -warnings=none -build-cache C:\Users\asuspc\AppData\Local\Temp\arduino_cache_364071 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avr-gcc.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.arduinoOTA.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -verbose C:\Users\asuspc\Desktop\temp_sketch\temp_sketch.ino\temp_sketch.ino.ino
C:\Program Files (x86)\Arduino\arduino-builder -compile -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\asuspc\Documents\Arduino\libraries -fqbn=arduino:avr:uno -vid-pid=0X2341_0X0043 -ide-version=10805 -build-path C:\Users\asuspc\AppData\Local\Temp\arduino_build_15856 -warnings=none -build-cache C:\Users\asuspc\AppData\Local\Temp\arduino_cache_364071 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avr-gcc.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.arduinoOTA.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -verbose C:\Users\asuspc\Desktop\temp_sketch\temp_sketch.ino\temp_sketch.ino.ino
Using board 'uno' from platform in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr
Using core 'arduino' from platform in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr
Detecting libraries used...
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10805 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "C:\Users\asuspc\AppData\Local\Temp\arduino_build_15856\sketch\temp_sketch.ino.ino.cpp" -o "nul"
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10805 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "-IC:\Program Files (x86)\Arduino\libraries\LiquidCrystal\src" "C:\Users\asuspc\AppData\Local\Temp\arduino_build_15856\sketch\temp_sketch.ino.ino.cpp" -o "nul"
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10805 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "-IC:\Program Files (x86)\Arduino\libraries\LiquidCrystal\src" "-IC:\Users\asuspc\Documents\Arduino\libraries\Rotary" "C:\Users\asuspc\AppData\Local\Temp\arduino_build_15856\sketch\temp_sketch.ino.ino.cpp" -o "nul"
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10805 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "-IC:\Program Files (x86)\Arduino\libraries\LiquidCrystal\src" "-IC:\Users\asuspc\Documents\Arduino\libraries\Rotary" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\EEPROM\src" "C:\Users\asuspc\AppData\Local\Temp\arduino_build_15856\sketch\temp_sketch.ino.ino.cpp" -o "nul"
Using cached library dependencies for file: C:\Program Files (x86)\Arduino\libraries\LiquidCrystal\src\LiquidCrystal.cpp
Using cached library dependencies for file: C:\Users\asuspc\Documents\Arduino\libraries\Rotary\rotary.cpp
Generating function prototypes...
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10805 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "-IC:\Program Files (x86)\Arduino\libraries\LiquidCrystal\src" "-IC:\Users\asuspc\Documents\Arduino\libraries\Rotary" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\EEPROM\src" "C:\Users\asuspc\AppData\Local\Temp\arduino_build_15856\sketch\temp_sketch.ino.ino.cpp" -o "C:\Users\asuspc\AppData\Local\Temp\arduino_build_15856\preproc\ctags_target_for_gcc_minus_e.cpp"
"C:\Program Files (x86)\Arduino\tools-builder\ctags\5.8-arduino11/ctags" -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives "C:\Users\asuspc\AppData\Local\Temp\arduino_build_15856\preproc\ctags_target_for_gcc_minus_e.cpp"
Compiling sketch...
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -flto -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10805 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "-IC:\Program Files (x86)\Arduino\libraries\LiquidCrystal\src" "-IC:\Users\asuspc\Documents\Arduino\libraries\Rotary" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\EEPROM\src" "C:\Users\asuspc\AppData\Local\Temp\arduino_build_15856\sketch\temp_sketch.ino.ino.cpp" -o "C:\Users\asuspc\AppData\Local\Temp\arduino_build_15856\sketch\temp_sketch.ino.ino.cpp.o"
C:\Users\asuspc\Desktop\temp_sketch\temp_sketch.ino\temp_sketch.ino.ino: In function 'void setup()':

temp_sketch.ino:72: error: 'startAddress' was not declared in this scope

EEPROM.read(startAddress, millions);

^

temp_sketch.ino:81: error: a function-definition is not allowed here before '{' token

void loop() {

^

temp_sketch.ino:231: error: expected '}' at end of input

};

^

Multiple libraries were found for "LiquidCrystal.h"
Used: C:\Program Files (x86)\Arduino\libraries\LiquidCrystal
Not used: C:\Users\asuspc\Documents\Arduino\libraries\Newliquidcrystal_1.3.5
Using library LiquidCrystal at version 1.0.7 in folder: C:\Program Files (x86)\Arduino\libraries\LiquidCrystal
Using library Rotary in folder: C:\Users\asuspc\Documents\Arduino\libraries\Rotary (legacy)
Using library EEPROM at version 2.0 in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\EEPROM
exit status 1
'startAddress' was not declared in this scope

test_code.ino (7.56 KB)

Modified code - see attached file.

This is the error report for the modified code with the suggested "storeMem(startAddress)"

Are you sure that you have attached the correct file because it contains no reference to startAddress

When you have sorted out saving and loading 2 values we will attack the clumsy way in which it is being done, but first things first.

Hi
Sorry wrong file attached to last post.

See attached file for latest code.

Error message:

Arduino: 1.8.5 (Windows 10), Board: "Arduino/Genuino Uno"

Compiling sketch...
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -flto -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10805 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "-IC:\Program Files (x86)\Arduino\libraries\LiquidCrystal\src" "-IC:\Users\asuspc\Documents\Arduino\libraries\Rotary" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\EEPROM\src" "C:\Users\asuspc\AppData\Local\Temp\arduino_build_15856\sketch\temp_sketch.ino.ino.cpp" -o "C:\Users\asuspc\AppData\Local\Temp\arduino_build_15856\sketch\temp_sketch.ino.ino.cpp.o"
C:\Users\asuspc\Desktop\Forum\temp_sketch.ino\temp_sketch.ino.ino: In function 'void setup()':

temp_sketch.ino:72: error: 'startAddress' was not declared in this scope

EEPROM.read(startAddress, millions);

^

temp_sketch.ino:81: error: a function-definition is not allowed here before '{' token

void loop() {

^

temp_sketch.ino:231: error: expected '}' at end of input

};

^

Multiple libraries were found for "LiquidCrystal.h"
Used: C:\Program Files (x86)\Arduino\libraries\LiquidCrystal
Not used: C:\Users\asuspc\Documents\Arduino\libraries\Newliquidcrystal_1.3.5
Using library LiquidCrystal at version 1.0.7 in folder: C:\Program Files (x86)\Arduino\libraries\LiquidCrystal
Using library Rotary in folder: C:\Users\asuspc\Documents\Arduino\libraries\Rotary (legacy)
Using library EEPROM at version 2.0 in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\EEPROM
exit status 1
'startAddress' was not declared in this scope

temp_sketch.ino.ino (7.97 KB)

Where does the setup() function end ?

Hi

I have added the following setup function end comment:
is that the correct way to do it?

// Load the stored frequency
if (ForceFreq == 0) {
}

EEPROM.read(startAddress, millions);
EEPROM.read(startAddress+1, hundredthousands);
EEPROM.read(startAddress+2, tenthousands);
EEPROM.read(startAddress+3, thousands);
EEPROM.read(startAddress+4, hundreds);
EEPROM.read(startAddress+5, tens);
EEPROM.read(startAddress+6, ones);
}

} //setup function end

void loop() {

If you mean that you have added a closing brace just before the loop() function then that sounds right. Have you ever tried Auto Format in the IDE ? It helps to spot such problems.

Does the code compile now ?

Hi.
Thanks I have switched on Auto format.

No still not compiling.

error report: "start address was not declared in scope"


Arduino: 1.8.5 (Windows 10), Board: "Arduino/Genuino Uno"

Compiling sketch...
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -flto -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10805 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "-IC:\Program Files (x86)\Arduino\libraries\LiquidCrystal\src" "-IC:\Users\asuspc\Documents\Arduino\libraries\Rotary" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\EEPROM\src" "C:\Users\asuspc\AppData\Local\Temp\arduino_build_15856\sketch\temp_sketch.ino.ino.cpp" -o "C:\Users\asuspc\AppData\Local\Temp\arduino_build_15856\sketch\temp_sketch.ino.ino.cpp.o"
C:\Users\asuspc\Desktop\Forum\temp_sketch.ino\temp_sketch.ino.ino: In function 'void setup()':

temp_sketch.ino:71: error: 'startAddress' was not declared in this scope

EEPROM.read(startAddress, millions);

^

C:\Users\asuspc\Desktop\Forum\temp_sketch.ino\temp_sketch.ino.ino: At global scope:

temp_sketch.ino:80: error: expected declaration before '}' token

} //setup function end

^

Multiple libraries were found for "LiquidCrystal.h"
Used: C:\Program Files (x86)\Arduino\libraries\LiquidCrystal
Not used: C:\Users\asuspc\Documents\Arduino\libraries\Newliquidcrystal_1.3.5
Using library LiquidCrystal at version 1.0.7 in folder: C:\Program Files (x86)\Arduino\libraries\LiquidCrystal
Using library Rotary in folder: C:\Users\asuspc\Documents\Arduino\libraries\Rotary (legacy)
Using library EEPROM at version 2.0 in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\EEPROM
exit status 1
'startAddress' was not declared in this scope

EVERY time you change the code, you need to post it.

See attached sketch file

temp_sketch.ino.ino (8.05 KB)

You have defined startAddress on line 266. You are trying to use it on line 71. Can you see that that could be a problem?

You are trying to call digitalRead() outside of a function, on line 268. That won't work.

You are trying to assign startAddress a new value on line 269. That won't work.

You are trying to call storeMem() in line 271, outside of a function. That won't work.

The snippets I posted need to be put in the right places in the setup() and/or loop() functions, as appropriate.

Here is the program formatted better

/*
  Main code by Richard Visokey AD7C - www.ad7c.com
  Revision 2.0 - November 6th, 2013
*/

// Include the library code
#include <LiquidCrystal.h>
#include <rotary.h>
#include <EEPROM.h>

//Setup some items
#define W_CLK 8   // Pin 8 - connect to AD9850 module word load clock pin (CLK)
#define FQ_UD 9   // Pin 9 - connect to freq update pin (FQ)
#define DATA 10   // Pin 10 - connect to serial data load pin (DATA)
#define RESET 11  // Pin 11 - connect to reset pin (RST) 
#define pulseHigh(pin) {digitalWrite(pin, HIGH); digitalWrite(pin, LOW); }
Rotary r = Rotary(2, 3); // sets the pins the rotary encoder uses.  Must be interrupt pins.
LiquidCrystal lcd(12, 13, 7, 6, 5, 4); // I used an odd pin combination because I need pin 2 and 3 for the interrupts.
int_fast32_t rx = 50000; // Base (starting) frequency of VFO.  This only loads once.  To force load again see ForceFreq variable below.
int_fast32_t rx2 = 1; // variable to hold the updated frequency
int_fast32_t increment = 10; // starting VFO update increment in HZ.
int_fast32_t iffreq = 0; // Intermedite Frequency - Amount to subtract (-) from base frequency. ********************************************
int buttonstate = 0;
int buttonstate2 = 0;
int GoIF = 1;
String hertz = "10 Hz";
int  hertzPosition = 5;
byte ones, tens, hundreds, thousands, tenthousands, hundredthousands, millions ; //Placeholders
String freq; // string to hold the frequency
int_fast32_t timepassed = millis(); // int to hold the arduino miilis since startup
int memstatus = 1;  // value to notify if memory is current or old. 0=old, 1=current.

int ForceFreq = 0;  // Change this to 0 after you upload and run a working sketch to activate the EEPROM memory.  YOU MUST PUT THIS BACK TO 0 AND UPLOAD THE SKETCH AGAIN AFTER STARTING FREQUENCY IS SET!

void setup()
{
  pinMode(A0, INPUT); // Set incrument, Connect to a button that goes to GND on push
  pinMode(A4, INPUT); // GB mod Speed select sw. Connects switch to GND whet closed
  // pinMode(A5,INPUT); // IF sense **********************************************
  digitalWrite(A0, HIGH);
  digitalWrite(A4, HIGH);
  // digitalWrite(A5,HIGH);
  lcd.begin(16, 2);
  PCICR |= (1 << PCIE2);
  PCMSK2 |= (1 << PCINT18) | (1 << PCINT19);
  sei();
  pinMode(FQ_UD, OUTPUT);
  pinMode(W_CLK, OUTPUT);
  pinMode(DATA, OUTPUT);
  pinMode(RESET, OUTPUT);
  pulseHigh(RESET);
  pulseHigh(W_CLK);
  pulseHigh(FQ_UD);  // this pulse enables serial mode on the AD9850 - Datasheet page 12.
  lcd.setCursor(hertzPosition, 1);
  lcd.print(hertz);
  /* // Load the stored frequency
    if (ForceFreq == 0) {
     freq = String(EEPROM.read(0))+String(EEPROM.read(1))+String(EEPROM.read(2))+String(EEPROM.read(3))+String(EEPROM.read(4))+String(EEPROM.read(5))+String(EEPROM.read(6));
     rx = freq.toInt();
    }
  */
  // Load the stored frequency
  if (ForceFreq == 0)
  {
  }
  EEPROM.read(startAddress, millions);
  EEPROM.read(startAddress + 1, hundredthousands);
  EEPROM.read(startAddress + 2, tenthousands);
  EEPROM.read(startAddress + 3, thousands);
  EEPROM.read(startAddress + 4, hundreds);
  EEPROM.read(startAddress + 5, tens);
  EEPROM.read(startAddress + 6, ones);
}

} //setup function end

void loop()
{
  // Update the display and frequency if the new Freq NEQ the old Freq
  if (rx != rx2)
  {
    showFreq();
    sendFrequency(rx);
    rx2 = rx;
  }
  // Rotate through the rate of tuning as you hold down the button
  buttonstate = digitalRead(A0);
  if (buttonstate == LOW)
  {
    setincrement();
  };
  // Check for PIN low to drive IF offset Freq
  buttonstate = digitalRead(A5);
  if (buttonstate != buttonstate2)
  {
    if (buttonstate == LOW)
    {
      lcd.setCursor(15, 1);
      lcd.print(".");
      GoIF = 0;
      buttonstate2 = buttonstate;
      sendFrequency(rx);
    }
    else
    {
      lcd.setCursor(15, 1);
      lcd.print(" ");
      GoIF = 1;
      buttonstate2 = buttonstate;
      sendFrequency(rx);
    };
  };
  // Write the frequency to memory if not stored and 2 seconds have passed since the last frequency change.
  if (memstatus == 0)
  {
    if (timepassed + 2000 < millis())
    {
      storeMEM();
    }
  }
}

// Interrupt routine to catch the rotary encoder
ISR(PCINT2_vect)
{
  unsigned char result = r.process();
  if (result)
  {
    if (result == DIR_CW)
    {
      rx = rx + increment;
    }
    else
    {
      rx = rx - increment;
    };
    if (rx >= 30000000)
    {
      rx = rx2;
    }; // UPPER VFO LIMIT
    if (rx <= 500)
    {
      rx = rx2;
    }; // LOWER VFO LIMIT
  }
}

// frequency calc from datasheet page 8 = <sys clock> * <frequency tuning word>/2^32
void sendFrequency(double frequency)
{
  if (GoIF == 1)
  {
    frequency = frequency - iffreq;
  }; //If pin = low, subtract the IF frequency.
  int32_t freq = frequency * 4294967295 / 125000000; // note 125 MHz clock on 9850.  You can make 'slight' tuning variations here by adjusting the clock frequency.
  for (int b = 0; b < 4; b++, freq >>= 8)
  {
    tfr_byte(freq & 0xFF);
  }
  tfr_byte(0x000);   // Final control byte, all 0 for 9850 chip
  pulseHigh(FQ_UD);  // Done!  Should see output
}
// transfers a byte, a bit at a time, LSB first to the 9850 via serial DATA line
void tfr_byte(byte data)
{
  for (int i = 0; i < 8; i++, data >>= 1)
  {
    digitalWrite(DATA, data & 0x01);
    pulseHigh(W_CLK);   //after each bit sent, CLK is pulsed high
  }
}

void setincrement()
{
  if (increment == 10)
  {
    increment = 50;
    hertz = "50 Hz";
    hertzPosition = 5;
  }
  else if (increment == 50)
  {
    increment = 100;
    hertz = "100 Hz";
    hertzPosition = 4;
  }
  else if (increment == 100)
  {
    increment = 500;
    hertz = "500 Hz";
    hertzPosition = 4;
  }
  else if (increment == 500)
  {
    increment = 1000;
    hertz = "1 Khz";
    hertzPosition = 6;
  }
  else if (increment == 1000)
  {
    increment = 2500;
    hertz = "2.5 Khz";
    hertzPosition = 4;
  }
  else if (increment == 2500)
  {
    increment = 5000;
    hertz = "5 Khz";
    hertzPosition = 6;
  }
  else if (increment == 5000)
  {
    increment = 10000;
    hertz = "10 Khz";
    hertzPosition = 5;
  }
  else if (increment == 10000)
  {
    increment = 100000;
    hertz = "100 Khz";
    hertzPosition = 4;
  }
  else if (increment == 100000)
  {
    increment = 1000000;
    hertz = "1 Mhz";
    hertzPosition = 6;
  }
  else
  {
    increment = 10;
    hertz = "10 Hz";
    hertzPosition = 5;
  };
  lcd.setCursor(0, 1);
  lcd.print("                ");
  lcd.setCursor(hertzPosition, 1);
  lcd.print(hertz);
  delay(250); // Adjust this delay to speed up/slow down the button menu scroll speed.
};

void showFreq()
{
  millions = int(rx / 1000000);
  hundredthousands = ((rx / 100000) % 10);
  tenthousands = ((rx / 10000) % 10);
  thousands = ((rx / 1000) % 10);
  hundreds = ((rx / 100) % 10);
  tens = ((rx / 10) % 10);
  ones = ((rx / 1) % 10);
  lcd.setCursor(0, 0);
  lcd.print("                ");
  if (millions > 9)
  {
    lcd.setCursor(1, 0);
  }
  else
  {
    lcd.setCursor(2, 0);
  }
  lcd.print(millions);
  lcd.print(".");
  lcd.print(hundredthousands);
  lcd.print(tenthousands);
  lcd.print(thousands);
  lcd.print(".");
  lcd.print(hundreds);
  lcd.print(tens);
  lcd.print(ones);
  lcd.print(" Mhz  ");
  timepassed = millis();
  memstatus = 0; // Trigger memory write
};
/*
  void storeMEM(){
  //Write each frequency section to a EPROM slot.  Yes, it's cheating but it works!
   EEPROM.write(0,millions);
   EEPROM.write(1,hundredthousands);
   EEPROM.write(2,tenthousands);
   EEPROM.write(3,thousands);
   EEPROM.write(4,hundreds);
   EEPROM.write(5,tens);
   EEPROM.write(6,ones);
   memstatus = 1;  // Let program know memory has been written

*/

byte startAddress = 0;

if (digitalRead(A4) == HIGH)
  startAddress = 10;

storeMem(startAddress);

void storeMEM(byte startAddress)
{
  //Write each frequency section to a EPROM slot.  Yes, it's cheating but it works!
  EEPROM.write(startAddress, millions);
  EEPROM.write(startAddress + 1, hundredthousands);
  EEPROM.write(startAddress + 2, tenthousands);
  EEPROM.write(startAddress + 3, thousands);
  EEPROM.write(startAddress + 4, hundreds);
  EEPROM.write(startAddress + 5, tens);
  EEPROM.write(startAddress + 6, ones);
  memstatus = 1;  // Let program know memory has been written
};

Now where does the setup() function end ?

Why are there semicolons after the closing braces of functions ?

Why is there code

if (digitalRead(A4) == HIGH)
  startAddress = 10;

storeMem(startAddress);

Not in a function ?

Thanks UKHelibob and PaulS

I have done the alterations you both suggested, but not too sure if I have done it correctly.

See new sketch attached

Error Report:
Compiling sketch...
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -flto -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10805 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "-IC:\Program Files (x86)\Arduino\libraries\LiquidCrystal\src" "-IC:\Users\asuspc\Documents\Arduino\libraries\Rotary" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\EEPROM\src" "C:\Users\asuspc\AppData\Local\Temp\arduino_build_69043\sketch\temp_sketch.ino.ino.cpp" -o "C:\Users\asuspc\AppData\Local\Temp\arduino_build_69043\sketch\temp_sketch.ino.ino.cpp.o"
C:\Users\asuspc\Desktop\Forum\temp_sketch.ino\temp_sketch.ino.ino: In function 'void setup()':

temp_sketch.ino:71: error: expected initializer before 'storeMem'

storeMem(startAddress);

^

temp_sketch.ino:76: error: no matching function for call to 'EEPROMClass::read(byte&, byte&)'

EEPROM.read(startAddress, millions);

^

C:\Users\asuspc\Desktop\Forum\temp_sketch.ino\temp_sketch.ino.ino:76:37: note: candidate is:

In file included from C:\Users\asuspc\Desktop\Forum\temp_sketch.ino\temp_sketch.ino.ino:10:0:

C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\EEPROM\src/EEPROM.h:120:13: note: uint8_t EEPROMClass::read(int)

uint8_t read( int idx ) { return EERef( idx ); }

^

C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\EEPROM\src/EEPROM.h:120:13: note: candidate expects 1 argument, 2 provided

temp_sketch.ino:77: error: no matching function for call to 'EEPROMClass::read(int, byte&)'

EEPROM.read(startAddress + 1, hundredthousands);

^

C:\Users\asuspc\Desktop\Forum\temp_sketch.ino\temp_sketch.ino.ino:77:49: note: candidate is:

In file included from C:\Users\asuspc\Desktop\Forum\temp_sketch.ino\temp_sketch.ino.ino:10:0:

C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\EEPROM\src/EEPROM.h:120:13: note: uint8_t EEPROMClass::read(int)

uint8_t read( int idx ) { return EERef( idx ); }

^

C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\EEPROM\src/EEPROM.h:120:13: note: candidate expects 1 argument, 2 provided

temp_sketch.ino:78: error: no matching function for call to 'EEPROMClass::read(int, byte&)'

EEPROM.read(startAddress + 2, tenthousands);

^

C:\Users\asuspc\Desktop\Forum\temp_sketch.ino\temp_sketch.ino.ino:78:45: note: candidate is:

In file included from C:\Users\asuspc\Desktop\Forum\temp_sketch.ino\temp_sketch.ino.ino:10:0:

C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\EEPROM\src/EEPROM.h:120:13: note: uint8_t EEPROMClass::read(int)

uint8_t read( int idx ) { return EERef( idx ); }

^

C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\EEPROM\src/EEPROM.h:120:13: note: candidate expects 1 argument, 2 provided

temp_sketch.ino:79: error: no matching function for call to 'EEPROMClass::read(int, byte&)'

EEPROM.read(startAddress + 3, thousands);

^

C:\Users\asuspc\Desktop\Forum\temp_sketch.ino\temp_sketch.ino.ino:79:42: note: candidate is:

In file included from C:\Users\asuspc\Desktop\Forum\temp_sketch.ino\temp_sketch.ino.ino:10:0:

C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\EEPROM\src/EEPROM.h:120:13: note: uint8_t EEPROMClass::read(int)

uint8_t read( int idx ) { return EERef( idx ); }

^

C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\EEPROM\src/EEPROM.h:120:13: note: candidate expects 1 argument, 2 provided

temp_sketch.ino:80: error: no matching function for call to 'EEPROMClass::read(int, byte&)'

EEPROM.read(startAddress + 4, hundreds);

^

C:\Users\asuspc\Desktop\Forum\temp_sketch.ino\temp_sketch.ino.ino:80:41: note: candidate is:

In file included from C:\Users\asuspc\Desktop\Forum\temp_sketch.ino\temp_sketch.ino.ino:10:0:

C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\EEPROM\src/EEPROM.h:120:13: note: uint8_t EEPROMClass::read(int)

uint8_t read( int idx ) { return EERef( idx ); }

^

C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\EEPROM\src/EEPROM.h:120:13: note: candidate expects 1 argument, 2 provided

temp_sketch.ino:81: error: no matching function for call to 'EEPROMClass::read(int, byte&)'

EEPROM.read(startAddress + 5, tens);

^

C:\Users\asuspc\Desktop\Forum\temp_sketch.ino\temp_sketch.ino.ino:81:37: note: candidate is:

In file included from C:\Users\asuspc\Desktop\Forum\temp_sketch.ino\temp_sketch.ino.ino:10:0:

C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\EEPROM\src/EEPROM.h:120:13: note: uint8_t EEPROMClass::read(int)

uint8_t read( int idx ) { return EERef( idx ); }

^

C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\EEPROM\src/EEPROM.h:120:13: note: candidate expects 1 argument, 2 provided

temp_sketch.ino:82: error: no matching function for call to 'EEPROMClass::read(int, byte&)'

EEPROM.read(startAddress + 6, ones);

^

C:\Users\asuspc\Desktop\Forum\temp_sketch.ino\temp_sketch.ino.ino:82:37: note: candidate is:

In file included from C:\Users\asuspc\Desktop\Forum\temp_sketch.ino\temp_sketch.ino.ino:10:0:

C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\EEPROM\src/EEPROM.h:120:13: note: uint8_t EEPROMClass::read(int)

uint8_t read( int idx ) { return EERef( idx ); }

^

C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\EEPROM\src/EEPROM.h:120:13: note: candidate expects 1 argument, 2 provided

C:\Users\asuspc\Desktop\Forum\temp_sketch.ino\temp_sketch.ino.ino: At global scope:

temp_sketch.ino:85: error: expected declaration before '}' token

} //setup function end

^

Multiple libraries were found for "LiquidCrystal.h"
Used: C:\Program Files (x86)\Arduino\libraries\LiquidCrystal
Not used: C:\Users\asuspc\Documents\Arduino\libraries\Newliquidcrystal_1.3.5
Using library LiquidCrystal at version 1.0.7 in folder: C:\Program Files (x86)\Arduino\libraries\LiquidCrystal
Using library Rotary in folder: C:\Users\asuspc\Documents\Arduino\libraries\Rotary (legacy)
Using library EEPROM at version 2.0 in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\EEPROM
exit status 1
expected initializer before 'storeMem'

temp_sketch.ino.ino (8.09 KB)

void storeMEM(byte startAddress)

storeMem(startAddress);

What are these lines supposed to do ?

Apart from anything else (and there is more), storeMEM is not the same as storeMem