   }
 }
 
+
+void setPosition(unsigned char num){
+  result[buttonGrid.getRow(num)-1][buttonGrid.getColumn(num)-1] = 1;
+}
+
+
+boolean checkDownDiagonal(unsigned char num){
+  Serial.print("Num value: ");Serial.println(num);
+  setPosition(num);  
+  if((result[0][0]==1)&&(result[1][1]==1)&&(result[3][3]==1)&&(result[4][4]==1)){
+    return true;
+  }
+  return false;
+}
+
+
+boolean checkUpDiagonal(unsigned char num){
+  Serial.print("Num value: ");Serial.println(num);
+  setPosition(num);
+  if((result[4][0]==1)&&(result[3][1]==1)&&(result[1][3]==1)&&(result[0][4]==1)){
+    return true;
+  }
+  return false;
+}
+
+
+signed char checkHorizontal(unsigned char num){
+  setPosition(num);
+  for(byte r=0; r<5; r++)
+  {
+      if((result[r][0]==1)&&(result[r][1]==1)&&(result[r][2]==1)&&(result[r][3]==1)&&(result[r][4]==1)){
+        return r;
+      }
+  }
+  return -1;
+}
+
+
+signed char checkVertical(unsigned char num){
+  setPosition(num);
+  for(byte c=0; c<5; c++)
+  {
+      if((result[0][c]==1)&&(result[1][c]==1)&&(result[2][c]==1)&&(result[3][c]==1)&&(result[4][c]==1)){
+        return c;
+      }
+  }
+  return -1;
+}
+
+
+void showResult(){
+  Serial.println("Results");
+  for(byte r=0; r<5; r++)
+  {
+    for(byte c=0; c<5; c++)
+    {
+      Serial.print(result[r][c]);
+      Serial.print(",");
+    }
+    Serial.println();
+  }
+}
+
+
+void clearResult(){
+  for(byte r=0; r<5; r++)
+  {
+    for(byte c=0; c<5; c++)
+    {
+      result[r][c] = (r==2 && c==2) ? 1 : 0;
+    }
+  }  
+}

unsigned char G[5];
unsigned char O[5];

void setup() {
  Serial.begin(9600);
  canvas.init(TFT_LANDSCAPE);

    btnClear.setEventHandler(&buttonEventHandler);
    btnClear.init();
    btnClear.setDebounce(100);

    btnWon.setSize(200,100);
    btnWon.setColors(GREEN,BLACK,GRAY2);
    btnWon.setText("WON");
    btnWon.setEventHandler(&wonEventHandler);
    btnWon.init();
    btnWon.setDebounce(100);
    btnWon.visible = false;
    btnWon.block = true;
    
    buttonGrid.setSize(220 ,240);
    buttonGrid.setColors(GRAY1,BLACK,WHITE);
