//PD = Pin digit, PD1 is the most left position and PD4 is the most right
// PD1 PD2 PD3 PD4
int pd1 = 1;
int pd2 = 1;
int pd3 = 1;
int pd4 = 1;
int reset = 53;
int a = 0;
int b = 0;
int c = 0;
int d = 0;
int u1 = 0;
int u2 = 0;
int u3 = 0;
int u4 = 0;
#include <TM1637.h>
const int CLK = 11;
const int DIO = 12;
TM1637 tm(CLK, DIO);
void setup() {
tm.init();
tm.set(BRIGHT_TYPICAL);
Serial.begin(9600);
// pinMode initialization:
pinMode(25, INPUT_PULLUP);
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
pinMode(4, INPUT_PULLUP);
pinMode(45, INPUT_PULLUP);
pinMode(47, INPUT_PULLUP);
pinMode(49, INPUT_PULLUP);
pinMode(51, INPUT_PULLUP);
pinMode(reset, INPUT_PULLUP);
pinMode(22, OUTPUT);
pinMode(23, OUTPUT);
}
void loop() {
Serial.print(u1); Serial.print(" | "); Serial.print(u2); Serial.print(" | "); Serial.print(u3); Serial.print(" | "); Serial.println(u4);
tm.display(0,a); tm.display(1,b); tm.display(2,c); tm.display(3,d);
// up the green button
if (digitalRead(25) == 0) {a += 1; delay(200);}
if (digitalRead(2) == 0) {b += 1; delay(200);}
if (digitalRead(3) == 0) {c += 1; delay(200);}
if (digitalRead(4) == 0) {d += 1; delay(200);}
// down green button
if (digitalRead(45) == 0) {a -= 1; delay(200);}
if (digitalRead(47) == 0) {b -= 1; delay(200);}
if (digitalRead(49) == 0) {c -= 1; delay(200);}
if (digitalRead(51) == 0) {d -= 1; delay(200);}
// reset button
if (digitalRead(reset) == 0) {a = 0; b = 0; c = 0; d = 0; delay(200);}
// pin digit combination logic
if (a == pd1) {u1 = 1;} else {u1 = 0;}
if (b == pd2) {u2 = 1;} else {u2 = 0;}
if (c == pd3) {u3 = 1;} else {u3 = 0;}
if (d == pd4) {u4 = 1;} else {u4 = 0;}
// pin digit authentication from pin digit combination
int auth = u1 + u2 + u3 + u4;
if (auth == 4) {digitalWrite(22,HIGH);digitalWrite(23,LOW);}
else {digitalWrite(22,LOW);digitalWrite(23,HIGH);}
}