Using Millis to blink two leds at differant durations Problem

Last year Larry guided me to get my project going.
recently being able to change the timing parameters with the LED button Shield buttons stopped working, I am unable to adjust parameters with the buttons.
Also it seems to be not clearing the EEPROM, If I run the eeprom clear sketch and then run the timing sketch I can change the default Parameters.
I don't think I have changed the sketch (i reinstalled the last sketch you sent me and still not going)
I was starting to think there is a hardware problem But I have tried another arduino and Lcd Button shield and the problem persists. I am now thinking it may be an EEPROM issue.
any suggestions or wisdom would be greatly appreciated.

It sounds like either a hardware or software problem. We can't see either. Also you posted in the IDE Installation and Troubleshooting section.

If you have been here a year, you must have read the forum guidelines, or seen it mentioned...

Cannot remember, please post the sketch you are using.

Also a schematic will dust off the old brain too.
:older_man:

I have to work out how to post the code I was using but is at home. I can post tonight.
I did try reverting to the last code you posted in the original topic.
"Using Millis to blink two leds at differant durations"
but it seemed to have the same problem.

Do you think it could be EEPROM reached max number of writes.
If i Clear the EEPROM and load the sketch I will update with the defaults which I have written in the sketch.

Maybe, we will look a bit closer at the code when you repost it.

The SELECT switch may need a wider window or better still, use a digital input. :thinking:

You can do a quick test and change the base address up to different locations than are being used now.

I will get the code tonight.
I have been using the unit most weekends doing testing and experiments and it was working fine up till November.
then suddenly had this problem.
it is using the LCD Button shield and occasionally button RH works but nothing else,
you cannot decrease or increase figures, select or save.

Unlikely to be EEPROM writes… since you loaded the code onto a different board.

//
//  https://forum.arduino.cc/t/using-millis-to-blink-two-leds-at-differant-durations/944151?u=larryd
//
//  Version   YY/MM/DD     Comments
//  =======   ========     =======================================================
//  1.00      22/01/08     Running code
//  1.02      22/01/08     using micros() for better pulse timing
//  1.03      22/01/16     Added LCD and increment and decrement switches to adjust timing of LEDs
//  1.04      22/01/17     Changed out individual switches for analog_switch_ladder
//  1.05      22/01/17     Added EEPROM stuff
//  1.06      22/01/17     Fixed a timing bug
//  1.07      22/01/18     Now using 'pulseHighCounter' to disable LCD updates while a pulse is HIGH.
//                         This prevents the possibility of adding LCD code execution time to our pulse.
//  1.08      22/01/18     Added "graemecns" numbers to reflect his resistor ladder.
//  1.09      22/01/19     Ignore all 'non-essential ' code execution 'while' we are timing a pulse
//

#include <EEPROM.h>

//******************************************************************************
//Switch operation:
//
//Left/Right switches change the menu
//Up/Down    switches change the value of the variable
//Select     switch updates the EEPROM with all new values

//******************************************************************************
//remove comment marks for an I2C LCD
//#define serialLCDisBeingUsed  //uncomment if you have a serial LCD  <--------------<<<<<

//********************************************
#ifdef  serialLCDisBeingUsed
#include <Wire.h>

//LarryD's ladder numbers
#define RIGHT_10BIT_ADC                 0    //Right
#define UP_10BIT_ADC                    145  //Up
#define DOWN_10BIT_ADC                  329  //Down
#define LEFT_10BIT_ADC                  505  //Left
#define SELECT_10BIT_ADC                741  //Select

//Use I2C library:     https://github.com/duinoWitchery/hd44780
//LCD Reference:       https://www.arduino.cc/en/Reference/LiquidCrystal

//this LCD is I2C wired
#include <hd44780.h>   //main hd44780 header

//N O T E :
//hd44780_I2Cexp control LCD using I2C I/O expander backpack (PCF8574 or MCP23008)
//hd44780_I2Clcd control LCD with native I2C interface (PCF2116, PCF2119x, etc...)

#include <hd44780ioClass/hd44780_I2Cexp.h> //I2C expander i/o class header

//If you do not know what your I2C address is, first run the 'I2C_Scanner' sketch
//OR
//Run: I2CexpDiag.ino
//C:\Users\YourName\Documents\Arduino1.69\libraries\hd44780\examples\ioClass\hd44780_I2Cexp\I2CexpDiag

hd44780_I2Cexp lcd(0x3F);
//hd44780_I2Cexp lcd(0x27);

//********************************************
#else

//this LCD is parallel wired
#include <LiquidCrystal.h>

// LCD pin         4   6  11  12  13  14
//                RS  EN  D4  D5  D6  D7
LiquidCrystal lcd( 8,  9,  4,  5,  6,  7);

//"graemecns" ladder numbers
#define RIGHT_10BIT_ADC                 0    //Right
#define UP_10BIT_ADC                    101  //Up
#define DOWN_10BIT_ADC                  259  //Down
#define LEFT_10BIT_ADC                  410  //Left
#define SELECT_10BIT_ADC                640  //Select

#endif

//******************************************************************************
#define LEDon                           HIGH
#define LEDoff                          LOW

#define ENABLED                         true
#define DISABLED                        false

#define OPENED                          HIGH
#define CLOSED                          LOW  //+5V---[Internal 50k]---PIN---[switch]---GND

//For diagnostics only
//macro definition for a pulse on UNO pin 11 i.e. PINB3
//63ns
//pinMode(11,OUTPUT);         // add to setup()
//#define PULSE62_11          cli(); PINB = bit(PINB3); PINB = bit(PINB3); sei()

//******************************************************************************
//  https://www.freetronics.com.au/pages/16x2-lcd-shield-quickstart-guide#.YeUrY_7MLcd
//
//Analog switch ladder stuff
//                                          A0
//                                          |
//Resistor Ladder              +5V---[ 2k ]-+-[330R]-.-[620R]-.-[ 1k ]-.-[3.3k]-.
//                                          |        |        |        |        |
//                                         Rsw      Usw      Dsw      Lsw      Ssw
//                                          '--------'--------'--------'--------'--------GND

#define BUTTON_ADC_PIN                  A0   //A0 is connected to the ladder as seen above

//ADC readings expected for the 5 buttons on the ADC input

//LarryD's Numbers
//#define RIGHT_10BIT_ADC                 0    //Right
//#define UP_10BIT_ADC                    145  //Up
//#define DOWN_10BIT_ADC                  329  //Down
//#define LEFT_10BIT_ADC                  505  //Left
//#define SELECT_10BIT_ADC                741  //Select

#define BUTTONHYSTERESIS                10   //hysteresis for valid button sensing window

//return values for checkSwitches()
#define BUTTON_NONE                     0
#define BUTTON_RIGHT                    1
#define BUTTON_UP                       2
#define BUTTON_DOWN                     3
#define BUTTON_LEFT                     4
#define BUTTON_SELECT                   5

byte buttonJustPressed                = false;         //true after a checkSwitches() call if triggered
byte buttonJustReleased               = true;          //true after a checkSwitches() call if triggered
byte buttonWas                        = BUTTON_NONE;   //for detection of button events

//******************************************************************************
//LCD State Machine stuff
enum SM {Startup, Waiting, LED1onTime, LED2onTime, LEDsOffTime, LastState};
SM displayStateMachine = Startup;

//******************************************************************************
const byte LED1pin                    = 2;
const byte LED2pin                    = 3;

const byte heartbeatLED               = 13;

bool LED1Flag                         = DISABLED;
bool LED2Flag                         = DISABLED;
bool newCycleFlag                     = ENABLED;
bool nextCycleFlag                    = DISABLED;

//For reference, an update to the LCD can take 10-20 ms,
//hence we can consider an LCD update results in short term blocking of our code.
//N O T E :  when the pulseHighCounter is not equal to zero, we disable updates to the LCD.
//If we did not disable updates when a pulse was HIGH, and we "called" the update LCD routine,
//the update routine execution time is added (can be added) to the pulse time.
//This would cause a pulse width that is wider than we want.
//
byte pulseHighCounter                 = 0;

byte menuCounter                      = Waiting;
byte buttonSwitch                     = BUTTON_NONE;

const unsigned int incDecAmount       = 10;            //100 for both micro and milli seconds adjustments

//EEPROM stuff
//N O T E :   if the EEPROM data is valid, EEPROM location 0 will be 0xAA
unsigned int  LED1onDurationAddress   = 10;             //10 11 12 13
unsigned int  LED2onDurationAddress   = 14;             //14 15 16 17
unsigned int  LEDoffTimeAddress       = 18;             //18 19 20 21

//timing stuff
unsigned long LED1onDurationDefault   = 100 * 1000UL;    //ON time for LED1 in micro seconds
unsigned long LED1onDuration          = LED1onDurationDefault;
unsigned long LED1onDurationNew;

unsigned long LED2onDurationDefault   = 300  * 1000UL;    //ON time for LED2 in micro seconds
unsigned long LED2onDuration          = LED2onDurationDefault;
unsigned long LED2onDurationNew;

unsigned long LEDoffTimeDefault       = 1 * 1000UL;    //time between cycles in milliseconds
unsigned long LEDoffTime              = LEDoffTimeDefault;
unsigned long LEDoffTimeNew;

unsigned long heartbeatMillis;
unsigned long switchMillis;
unsigned long displaySM_Millis;
unsigned long nextCycleMillis;
unsigned long LED1onMicros;
unsigned long LED2onMicros;

//MULTI SPARK

#define LEDAon                           HIGH
#define LEDAoff                          LOW

const byte LED3pin                    = 11;
const byte LED4pin                    = 12;

byte LED3State                        = LEDAoff; //initial state of LED
byte LED4State                        = LEDAoff; //initial state of LED

//const unsigned long LED1onDuration    = 8 ;   //ON time for LED
//const unsigned long LED1offDuration   = 1191; //OFF time for LED
//const unsigned long LED2onDuration    = 10;   //ON time for LED
//const unsigned long LED2offDuration   = 2189; //OFF time for LED

//testing values
const unsigned long LED3onDuration    = 8;  //ON time for LED
const unsigned long LED3offDuration   = 192;   //OFF time for LED
const unsigned long LED4onDuration    = 12;     //Multi Spark ON time for LED
const unsigned long LED4offDuration   = 50;   //Multi Spark OFF time for LED

//timing stuff
unsigned long Timer1Interval          = LED3offDuration;
unsigned long Timer2Interval          = LED4offDuration;

unsigned long rememberTime1;
unsigned long rememberTime2;



//******************************************************************************
void setup()
{
  Serial.begin(115200);

  pinMode(heartbeatLED, OUTPUT);

  //pinMode(11, OUTPUT);

  pinMode(LED1pin, OUTPUT);
  digitalWrite(LED1pin, LEDoff);

  pinMode(LED2pin, OUTPUT);
  digitalWrite(LED2pin, LEDoff);

  lcd.begin(16, 2);
//MULTI SPARK

 pinMode(LED3pin, OUTPUT);         // define LEDpin as output
  digitalWrite(LED3pin, LED3State); // set initial state

  pinMode(LED4pin, OUTPUT);         // define LEDpin as output
  digitalWrite(LED4pin, LED4State); // set initial state

  delay(2000);
} //END of setup()


//******************************************************************************
void loop()
{

  //MULTISPARK
  
  //****************************************               T I M E R 1
  //has TIMER 1 expired ?
  if (millis() - rememberTime1 >= Timer1Interval)
  {
    //restart TIMER 1
    rememberTime1 = millis();

    //is the LED ON ?
    if (LED3State == LEDAon)
    {
      //toggle the state
      LED3State = LEDAoff;

      //initialize to the OFF interval
      Timer1Interval = LED3offDuration;
    }

    //the LED is OFF
    else
    {
      //toggle the state
      LED3State = LEDAon;

      //initialize to the ON interval
      Timer1Interval = LED3onDuration;
    }

    //update to the new LED state
    digitalWrite(LED3pin, LED3State);
  }

  //****************************************               T I M E R 2
  //has TIMER 2 expired ?
  if (millis() - rememberTime2 >= Timer2Interval)
  {
    //restart TIMER 2
    rememberTime2 = millis();

    //is the LED ON ?
    if (LED4State == LEDAon)
    {
      //toggle the state
      LED4State = LEDAoff;

      //initialize to the OFF interval
      Timer2Interval = LED4offDuration;
    }

    //the LED is OFF
    else
    {
      //toggle the state
      LED4State = LEDAon;

      //initialize to the ON interval
      Timer2Interval = LED4onDuration;
    }

    //update to the new LED state
    digitalWrite(LED4pin, LED4State);}

  //MULTISPARK END
    //****************************************               c h e c k S w i t c h e s    T I M E R
    //is it time to check the switches ?
    if (pulseHighCounter == 0 && millis() - switchMillis >= 100)
    {
      //restart this TIMER
      switchMillis = millis();

      buttonSwitch = checkSwitches();
    }

    //****************************************               L E D 1   O F F   T I M E R
    //time to turn OFF LED1 ?
    if (LED1Flag == ENABLED && micros() - LED1onMicros >= LED1onDuration)
    {
      digitalWrite(LED1pin, LEDoff);

      //DISABLE this TIMER
      LED1Flag = DISABLED;

      pulseHighCounter--;
    }

    //****************************************               L E D 2   O F F   T I M E R
    //time to turn OFF LED2 ?
    if (LED2Flag == ENABLED && micros() - LED2onMicros >= LED2onDuration)
    {
      digitalWrite(LED2pin, LEDoff);

      //DISABLE this TIMER
      LED2Flag = DISABLED;

      pulseHighCounter--;
    }
    
  //=============================================================
  //non critical events are only allowed when we 'are not' waiting for a pulse to finish
  if (pulseHighCounter == 0)
  {
    //****************************************               h e a r t b e a t L E D   T I M E R
    //is it time to toggle the heartbeatLED ?
    if (pulseHighCounter == 0 && millis() - heartbeatMillis >= 500)
    {
      //restart this TIMER
      heartbeatMillis = millis();

      //Toggle the heartbeatLED
      digitalWrite(heartbeatLED, !digitalRead(heartbeatLED));
    }

    //****************************************               n e x t C y c l e   T I M E R
    //time to start a new cycle
    if (nextCycleFlag == ENABLED && millis() - nextCycleMillis >= LEDoffTime)
    {
      //DISABLE this TIMER
      nextCycleFlag = DISABLED;

      //allow another cycle to start
      newCycleFlag = ENABLED;
    }

    //****************************************               d i s p l a y   u p d a t e   T I M E R
    //is it time to check the display State Machine ?
    if (millis() - displaySM_Millis >= 500)
    {
      //restart this TIMER
      displaySM_Millis = millis();

      //N O T E :  any 'Machine State' that updates the LCD takes ~ 20ms to complete
      //hence we can consider an LCD update results in short term blocking of our code
      displayMachine();
    }

    //****************************************               L E D s   O N  ?
    //should we turn on the LEDs ?
    if (newCycleFlag == ENABLED)
    {
      newCycleFlag = DISABLED;

      //enable the LED1 OFF TIMER
      LED1Flag = ENABLED;
      //start the TIMER
      LED1onMicros = micros();
      digitalWrite(LED1pin, LEDon);
      //this disables slow LCD updates while any LED/pulse is HIGH
      pulseHighCounter++;

      //enable the LED2 OFF TIMER
      LED2Flag = ENABLED;
      //start the TIMER
      LED2onMicros = micros();
      digitalWrite(LED2pin, LEDon);
      //this disables slow LCD updates while any LED/pulse is HIGH
      pulseHighCounter++;

      //enable the nextCycle TIMER
      nextCycleFlag = ENABLED;
      //start the TIMER
      nextCycleMillis = millis();
    }
    
  } //END of   if(pulseHighCounter == 0) 

  //****************************************
  //Other non blocking code goes here
  //****************************************

} //END of loop()


//******************************************************************************
void displayMachine()
{
  switch (displayStateMachine)
  {
    //****************************************
    case Startup:
      {
        //return the variables to their last values
        //is the EEPROM data valid ?
        if (EEPROM_ReadByte(0) == 0xAA)
        {
          //get the values from EEPROM
          LED1onDuration = EEPROM_ReadLong(LED1onDurationAddress);
          LED2onDuration = EEPROM_ReadLong(LED2onDurationAddress);
          LEDoffTime = EEPROM_ReadLong(LEDoffTimeAddress);
        }

        //we have to update to the default times
        else
        {
          //mark the EEPROM as valid data
          EEPROM_WriteByte(0, 0xAA);

          //save the default times
          EEPROM_WriteLong(LED1onDurationAddress, LED1onDurationDefault);
          EEPROM_WriteLong(LED2onDurationAddress, LED2onDurationDefault);
          EEPROM_WriteLong(LEDoffTimeAddress, LEDoffTimeDefault);
        }

        //update the "New" variables
        LED1onDurationNew = LED1onDuration;
        LED2onDurationNew = LED2onDuration;
        LEDoffTimeNew = LEDoffTime;

        //next state
        displayStateMachine = Waiting;
      }
      break;

    //****************************************
    case Waiting:
      {
        lcd.setCursor(0, 0);
        //                   111111
        //         0123456789012345
        //         1=XXXXX  2=YYYYY
        lcd.print("1=       2=     ");

        lcd.setCursor(2, 0);
        lcd.print(LED1onDuration);

        lcd.setCursor(11, 0);
        //                   111111
        //         0123456789012345
        //         1=XXXXX  2=YYYYY
        lcd.print(LED2onDuration);

        lcd.setCursor(0, 1);
        //                   111111
        //         0123456789012345
        //         Off = ZZZZZ ms
        lcd.print("Off =       ms  ");

        lcd.setCursor(6, 1);
        //                   111111
        //         0123456789012345
        //         Off = ZZZZZ ms
        lcd.print(LEDoffTime);
      }
      break;

    //****************************************
    case LED1onTime:
      {
        lcd.setCursor(0, 0);
        //                   111111
        //         0123456789012345
        //         LED1 ON = XXXXX
        lcd.print("LED1 ON =       ");

        lcd.setCursor(10, 0);
        lcd.print(LED1onDuration);

        lcd.setCursor(0, 1);
        //                   111111
        //         0123456789012345
        //         New     = XXXXX
        lcd.print("New     =       ");

        lcd.setCursor(10, 1);
        lcd.print(LED1onDurationNew);
      }
      break;

    //****************************************
    case LED2onTime:
      {
        lcd.setCursor(0, 0);
        //                   111111
        //         0123456789012345
        //         LED2 ON = XXXXX
        lcd.print("LED2 ON =       ");

        lcd.setCursor(10, 0);
        lcd.print(LED2onDuration);

        lcd.setCursor(0, 1);
        //                   111111
        //         0123456789012345
        //         New     = XXXXX
        lcd.print("New     =       ");

        lcd.setCursor(10, 1);
        lcd.print(LED2onDurationNew);
      }
      break;

    //****************************************
    case LEDsOffTime:
      {
        lcd.setCursor(0, 0);
        //                   111111
        //         0123456789012345
        //         LED1 ON = XXXXX
        lcd.print("LED OFF =       ");

        lcd.setCursor(10, 0);
        lcd.print(LEDoffTime);

        lcd.setCursor(0, 1);
        //                   111111
        //         0123456789012345
        //         New     = XXXXX
        lcd.print("New     =       ");

        lcd.setCursor(10, 1);
        lcd.print(LEDoffTimeNew);
      }
      break;

  } //END of switch...Case

} //END of    displayMachine()


//******************************************************************************
byte checkSwitches()
{
  unsigned int buttonVoltage;

  //start out assuming no button is pressed
  byte button = BUTTON_NONE;

  //read the switch ladder voltage
  buttonVoltage = analogRead(BUTTON_ADC_PIN);

  //******************************                                i n c r e m e n t   m e n u
  //is the voltage within valid voltage windows
  if (buttonVoltage < (RIGHT_10BIT_ADC + BUTTONHYSTERESIS))
  {
    button = BUTTON_RIGHT;

    //is this a new button press ?
    if (buttonJustReleased == true)
    {
      buttonJustReleased = false;

      //increment the menu
      menuCounter++;

      //have we reached the end of the menus ?
      if (menuCounter == LastState)
      {
        menuCounter = Waiting;
      }

      displayStateMachine = menuCounter;
    }
  }

  //******************************                                i n c r e m e n t   t i m e
  else if (buttonVoltage >= (UP_10BIT_ADC - BUTTONHYSTERESIS)
           && buttonVoltage <= (UP_10BIT_ADC + BUTTONHYSTERESIS))
  {
    button = BUTTON_UP;

    //is this a new button press ?
    if (buttonJustReleased == true)
    {
      buttonJustReleased = false;

      switch (displayStateMachine)
      {
        //*****************
        case LED1onTime:
          {
            //microsecond adjustment
            LED1onDurationNew = LED1onDurationNew + incDecAmount;
          }
          break;

        //*****************
        case LED2onTime:
          {
            //microsecond adjustment
            LED2onDurationNew = LED2onDurationNew + incDecAmount;
          }
          break;

        //*****************
        case LEDsOffTime:
          {
            //millisecond adjustment
            LEDoffTimeNew = LEDoffTimeNew + incDecAmount;
          }
          break;

      } //END of   switch...case
    }
  }

  //******************************                                d e c r e m e n t   t i m e
  else if (buttonVoltage >= (DOWN_10BIT_ADC - BUTTONHYSTERESIS)
           && buttonVoltage <= (DOWN_10BIT_ADC + BUTTONHYSTERESIS))
  {
    button = BUTTON_DOWN;

    //is this a new button press ?
    if (buttonJustReleased == true)
    {
      buttonJustReleased = false;

      switch (displayStateMachine)
      {
        //*****************
        case LED1onTime:
          {
            //microsecond adjustment
            LED1onDurationNew = LED1onDurationNew - incDecAmount;

            //don't go too low
            if (LED1onDurationNew < incDecAmount)
            {
              LED1onDurationNew = incDecAmount;
            }
          }
          break;

        //*****************
        case LED2onTime:
          {
            //microsecond adjustment
            LED2onDurationNew = LED2onDurationNew - incDecAmount;

            //don't go too low
            if (LED2onDurationNew < incDecAmount)
            {
              LED2onDurationNew = incDecAmount;
            }
          }
          break;

        //*****************
        case LEDsOffTime:
          {
            //millisecond adjustment
            LEDoffTimeNew = LEDoffTimeNew - incDecAmount;

            //don't go too low
            if (LEDoffTimeNew < incDecAmount)
            {
              LEDoffTimeNew = incDecAmount;
            }
          }
          break;

      } //END of   switch...case
    }
  }

  //******************************                                d e c r e m e n t   m e n u
  else if (buttonVoltage >= (LEFT_10BIT_ADC - BUTTONHYSTERESIS)
           && buttonVoltage <= (LEFT_10BIT_ADC + BUTTONHYSTERESIS))
  {
    button = BUTTON_LEFT;

    //is this a new button press ?
    if (buttonJustReleased == true)
    {
      buttonJustReleased = false;

      //decrement the menu
      menuCounter--;

      //have we reached the end of the menus ?
      if (menuCounter == Startup)
      {
        menuCounter = Waiting;
      }

      displayStateMachine = menuCounter;
    }
  }

  //******************************                                s t o r e   n e w   t i m e s
  else if (buttonVoltage >= (SELECT_10BIT_ADC - BUTTONHYSTERESIS)
           && buttonVoltage <= (SELECT_10BIT_ADC + BUTTONHYSTERESIS))
  {
    button = BUTTON_SELECT;

    //is this a new button press ?
    if (buttonJustReleased == true)
    {
      buttonJustReleased = false;

      //update the EEPROM to the new values, if they have changed
      //*****************
      if (LED1onDuration != LED1onDurationNew)
      {
        LED1onDuration = LED1onDurationNew;

        EEPROM_WriteLong(LED1onDurationAddress, LED1onDurationNew);
      }

      //*****************
      if (LED2onDuration != LED2onDurationNew)
      {
        LED2onDuration = LED2onDurationNew;

        EEPROM_WriteLong(LED2onDurationAddress, LED2onDurationNew);
      }

      //*****************
      if (LEDoffTime != LEDoffTimeNew)
      {
        LEDoffTime = LEDoffTimeNew;

        EEPROM_WriteLong(LEDoffTimeAddress, LEDoffTimeNew);
      }
    }

    //need to adjust our menu counter to the new state
    menuCounter = Waiting;

    displayStateMachine = Waiting;
  }

  //******************************
  //handle button flags for just pressed and just released events
  if ((buttonWas == BUTTON_NONE) && (button != BUTTON_NONE))
  {
    //the button was just pressed, set buttonJustPressed, this can optionally be used to
    //trigger a once-off action for a button press event
    //it's the duty of the receiver to clear these flags if it wants to detect
    //a new button change event
    buttonJustPressed  = true;
    buttonJustReleased = false;
  }

  //******************************
  if ((buttonWas != BUTTON_NONE) && (button == BUTTON_NONE))
  {
    buttonJustPressed  = false;
    buttonJustReleased = true;
  }

  //save the latest button value, for change event detection next time round
  buttonWas = button;

  //******************************
  return (button);

} //END of   checkSwitches()


//******************************************************************************
//This function will write a 4 byte (32bit) long to the EEPROM at
//the specified address to address + 3.
void EEPROM_WriteLong(int address, long value)
{
  //Decomposition from a long to 4 bytes by using bit shift.
  //One = Most significant -> Four = Least significant byte
  byte four  = (value & 0xFF);
  byte three = ((value >>  8) & 0xFF);
  byte two   = ((value >> 16) & 0xFF);
  byte one   = ((value >> 24) & 0xFF);

  //Write the 4 bytes into the eeprom memory.
  EEPROM.write(address,     four);
  EEPROM.write(address + 1, three);
  EEPROM.write(address + 2, two);
  EEPROM.write(address + 3, one);

} //END of   EEPROM_WriteLong()


//******************************************************************************
//This function will write a byte (8 bits) to the EEPROM at
//the specified address.
void EEPROM_WriteByte(int address, byte value)
{
  //Decomposition from a long to 1 byte by using bit shift.
  byte one = (value);

  //Write the 1 bytes into the eeprom memory.
  EEPROM.write(address, one);

} //END of   EEPROM_WriteByte()


//******************************************************************************
long EEPROM_ReadLong(int address)
{
  //Read the 4 bytes from the EEPROM memory.
  long four  = EEPROM.read(address);
  long three = EEPROM.read(address + 1);
  long two   = EEPROM.read(address + 2);
  long one   = EEPROM.read(address + 3);
  long r;

  r =     (one   << 24);
  r = r + (two   << 16);
  r = r + (three << 8);
  r = r +  four;

  return r;

} //END of   EEPROM_ReadLong()


//******************************************************************************
byte EEPROM_ReadByte(int address)
{
  //Read the 1 byte from the EEPROM memory.
  byte one = EEPROM.read(address);

  //Return the Byte
  return one;
} //END of   EEPROM_ReadByte()


//******************************************************************************
//                           E N D  O F  C O D E
//******************************************************************************

Link To Video.

Arduino With LCD Button Shield Running sketch on test circuit.
Yellow, Timed pulse for Fuel Injection
Red, Timed pulse for coil ignition fire when pulse turns off
Blue, OPTION to run 50 cycles/Sec ignition (pulse Jet)

do you plan to use this to control and actual "pulse Jet"?

I dont mean to be rude, but if thats the case, I would start with another project. Flashing lights at different intervals is reasonably trivial.
getting it wrong when connected to a jet would likely have non trivial results.

I have moved on from Pulse Jets I have been working on Pulse detonation engines with some success.
but having moved on my concern at the moment is to stop my HHO fuel resevoirs from flashing back and exploding.
Maybe my videos will be of interest to you.
There are some with flashing lights but most of these are Valveless Pulsejets, with LP Gas, Petrol then Pulse Detonation engines successes, Failures and Learning Curves.

Assumption, the sketch use to work as you needed.

To see if EEPROM locations are then problem, the EEPROM addresses have been changed to what is written in comments 1.10

These changes have not be tested here.


//
//  https://forum.arduino.cc/t/using-millis-to-blink-two-leds-at-differant-durations/944151?u=larryd
//
//  Version   YY/MM/DD     Comments
//  =======   ========     =======================================================
//  1.00      22/01/08     Running code
//  1.02      22/01/08     using micros() for better pulse timing
//  1.03      22/01/16     Added LCD and increment and decrement switches to adjust timing of LEDs
//  1.04      22/01/17     Changed out individual switches for analog_switch_ladder
//  1.05      22/01/17     Added EEPROM stuff
//  1.06      22/01/17     Fixed a timing bug
//  1.07      22/01/18     Now using 'pulseHighCounter' to disable LCD updates while a pulse is HIGH.
//                         This prevents the possibility of adding LCD code execution time to our pulse.
//  1.08      22/01/18     Added "graemecns" numbers to reflect his resistor ladder.
//  1.09      22/01/19     Ignore all 'non-essential ' code execution 'while' we are timing a pulse
//  1.10      23/01/13     Changed the default EEPROM addresses, address 29 will now be 0xAA, 30 to 41 for LED values

#include <EEPROM.h>

//******************************************************************************
//Switch operation:
//
//Left/Right switches change the menu
//Up/Down    switches change the value of the variable
//Select     switch updates the EEPROM with all new values

//******************************************************************************
//remove comment marks for an I2C LCD
//#define serialLCDisBeingUsed  //uncomment if you have a serial LCD  <--------------<<<<<

//********************************************
#ifdef  serialLCDisBeingUsed
#include <Wire.h>

//LarryD's ladder numbers
#define RIGHT_10BIT_ADC                 0    //Right
#define UP_10BIT_ADC                    145  //Up
#define DOWN_10BIT_ADC                  329  //Down
#define LEFT_10BIT_ADC                  505  //Left
#define SELECT_10BIT_ADC                741  //Select

//Use I2C library:     https://github.com/duinoWitchery/hd44780
//LCD Reference:       https://www.arduino.cc/en/Reference/LiquidCrystal

//this LCD is I2C wired
#include <hd44780.h>   //main hd44780 header

//N O T E :
//hd44780_I2Cexp control LCD using I2C I/O expander backpack (PCF8574 or MCP23008)
//hd44780_I2Clcd control LCD with native I2C interface (PCF2116, PCF2119x, etc...)

#include <hd44780ioClass/hd44780_I2Cexp.h> //I2C expander i/o class header

//If you do not know what your I2C address is, first run the 'I2C_Scanner' sketch
//OR
//Run: I2CexpDiag.ino
//C:\Users\YourName\Documents\Arduino1.69\libraries\hd44780\examples\ioClass\hd44780_I2Cexp\I2CexpDiag

hd44780_I2Cexp lcd(0x3F);
//hd44780_I2Cexp lcd(0x27);

//********************************************
#else

//this LCD is parallel wired
#include <LiquidCrystal.h>

// LCD pin         4   6  11  12  13  14
//                RS  EN  D4  D5  D6  D7
LiquidCrystal lcd( 8,  9,  4,  5,  6,  7);

//"graemecns" ladder numbers
#define RIGHT_10BIT_ADC                 0    //Right
#define UP_10BIT_ADC                    101  //Up
#define DOWN_10BIT_ADC                  259  //Down
#define LEFT_10BIT_ADC                  410  //Left
#define SELECT_10BIT_ADC                640  //Select

#endif

//******************************************************************************
#define LEDon                           HIGH
#define LEDoff                          LOW

#define ENABLED                         true
#define DISABLED                        false

#define OPENED                          HIGH
#define CLOSED                          LOW  //+5V---[Internal 50k]---PIN---[switch]---GND

//For diagnostics only
//macro definition for a pulse on UNO pin 11 i.e. PINB3
//63ns
//pinMode(11,OUTPUT);         // add to setup()
//#define PULSE62_11          cli(); PINB = bit(PINB3); PINB = bit(PINB3); sei()

//******************************************************************************
//  https://www.freetronics.com.au/pages/16x2-lcd-shield-quickstart-guide#.YeUrY_7MLcd
//
//Analog switch ladder stuff
//                                          A0
//                                          |
//Resistor Ladder              +5V---[ 2k ]-+-[330R]-.-[620R]-.-[ 1k ]-.-[3.3k]-.
//                                          |        |        |        |        |
//                                         Rsw      Usw      Dsw      Lsw      Ssw
//                                          '--------'--------'--------'--------'--------GND

#define BUTTON_ADC_PIN                  A0   //A0 is connected to the ladder as seen above

//ADC readings expected for the 5 buttons on the ADC input

//LarryD's Numbers
//#define RIGHT_10BIT_ADC                 0    //Right
//#define UP_10BIT_ADC                    145  //Up
//#define DOWN_10BIT_ADC                  329  //Down
//#define LEFT_10BIT_ADC                  505  //Left
//#define SELECT_10BIT_ADC                741  //Select

#define BUTTONHYSTERESIS                10   //hysteresis for valid button sensing window

//return values for checkSwitches()
#define BUTTON_NONE                     0
#define BUTTON_RIGHT                    1
#define BUTTON_UP                       2
#define BUTTON_DOWN                     3
#define BUTTON_LEFT                     4
#define BUTTON_SELECT                   5

byte buttonJustPressed                = false;         //true after a checkSwitches() call if triggered
byte buttonJustReleased               = true;          //true after a checkSwitches() call if triggered
byte buttonWas                        = BUTTON_NONE;   //for detection of button events

//******************************************************************************
//LCD State Machine stuff
enum SM {Startup, Waiting, LED1onTime, LED2onTime, LEDsOffTime, LastState};
SM displayStateMachine = Startup;

//******************************************************************************
const byte LED1pin                    = 2;
const byte LED2pin                    = 3;

const byte heartbeatLED               = 13;

bool LED1Flag                         = DISABLED;
bool LED2Flag                         = DISABLED;
bool newCycleFlag                     = ENABLED;
bool nextCycleFlag                    = DISABLED;

//For reference, an update to the LCD can take 10-20 ms,
//hence we can consider an LCD update results in short term blocking of our code.
//N O T E :  when the pulseHighCounter is not equal to zero, we disable updates to the LCD.
//If we did not disable updates when a pulse was HIGH, and we "called" the update LCD routine,
//the update routine execution time is added (can be added) to the pulse time.
//This would cause a pulse width that is wider than we want.
//
byte pulseHighCounter                 = 0;

byte menuCounter                      = Waiting;
byte buttonSwitch                     = BUTTON_NONE;

const unsigned int incDecAmount       = 10;            //100 for both micro and milli seconds adjustments

//EEPROM stuff
//N O T E :   if the EEPROM data is valid, EEPROM location 29 will be 0xAA
unsigned int  LED1onDurationAddress   = 30;             //30 31 32 33
unsigned int  LED2onDurationAddress   = 34;             //34 35 36 37
unsigned int  LEDoffTimeAddress       = 38;             //38 39 40 41

//timing stuff
unsigned long LED1onDurationDefault   = 100 * 1000UL;    //ON time for LED1 in micro seconds
unsigned long LED1onDuration          = LED1onDurationDefault;
unsigned long LED1onDurationNew;

unsigned long LED2onDurationDefault   = 300  * 1000UL;    //ON time for LED2 in micro seconds
unsigned long LED2onDuration          = LED2onDurationDefault;
unsigned long LED2onDurationNew;

unsigned long LEDoffTimeDefault       = 1 * 1000UL;    //time between cycles in milliseconds
unsigned long LEDoffTime              = LEDoffTimeDefault;
unsigned long LEDoffTimeNew;

unsigned long heartbeatMillis;
unsigned long switchMillis;
unsigned long displaySM_Millis;
unsigned long nextCycleMillis;
unsigned long LED1onMicros;
unsigned long LED2onMicros;

//MULTI SPARK

#define LEDAon                           HIGH
#define LEDAoff                          LOW

const byte LED3pin                    = 11;
const byte LED4pin                    = 12;

byte LED3State                        = LEDAoff; //initial state of LED
byte LED4State                        = LEDAoff; //initial state of LED

//const unsigned long LED1onDuration    = 8 ;   //ON time for LED
//const unsigned long LED1offDuration   = 1191; //OFF time for LED
//const unsigned long LED2onDuration    = 10;   //ON time for LED
//const unsigned long LED2offDuration   = 2189; //OFF time for LED

//testing values
const unsigned long LED3onDuration    = 8;  //ON time for LED
const unsigned long LED3offDuration   = 192;   //OFF time for LED
const unsigned long LED4onDuration    = 12;     //Multi Spark ON time for LED
const unsigned long LED4offDuration   = 50;   //Multi Spark OFF time for LED

//timing stuff
unsigned long Timer1Interval          = LED3offDuration;
unsigned long Timer2Interval          = LED4offDuration;

unsigned long rememberTime1;
unsigned long rememberTime2;



//******************************************************************************
void setup()
{
  Serial.begin(115200);

  pinMode(heartbeatLED, OUTPUT);

  //pinMode(11, OUTPUT);

  pinMode(LED1pin, OUTPUT);
  digitalWrite(LED1pin, LEDoff);

  pinMode(LED2pin, OUTPUT);
  digitalWrite(LED2pin, LEDoff);

  lcd.begin(16, 2);
//MULTI SPARK

 pinMode(LED3pin, OUTPUT);         // define LEDpin as output
  digitalWrite(LED3pin, LED3State); // set initial state

  pinMode(LED4pin, OUTPUT);         // define LEDpin as output
  digitalWrite(LED4pin, LED4State); // set initial state

  delay(2000);
} //END of setup()


//******************************************************************************
void loop()
{

  //MULTISPARK
  
  //****************************************               T I M E R 1
  //has TIMER 1 expired ?
  if (millis() - rememberTime1 >= Timer1Interval)
  {
    //restart TIMER 1
    rememberTime1 = millis();

    //is the LED ON ?
    if (LED3State == LEDAon)
    {
      //toggle the state
      LED3State = LEDAoff;

      //initialize to the OFF interval
      Timer1Interval = LED3offDuration;
    }

    //the LED is OFF
    else
    {
      //toggle the state
      LED3State = LEDAon;

      //initialize to the ON interval
      Timer1Interval = LED3onDuration;
    }

    //update to the new LED state
    digitalWrite(LED3pin, LED3State);
  }

  //****************************************               T I M E R 2
  //has TIMER 2 expired ?
  if (millis() - rememberTime2 >= Timer2Interval)
  {
    //restart TIMER 2
    rememberTime2 = millis();

    //is the LED ON ?
    if (LED4State == LEDAon)
    {
      //toggle the state
      LED4State = LEDAoff;

      //initialize to the OFF interval
      Timer2Interval = LED4offDuration;
    }

    //the LED is OFF
    else
    {
      //toggle the state
      LED4State = LEDAon;

      //initialize to the ON interval
      Timer2Interval = LED4onDuration;
    }

    //update to the new LED state
    digitalWrite(LED4pin, LED4State);}

  //MULTISPARK END
    //****************************************               c h e c k S w i t c h e s    T I M E R
    //is it time to check the switches ?
    if (pulseHighCounter == 0 && millis() - switchMillis >= 100)
    {
      //restart this TIMER
      switchMillis = millis();

      buttonSwitch = checkSwitches();
    }

    //****************************************               L E D 1   O F F   T I M E R
    //time to turn OFF LED1 ?
    if (LED1Flag == ENABLED && micros() - LED1onMicros >= LED1onDuration)
    {
      digitalWrite(LED1pin, LEDoff);

      //DISABLE this TIMER
      LED1Flag = DISABLED;

      pulseHighCounter--;
    }

    //****************************************               L E D 2   O F F   T I M E R
    //time to turn OFF LED2 ?
    if (LED2Flag == ENABLED && micros() - LED2onMicros >= LED2onDuration)
    {
      digitalWrite(LED2pin, LEDoff);

      //DISABLE this TIMER
      LED2Flag = DISABLED;

      pulseHighCounter--;
    }
    
  //=============================================================
  //non critical events are only allowed when we 'are not' waiting for a pulse to finish
  if (pulseHighCounter == 0)
  {
    //****************************************               h e a r t b e a t L E D   T I M E R
    //is it time to toggle the heartbeatLED ?
    if (pulseHighCounter == 0 && millis() - heartbeatMillis >= 500)
    {
      //restart this TIMER
      heartbeatMillis = millis();

      //Toggle the heartbeatLED
      digitalWrite(heartbeatLED, !digitalRead(heartbeatLED));
    }

    //****************************************               n e x t C y c l e   T I M E R
    //time to start a new cycle
    if (nextCycleFlag == ENABLED && millis() - nextCycleMillis >= LEDoffTime)
    {
      //DISABLE this TIMER
      nextCycleFlag = DISABLED;

      //allow another cycle to start
      newCycleFlag = ENABLED;
    }

    //****************************************               d i s p l a y   u p d a t e   T I M E R
    //is it time to check the display State Machine ?
    if (millis() - displaySM_Millis >= 500)
    {
      //restart this TIMER
      displaySM_Millis = millis();

      //N O T E :  any 'Machine State' that updates the LCD takes ~ 20ms to complete
      //hence we can consider an LCD update results in short term blocking of our code
      displayMachine();
    }

    //****************************************               L E D s   O N  ?
    //should we turn on the LEDs ?
    if (newCycleFlag == ENABLED)
    {
      newCycleFlag = DISABLED;

      //enable the LED1 OFF TIMER
      LED1Flag = ENABLED;
      //start the TIMER
      LED1onMicros = micros();
      digitalWrite(LED1pin, LEDon);
      //this disables slow LCD updates while any LED/pulse is HIGH
      pulseHighCounter++;

      //enable the LED2 OFF TIMER
      LED2Flag = ENABLED;
      //start the TIMER
      LED2onMicros = micros();
      digitalWrite(LED2pin, LEDon);
      //this disables slow LCD updates while any LED/pulse is HIGH
      pulseHighCounter++;

      //enable the nextCycle TIMER
      nextCycleFlag = ENABLED;
      //start the TIMER
      nextCycleMillis = millis();
    }
    
  } //END of   if(pulseHighCounter == 0) 

  //****************************************
  //Other non blocking code goes here
  //****************************************

} //END of loop()


//******************************************************************************
void displayMachine()
{
  switch (displayStateMachine)
  {
    //****************************************
    case Startup:
      {
        //return the variables to their last values
        //is the EEPROM data valid ?
        if (EEPROM_ReadByte(29) == 0xAA)
        {
          //get the values from EEPROM
          LED1onDuration = EEPROM_ReadLong(LED1onDurationAddress);
          LED2onDuration = EEPROM_ReadLong(LED2onDurationAddress);
          LEDoffTime = EEPROM_ReadLong(LEDoffTimeAddress);
        }

        //we have to update to the default times
        else
        {
          //mark the EEPROM as valid data
          EEPROM_WriteByte(29, 0xAA);

          //save the default times
          EEPROM_WriteLong(LED1onDurationAddress, LED1onDurationDefault);
          EEPROM_WriteLong(LED2onDurationAddress, LED2onDurationDefault);
          EEPROM_WriteLong(LEDoffTimeAddress, LEDoffTimeDefault);
        }

        //update the "New" variables
        LED1onDurationNew = LED1onDuration;
        LED2onDurationNew = LED2onDuration;
        LEDoffTimeNew = LEDoffTime;

        //next state
        displayStateMachine = Waiting;
      }
      break;

    //****************************************
    case Waiting:
      {
        lcd.setCursor(0, 0);
        //                   111111
        //         0123456789012345
        //         1=XXXXX  2=YYYYY
        lcd.print("1=       2=     ");

        lcd.setCursor(2, 0);
        lcd.print(LED1onDuration);

        lcd.setCursor(11, 0);
        //                   111111
        //         0123456789012345
        //         1=XXXXX  2=YYYYY
        lcd.print(LED2onDuration);

        lcd.setCursor(0, 1);
        //                   111111
        //         0123456789012345
        //         Off = ZZZZZ ms
        lcd.print("Off =       ms  ");

        lcd.setCursor(6, 1);
        //                   111111
        //         0123456789012345
        //         Off = ZZZZZ ms
        lcd.print(LEDoffTime);
      }
      break;

    //****************************************
    case LED1onTime:
      {
        lcd.setCursor(0, 0);
        //                   111111
        //         0123456789012345
        //         LED1 ON = XXXXX
        lcd.print("LED1 ON =       ");

        lcd.setCursor(10, 0);
        lcd.print(LED1onDuration);

        lcd.setCursor(0, 1);
        //                   111111
        //         0123456789012345
        //         New     = XXXXX
        lcd.print("New     =       ");

        lcd.setCursor(10, 1);
        lcd.print(LED1onDurationNew);
      }
      break;

    //****************************************
    case LED2onTime:
      {
        lcd.setCursor(0, 0);
        //                   111111
        //         0123456789012345
        //         LED2 ON = XXXXX
        lcd.print("LED2 ON =       ");

        lcd.setCursor(10, 0);
        lcd.print(LED2onDuration);

        lcd.setCursor(0, 1);
        //                   111111
        //         0123456789012345
        //         New     = XXXXX
        lcd.print("New     =       ");

        lcd.setCursor(10, 1);
        lcd.print(LED2onDurationNew);
      }
      break;

    //****************************************
    case LEDsOffTime:
      {
        lcd.setCursor(0, 0);
        //                   111111
        //         0123456789012345
        //         LED1 ON = XXXXX
        lcd.print("LED OFF =       ");

        lcd.setCursor(10, 0);
        lcd.print(LEDoffTime);

        lcd.setCursor(0, 1);
        //                   111111
        //         0123456789012345
        //         New     = XXXXX
        lcd.print("New     =       ");

        lcd.setCursor(10, 1);
        lcd.print(LEDoffTimeNew);
      }
      break;

  } //END of switch...Case

} //END of    displayMachine()


//******************************************************************************
byte checkSwitches()
{
  unsigned int buttonVoltage;

  //start out assuming no button is pressed
  byte button = BUTTON_NONE;

  //read the switch ladder voltage
  buttonVoltage = analogRead(BUTTON_ADC_PIN);

  //******************************                                i n c r e m e n t   m e n u
  //is the voltage within valid voltage windows
  if (buttonVoltage < (RIGHT_10BIT_ADC + BUTTONHYSTERESIS))
  {
    button = BUTTON_RIGHT;

    //is this a new button press ?
    if (buttonJustReleased == true)
    {
      buttonJustReleased = false;

      //increment the menu
      menuCounter++;

      //have we reached the end of the menus ?
      if (menuCounter == LastState)
      {
        menuCounter = Waiting;
      }

      displayStateMachine = menuCounter;
    }
  }

  //******************************                                i n c r e m e n t   t i m e
  else if (buttonVoltage >= (UP_10BIT_ADC - BUTTONHYSTERESIS)
           && buttonVoltage <= (UP_10BIT_ADC + BUTTONHYSTERESIS))
  {
    button = BUTTON_UP;

    //is this a new button press ?
    if (buttonJustReleased == true)
    {
      buttonJustReleased = false;

      switch (displayStateMachine)
      {
        //*****************
        case LED1onTime:
          {
            //microsecond adjustment
            LED1onDurationNew = LED1onDurationNew + incDecAmount;
          }
          break;

        //*****************
        case LED2onTime:
          {
            //microsecond adjustment
            LED2onDurationNew = LED2onDurationNew + incDecAmount;
          }
          break;

        //*****************
        case LEDsOffTime:
          {
            //millisecond adjustment
            LEDoffTimeNew = LEDoffTimeNew + incDecAmount;
          }
          break;

      } //END of   switch...case
    }
  }

  //******************************                                d e c r e m e n t   t i m e
  else if (buttonVoltage >= (DOWN_10BIT_ADC - BUTTONHYSTERESIS)
           && buttonVoltage <= (DOWN_10BIT_ADC + BUTTONHYSTERESIS))
  {
    button = BUTTON_DOWN;

    //is this a new button press ?
    if (buttonJustReleased == true)
    {
      buttonJustReleased = false;

      switch (displayStateMachine)
      {
        //*****************
        case LED1onTime:
          {
            //microsecond adjustment
            LED1onDurationNew = LED1onDurationNew - incDecAmount;

            //don't go too low
            if (LED1onDurationNew < incDecAmount)
            {
              LED1onDurationNew = incDecAmount;
            }
          }
          break;

        //*****************
        case LED2onTime:
          {
            //microsecond adjustment
            LED2onDurationNew = LED2onDurationNew - incDecAmount;

            //don't go too low
            if (LED2onDurationNew < incDecAmount)
            {
              LED2onDurationNew = incDecAmount;
            }
          }
          break;

        //*****************
        case LEDsOffTime:
          {
            //millisecond adjustment
            LEDoffTimeNew = LEDoffTimeNew - incDecAmount;

            //don't go too low
            if (LEDoffTimeNew < incDecAmount)
            {
              LEDoffTimeNew = incDecAmount;
            }
          }
          break;

      } //END of   switch...case
    }
  }

  //******************************                                d e c r e m e n t   m e n u
  else if (buttonVoltage >= (LEFT_10BIT_ADC - BUTTONHYSTERESIS)
           && buttonVoltage <= (LEFT_10BIT_ADC + BUTTONHYSTERESIS))
  {
    button = BUTTON_LEFT;

    //is this a new button press ?
    if (buttonJustReleased == true)
    {
      buttonJustReleased = false;

      //decrement the menu
      menuCounter--;

      //have we reached the end of the menus ?
      if (menuCounter == Startup)
      {
        menuCounter = Waiting;
      }

      displayStateMachine = menuCounter;
    }
  }

  //******************************                                s t o r e   n e w   t i m e s
  else if (buttonVoltage >= (SELECT_10BIT_ADC - BUTTONHYSTERESIS)
           && buttonVoltage <= (SELECT_10BIT_ADC + BUTTONHYSTERESIS))
  {
    button = BUTTON_SELECT;

    //is this a new button press ?
    if (buttonJustReleased == true)
    {
      buttonJustReleased = false;

      //update the EEPROM to the new values, if they have changed
      //*****************
      if (LED1onDuration != LED1onDurationNew)
      {
        LED1onDuration = LED1onDurationNew;

        EEPROM_WriteLong(LED1onDurationAddress, LED1onDurationNew);
      }

      //*****************
      if (LED2onDuration != LED2onDurationNew)
      {
        LED2onDuration = LED2onDurationNew;

        EEPROM_WriteLong(LED2onDurationAddress, LED2onDurationNew);
      }

      //*****************
      if (LEDoffTime != LEDoffTimeNew)
      {
        LEDoffTime = LEDoffTimeNew;

        EEPROM_WriteLong(LEDoffTimeAddress, LEDoffTimeNew);
      }
    }

    //need to adjust our menu counter to the new state
    menuCounter = Waiting;

    displayStateMachine = Waiting;
  }

  //******************************
  //handle button flags for just pressed and just released events
  if ((buttonWas == BUTTON_NONE) && (button != BUTTON_NONE))
  {
    //the button was just pressed, set buttonJustPressed, this can optionally be used to
    //trigger a once-off action for a button press event
    //it's the duty of the receiver to clear these flags if it wants to detect
    //a new button change event
    buttonJustPressed  = true;
    buttonJustReleased = false;
  }

  //******************************
  if ((buttonWas != BUTTON_NONE) && (button == BUTTON_NONE))
  {
    buttonJustPressed  = false;
    buttonJustReleased = true;
  }

  //save the latest button value, for change event detection next time round
  buttonWas = button;

  //******************************
  return (button);

} //END of   checkSwitches()


//******************************************************************************
//This function will write a 4 byte (32bit) long to the EEPROM at
//the specified address to address + 3.
void EEPROM_WriteLong(int address, long value)
{
  //Decomposition from a long to 4 bytes by using bit shift.
  //One = Most significant -> Four = Least significant byte
  byte four  = (value & 0xFF);
  byte three = ((value >>  8) & 0xFF);
  byte two   = ((value >> 16) & 0xFF);
  byte one   = ((value >> 24) & 0xFF);

  //Write the 4 bytes into the eeprom memory.
  EEPROM.write(address,     four);
  EEPROM.write(address + 1, three);
  EEPROM.write(address + 2, two);
  EEPROM.write(address + 3, one);

} //END of   EEPROM_WriteLong()


//******************************************************************************
//This function will write a byte (8 bits) to the EEPROM at
//the specified address.
void EEPROM_WriteByte(int address, byte value)
{
  //Decomposition from a long to 1 byte by using bit shift.
  byte one = (value);

  //Write the 1 bytes into the eeprom memory.
  EEPROM.write(address, one);

} //END of   EEPROM_WriteByte()


//******************************************************************************
long EEPROM_ReadLong(int address)
{
  //Read the 4 bytes from the EEPROM memory.
  long four  = EEPROM.read(address);
  long three = EEPROM.read(address + 1);
  long two   = EEPROM.read(address + 2);
  long one   = EEPROM.read(address + 3);
  long r;

  r =     (one   << 24);
  r = r + (two   << 16);
  r = r + (three << 8);
  r = r +  four;

  return r;

} //END of   EEPROM_ReadLong()


//******************************************************************************
byte EEPROM_ReadByte(int address)
{
  //Read the 1 byte from the EEPROM memory.
  byte one = EEPROM.read(address);

  //Return the Byte
  return one;
} //END of   EEPROM_ReadByte()


//******************************************************************************
//                           E N D  O F  C O D E
//******************************************************************************

Thanks Larry I will be able to set up and test this afternoon.
I at one stage was able to read eeprom on serial monitor, it was printing some numbers which would go when eeprom cleared. But I believe they came back when sketch was run.
House keeping question. When I load a sketch it seems to automatically saves the changes? Is it best to to manually save a good copy in a differant location before modifying a sketch or is there an option to not resave a sketch till after changes have been tested.

If you are referring to the sketch, suggest you save a copy with the version number in the name.
ex.
mySketchVersion1.10.ino

When you are making some test changes, save it under a new name with the new version number.

example:
junk.ino

  • make changes and test them thoroughly,
  • then save the new tested sketch:

mySketchVersion1.11.ino

OK I will continue with that process
Thanks.

Ok I have setup my default Arduino up at work.
Loaded the new code no change
RH Button will get to parameter menu and can button scroll through menu.
Up Button often if held down say for a second or more will reduce down the value
other 3 buttons not doing anything.
Loaded sketch onto my second arduino with shield
none of the Buttons seem to work on it.

I will see if I can find a simple program to load and test the LED Button Shield hardware is not the Problem.

Try this same sketch from the previous post.

Click the link below.

i Will check this.
I may have a hardware problem with my main shield.
I just tried the below sketch on my spare Button shield and all buttons are seeing a button push.
on my main button shield no indication of button press on the select button?

// Example program for MD_AButton library
//
// Determine the calibration values for the keys on 
// the LCD display menu pad
//
#include <LiquidCrystal.h>
#include <MD_AButton.h>

// LCD display definitions
const uint8_t LCD_ROWS = 2;
const uint8_t LCD_COLS = 16;

// LCD pin definitions
const uint8_t LCD_RS = 8;
const uint8_t LCD_ENA = 9;
const uint8_t LCD_D4 = 4;
const uint8_t LCD_D5 = LCD_D4+1;
const uint8_t LCD_D6 = LCD_D4+2;
const uint8_t LCD_D7 = LCD_D4+3;
const uint8_t LCD_KEYS = KEY_ADC_PORT; // use default pin

LiquidCrystal lcd(LCD_RS, LCD_ENA, LCD_D4, LCD_D5, LCD_D6, LCD_D7);

void setup() 
{ 
  lcd.begin(LCD_COLS, LCD_ROWS);
  lcd.clear();

  lcd.write("Keys Calibrate");
  lcd.setCursor(0,1);
  lcd.write("Press keys ...");

  pinMode(KEY_ADC_PORT, INPUT);
}

void loop() 
{
  int adcKeyIn;

  adcKeyIn = analogRead(KEY_ADC_PORT);    // read the value from the port  
  
  lcd.home();
  lcd.print("Value = ");
  lcd.print(adcKeyIn);
  lcd.print("   ");
  
  delay(100);
}