4 digit rotary encoder lock

Hi guys,

I have been using the rotary encoder on the arduino to count up and count down, displaying on the serial monitor. the passive subroutine is just to keep the rotary encoder from increasing and decreasing state.

i would like to make a 4 digit lock using the push button on the rotary encoder:

1- keep the count up and down feature
2- when a number is selected and the rotary encoder is pressed the number is stored
3- this must be repeated 3 more times
4- when a 4 digit number is clicked for example, 1 7 5 6, button 1 (external button) is used to check if the code is correct.

hope someone can guide me

#include <MultiFuncShield.h>
#include <TimerOne.h>
#include <Wire.h>

const int Button    = A1;
const int Point1    = 6;
const int Point2    = 9;
const int Switch    = 5;
int Count            = 0;
int C_State;
int L_State;


void setup() 
{
  Timer1.initialize();
  MFS.initialize(&Timer1);

  Serial.begin(9600);
  pinMode(Button,    INPUT_PULLUP);
 pinMode(Point1,    INPUT);
  pinMode(Point2,    INPUT);
  
  L_State = digitalRead(Point1);
}

void loop() 
{
 
Passive();

}


void Passive ()
{
  C_State = digitalRead(Point1);
  if (C_State != L_State)
  { 
      if (digitalRead(Point2) != C_State) 
      { 
       Count --;
      } 
       else 
      {
       Count ++;
      }
   
   Serial.print("Position: ");
   Serial.println(Count);
   MFS.write(Count);  
  } 
  L_State = C_State; 
}

Create an array with 4 entries and an index variable set to zero.
When the pushbutton becomes pressed save the count in the array at the position indicated by the index variable, increment the index variable and repeat until the index equals 4. Entry is now complete. The value in the array can now be checked

how do i save the value when the button is pressed i have no understanding in eeprom or storing values

You need to start with a place to store the 4 values. An array would be appropriate.

You need a way to count the number of times the encoder position value has been stored, so you know where to store the next value.

You need to read the state of the pin that the button is sewn onto.

You don't have any of that yet.

kzaki786:
how do i save the value when the button is pressed i have no understanding in eeprom or storing values

I was suggesting that you use an array to store the values, not the EEPROM