//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 = 13;
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 = 9;
const int DIO = 8;
TM1637 tm(CLK, DIO);
void setup() {
tm.init();
tm.set(BRIGHT_TYPICAL);
Serial.begin(9600);
// pinMode initialization:
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
pinMode(4, INPUT_PULLUP);
pinMode(5, INPUT_PULLUP);
pinMode(reset, INPUT_PULLUP);
pinMode(10, OUTPUT);
pinMode(11, 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);
// all the green button
if (digitalRead(2) == 0) {a += 1; delay(200);}
if (digitalRead(3) == 0) {b += 1; delay(200);}
if (digitalRead(4) == 0) {c += 1; delay(200);}
if (digitalRead(5) == 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(10,HIGH);digitalWrite(11,LOW);}
else {digitalWrite(10,LOW);digitalWrite(11,HIGH);}
}