int x1 = 2;
int x2 = 3;
int x3 = 4;
int x4 = 5;
int y1 = 6;
int y2 = 7;
int y3 = 8;
int y4 = 9;
int cislo = 0;
int matrix[6][6];
int moznosti[10];
int Xcursor = 0;
int Ycursor = 0;
int prosteneco = 0;
int nazev = 0;
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd1(0x27, 20, 4);
LiquidCrystal_I2C lcd2(0x28, 20, 4);
void setup() {
pinMode(x1, OUTPUT);
pinMode(x2, OUTPUT);
pinMode(x3, OUTPUT);
pinMode(x4, OUTPUT);
pinMode(y1, INPUT_PULLUP);
pinMode(y2, INPUT_PULLUP);
pinMode(y3, INPUT_PULLUP);
pinMode(y4, INPUT_PULLUP);
lcd1.init();
lcd2.init();
lcd1.backlight();
lcd2.backlight();
}
void loop() {
digitalWrite(x1, LOW);
if(digitalRead(y1) == LOW){
cislo = 1;
}
if(digitalRead(y2) == LOW){
cislo = 2;
}
if(digitalRead(y3) == LOW){
cislo = 3;
}
if(digitalRead(y4) == LOW){
Xcursor ++;
if(Xcursor > 5){
Xcursor = 0;
Ycursor ++;
}
if(Ycursor > 5){
Ycursor = 0;
}
delay(250);
lcd1.clear();
lcd2.clear();
}
digitalWrite(x1, HIGH);
digitalWrite(x2, LOW);
if(digitalRead(y1) == LOW){
cislo = 4;
}
if(digitalRead(y2) == LOW){
cislo = 5;
}
if(digitalRead(y3) == LOW){
cislo = 6;
}
if(digitalRead(y4) == LOW){
Xcursor --;
if(Xcursor < 0){
Xcursor = 5;
Ycursor --;
}
if(Ycursor < 0){
Ycursor = 5;
}
delay(250);
lcd1.clear();
lcd2.clear();
}
digitalWrite(x2, HIGH);
digitalWrite(x3, LOW);
if(digitalRead(y1) == LOW){
cislo = 7;
}
if(digitalRead(y2) == LOW){
cislo = 8;
}
if(digitalRead(y3) == LOW){
cislo = 9;
}
if(digitalRead(y4) == LOW){
matrix[Xcursor][Ycursor] = cislo;
}
digitalWrite(x3, HIGH);
digitalWrite(x4, LOW);
if(digitalRead(y1) == LOW){
cislo = 13;
}
if(digitalRead(y2) == LOW){
cislo = 0;
}
if(digitalRead(y3) == LOW){
cislo = 14;
}
if(digitalRead(y4) == LOW){
SOLVING();
}
digitalWrite(x4, HIGH);
lcd2.setCursor(19, 3);
lcd2.print(cislo);
for(int a = 0; a < 4;a++){
for(int i = 0; i < 6;i++){
lcd1.setCursor(i*2, a);
lcd1.print(matrix[i][a]);
}
}
for(int a = 0; a < 2;a++){
for(int i = 0; i < 6;i++){
lcd2.setCursor(i*2, a);
lcd2.print(matrix[i][a+4]);
}
}
if(Ycursor < 4){
lcd1.setCursor(Xcursor*2, Ycursor);
lcd1.print("*");
}else{
lcd2.setCursor(Xcursor*2, Ycursor-4);
lcd2.print("*");
}
delay(100);
}
void SOLVING(){
for(int y = 0; y < 6; y++){
for(int x = 0; x < 6; x++){
for(int i = 0; i < 6; i++){
moznosti[i] = 0;
}
if(matrix[x][y] == 0){
//-------------------------------------------------------------------------
if((x < 3) && (y < 2)){
moznosti[matrix[0][0]] = 1;
moznosti[matrix[1][0]] = 1;
moznosti[matrix[2][0]] = 1;
moznosti[matrix[0][1]] = 1;
moznosti[matrix[1][1]] = 1;
moznosti[matrix[2][1]] = 1;
}
if((x > 2) && (y < 2)){
moznosti[matrix[3][0]] = 1;
moznosti[matrix[4][0]] = 1;
moznosti[matrix[5][0]] = 1;
moznosti[matrix[3][1]] = 1;
moznosti[matrix[4][1]] = 1;
moznosti[matrix[5][1]] = 1;
}
if((x < 3) && (y < 4) && (y > 1)){
moznosti[matrix[0][2]] = 1;
moznosti[matrix[1][2]] = 1;
moznosti[matrix[2][2]] = 1;
moznosti[matrix[0][3]] = 1;
moznosti[matrix[1][3]] = 1;
moznosti[matrix[2][3]] = 1;
}
if((x > 2) && (y < 2)){
moznosti[matrix[3][2]] = 1;
moznosti[matrix[4][2]] = 1;
moznosti[matrix[5][2]] = 1;
moznosti[matrix[3][3]] = 1;
moznosti[matrix[4][3]] = 1;
moznosti[matrix[5][3]] = 1;
}
if((x < 3) && (y > 3)){
moznosti[matrix[0][4]] = 1;
moznosti[matrix[1][4]] = 1;
moznosti[matrix[2][4]] = 1;
moznosti[matrix[0][5]] = 1;
moznosti[matrix[1][5]] = 1;
moznosti[matrix[2][5]] = 1;
}
if((x > 2) && (y > 3)){
moznosti[matrix[3][4]] = 1;
moznosti[matrix[4][4]] = 1;
moznosti[matrix[5][4]] = 1;
moznosti[matrix[3][5]] = 1;
moznosti[matrix[4][5]] = 1;
moznosti[matrix[5][5]] = 1;
}
//-------------------------------------------------------------------------
for(int a = 0; a < 6; a ++){
moznosti[matrix[a][y]] = 1;
}
for(int a = 0; a < 6; a ++){
moznosti[matrix[x][a]] = 1;
}
//-------------------------------------------------------------------------
prosteneco = 0;
for(int l = 1; l < 7; l++){
if(moznosti[l] == 0){
prosteneco ++;
nazev = l;
}}
if(prosteneco == 1){
matrix[x][y] = nazev;
}
//------------------------------------------------------------------------
}
}
}
}