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