#include <Keypad.h>
#include<TM1651.h>
int CLK = 10;
int DIO = 9;
TM1651 batteryDisplay(CLK,DIO);
const byte ROWS = 4;
const byte COLS = 3;
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins[ROWS] = {8, 7, 6, 5};
byte colPins[COLS] = {4, 3, 2};
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
int start[7]={39,41,53,49,47,37,35};
int ugasi[7]={0,0,0,0,0,0,0};
int jedan[7]={0,1,1,0,0,0,0};
int dva[7]={1,1,0,1,1,0,1};
int tri[7]={1,1,1,1,0,0,1};
int cetiri[7]={0,1,1,0,0,1,1};
int pet[7]={1,0,1,1,0,1,1};
int sest[7]={0,0,1,1,1,1,1};
int sedam[7]={1,1,1,0,0,0,0};
int osam[7]={1,1,1,1,1,1,1};
int devet[7]={1,1,1,0,0,1,1};
int nula[7]={1,1,1,1,1,1,0};
int pom=0;
int s[50];
int k=0;
int partija=0;
void setup(){
Serial.begin(9600);
Output(start);
batteryDisplay.init();
batteryDisplay.set(BRIGHTEST);//BRIGHT_TYPICAL = 2,BRIGHT_DARKEST = 0,BRIGHTEST = 7;
batteryDisplay.frame(FRAME_ON);
randomSeed(analogRead(0));
while(partija!=8){
batteryDisplay.displayLevel(partija);
s[k]=random(0,10);
WriteDisplay(start,ugasi);
delay(200);
ispisi(s[k]);
if(Konacno(k)!=0){
WriteDisplay(start,ugasi);
break;
}
partija++;k++;
}//while end
}//setup end
void loop(){}
int Konacno(int k){
int pom=0;
while(pom<=k){
char key = keypad.getKey();
while(!key){ key = keypad.getKey(); }
if(s[pom]!=K(key)) return -1;
pom++;
delay(400);
}
return 0;
}//end konacno
int K(char key){
if(key=='1')return 1;
else if(key=='2')return 2;
else if(key=='3')return 3;
else if(key=='4')return 4;
else if(key=='5')return 5;
else if(key=='6')return 6;
else if(key=='7')return 7;
else if(key=='8')return 8;
else if(key=='9')return 9;
else if(key=='0')return 0;
else if(key=='*')return 10;
else if(key=='#')return 11;
}
void ispisi(int x){
switch(x){
case 1:{ WriteDisplay(start,jedan); break; }
case 2:{ WriteDisplay(start,dva); break; }
case 3:{ WriteDisplay(start,tri); break; }
case 4:{ WriteDisplay(start,cetiri); break; }
case 5:{ WriteDisplay(start,pet); break; }
case 6:{ WriteDisplay(start,sest); break; }
case 7:{ WriteDisplay(start,sedam); break; }
case 8:{ WriteDisplay(start,osam); break; }
case 9:{ WriteDisplay(start,devet); break; }
case 0:{ WriteDisplay(start,nula); break; }
}
}
void WriteDisplay(int start[], int niz[]){
for(int i=0;i<7;i++){
if(niz[i]==0)digitalWrite(start[i],LOW);
else digitalWrite(start[i],HIGH);
}
}
void Output(int start[]){
for(int i=0;i<7;i++){
pinMode(start[i],OUTPUT);
}
}
Comments