Manufaturação industrial
Internet das coisas industrial | Materiais industriais | Manutenção e reparo de equipamentos | Programação industrial |
home  MfgRobots >> Manufaturação industrial >  >> Manufacturing Technology >> Processo de manufatura

Arduino Due TIC TAC TOE com tela sensível ao toque

Componentes e suprimentos

Arduino Due
× 1
2,8 zoll TFT LCD com touchscreen
× 1
Fios de jumpers (genérico)
× 1

Aplicativos e serviços online

Arduino IDE

Sobre este projeto





Sobre


Olá, quero compartilhar meu trabalho no projeto de nickthegreek82:arduino-touch-tic-tac-toe-game.

Você precisa:
  • a biblioteca Adafruit
  • a biblioteca GFX
  • e a biblioteca URTouch





Fiação


A fiação é a seguinte para a tela de toque:
  • Toque -> Arduino devido
  • T_IRQ -> 22
  • T_DO -> 24
  • T_DIN -> 26
  • T_CS -> 28
  • T_CLK -> 30

Para a tela:
  • Display -> Arduino devido
  • SDO -> A.25
  • LED -> 3,3 V
  • SCK -> A.27
  • SDI -> A.26
  • DC -> 9
  • REINICIAR -> 8
  • CS -> 10
  • GND -> GND
  • VCC -> 3,3 V

22/08/2017

Modificado o KI e alguma otimização de código.

26/08/2017

Alguma otimização de código.

27/08/2017

Você pode vencer contra a CPU?

13/03/2018

encontrou uma maneira melhor para o I.A.

os agradecimentos vão para klauscam https://github.com/klauscam/ArduinoTicTacToe

Código

  • TIC TAC TOE
  • TicTacToe_new
TIC TAC TOE Arduino
Um jogo TIC TAC TOE simples para jogar contra o computador
 //////////////////////////////////////// ///////// // 2.8 "TOUCH SCREEN TIC TAC TOE // // // // http://www.educ8s.tv // // // // modificado em 08.2017 por rom3 // / //////////////////////////////////////////////// # include  #include  #include  #include  #include  #define TFT_RST 8 # 9 # definir TFT_DC definir TFT_CS 10 # definir TOUCH_ORIENTATION LANDSCAPEAdafruit_ILI9341 tft =Adafruit_ILI9341 (TFT_CS, TFT_DC, TFT_RST); Botões Adafruit_GFX_Button [9]; URTouch myTouch (30, 28, 26, 24, 22); movimentos curtos não assinados int =1; vencedor int curto sem sinal =0; // 0 =Empate, 1 =Human, 2 =CPUunsigned short int x, y; // posição touchunsigned short int cursor; // Cursor positionunsigned short int firstMoves [] ={0,2,6,8}; // usará essas posições primeiro, se CPU começar sem sinal short int board [] ={0,0,0,0,0,0,0,0,0}; // mantém os dados de posição 0 está em branco, 1 humano, 2 é computerbool player; // verdadeiro =VOCÊ, falso =CPUbo ol b =1; char start [10] ={"Gamestart"}; char you [4] ={"YOU"}; char cpu [4] ={"CPU"}; char again [7] ={"Again?"}; const unsigned char circle [] PROGMEM ={0b0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0 , 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0 , 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x7,0xf8,0x0,0x0,0x0 , 0x0,0x0,0x0,0x0,0x7f, 0xff, 0x80,0x0,0x0,0x0,0x0,0x0,0x3,0xff, 0xff, 0xf0,0x0,0x0,0x0,0x0,0x0,0xf, 0xff, 0xff, 0xfc , 0x0,0x0,0x0,0x0,0x0,0x1f, 0xff, 0xff, 0xfe, 0x0,0x0,0x0,0x0,0x0,0x7f, 0xf0,0x3,0xff, 0x80,0x0,0x0,0x0,0x0,0xff, 0x80 , 0x0,0x7f, 0xc0,0x0,0x0,0x0,0x1,0xfe, 0x0,0x0,0x1f, 0xe0,0x0,0x0,0x0,0x3,0xf8,0x0,0x0,0x7,0xf0,0x0,0x0,0x0,0x7 , 0xf0,0x0,0x0,0x3,0xf8,0x0,0x0,0x0,0xf, 0xe0,0x0,0x0,0x1,0xfc, 0x0,0x0,0x0,0xf, 0xc0,0x0,0x0,0x0,0xfc, 0x0,0x0 , 0x0,0x1f, 0x80,0x0,0x0,0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0xff, 0xff, 0xc0,0x0,0x3,0xff, 0xff, 0xc0,0x3,0xff, 0xff, 0xe0,0x0, 0x3,0xff, 0xff, 0xc0,0x1,0xff, 0xff, 0xe0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0 , 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0 , 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0}; void setup () {myTouch.InitTouch (); myTouch.setPrecision (PREC_HI); tft.begin (); tft.setRotation (3); tft.fillScreen (ILI9341_BLACK); // Desenhar quadro branco tft.drawRect (0,0,320,240, ILI9341_WHITE); // Imprime o texto "Arduino" tft.setCursor (80,30); tft.setTextColor (ILI9341_GREEN); tft.setTextSize (4); tft.print ("Arduino"); // Imprimir texto "Jogo da velha" tft.setCursor (30,100); tft.setTextColor (ILI9341_WHITE); tft.setTextSize (4); tft.print ("Jogo da velha"); // Criar botão vermelho // criar botões // x, y, w, h, contorno, preenchimento, botões de texto [0] .initButton (&tft, 160,200,200,40, ILI9341_WHITE, ILI9341_RED, ILI9341_WHITE, iniciar, 2); botões [0] .drawButton (); faça {waitonetouch (&x, &y); if (botões [0] .contém (x, y)) b =0;} while (b> 0); } void loop () {for (unsigned short int i =0; i <9; i ++) {board [i] =0; } tft.fillScreen (ILI9341_BLACK); // Desenhar quadro branco tft.drawRect (0,0,320,240, ILI9341_WHITE); // Imprimir texto "Jogo da velha" tft.setCursor (30,30); tft.setTextColor (ILI9341_WHITE); tft.setTextSize (4); tft.print ("Jogo da velha"); // Imprima "YouTube!" text tft.setCursor (30.100); tft.setTextColor (ILI9341_GREEN); tft.setTextSize (4); tft.print ("Quem começa"); // Criar botão vermelho // criar botões // botões x, y, w, h, contorno, preenchimento, texto [0] .initButton (&tft, 100,200,80,40, ILI9341_WHITE, ILI9341_RED, ILI9341_WHITE, você, 2); botões [0] .drawButton (); // criar botões // x, y, w, h, contorno, preenchimento, botões de texto [1] .initButton (&tft, 200,200,80,40, ILI9341_WHITE, ILI9341_RED, ILI9341_WHITE, cpu, 2); botões [1] .drawButton (); b =1; faça {waitonetouch (&x, &y); if (botões [0] .contém (x, y)) {b =0; jogador =1; tft.fillScreen (ILI9341_BLACK); // Desenhar quadro branco tft.drawRect (0,0,320,240, ILI9341_WHITE); tft.setCursor (30,30); tft.setTextColor (ILI9341_WHITE); tft.setTextSize (2); tft.print ("Ok, você começa."); atraso (2000); } if (botões [1] .contém (x, y)) {b =0; jogador =0; tft.fillScreen (ILI9341_BLACK); // Desenhar quadro branco tft.drawRect (0,0,320,240, ILI9341_WHITE); tft.setCursor (30,30); tft.setTextColor (ILI9341_WHITE); tft.setTextSize (2); tft.print ("Ok, a CPU começa."); atraso (2000); }} enquanto (b> 0); b =1; move =1; vencedor =0; cursor =10; tft.fillScreen (ILI9341_BLACK); // Desenhar quadro tft.drawRect (0,0,320,240, ILI9341_WHITE); // Desenhe a linha vertical tft.fillRect (80,15,5,205, ILI9341_WHITE); tft.fillRect (150,15,5,205, ILI9341_WHITE); // Desenhe a linha horizontal tft.fillRect (15,80,205,5, ILI9341_WHITE); tft.fillRect (15,150,205,5, ILI9341_WHITE); tft.drawRect (230,10,80,220, ILI9341_WHITE); {do {if (move% 2 ==1 &&player ==false || move% 2 ==0 &&player ==true) {cursor + =10; tft.setCursor (240, cursor); tft.setTextSize (1); tft.println ("Eu desenho"); arduinoMove (); checkWinner (); } else {cursor + =10; tft.setCursor (240, cursor); tft.setTextSize (1); tft.println ("Sua jogada"); playerMove (); checkWinner (); } atraso (1000); move ++; } enquanto (vencedor ==0 &&movimentos <10); waitonetouch (&x, &y); tft.fillScreen (ILI9341_BLACK); // Desenhar quadro tft.drawRect (0,0,320,240, ILI9341_WHITE); // Imprimir texto "Game Over" tft.setCursor (50,30); tft.setTextColor (ILI9341_WHITE); tft.setTextSize (4); tft.print ("GAME OVER"); if (vencedor ==0) {// Imprimir "DRAW!" text tft.setCursor (110,100); tft.setTextColor (ILI9341_YELLOW); tft.setTextSize (4); tft.print ("DRAW");} if (vencedor ==1) {// Imprimir "VITÓRIOS HUMANOS!" text tft.setCursor (40,100); tft.setTextColor (ILI9341_BLUE); tft.setTextSize (4); tft.print ("WINS HUMANOS");} if (vencedor ==2) {// Imprimir "CPU WINS!" text tft.setCursor (60.100); tft.setTextColor (ILI9341_RED); tft.setTextSize (4); tft.print ("CPU WINS");} // cria botões // x, y, w, h, contorno, preenchimento, botões de texto [0] .initButton (&tft, 160,200,200,40, ILI9341_WHITE, ILI9341_RED, ILI9341_WHITE, novamente , 2); botões [0] .drawButton (); faça {waitonetouch (&x, &y); if (botões [0] .contém (x, y)) b =0; } enquanto (b> 0); }} void playerMove () {waitonetouch (&x, &y); if ((x> 15 &&x <85) &&(y> 15 &&y <85)) // 0 {if (board [0] ==0) {board [0] =1; drawX (15,15); } else error (); } else if ((x> 85 &&x <155) &&(y> 15 &&y <85)) // 1 {if (board [1] ==0) {board [1] =1; drawX (85,15); } else error (); } if ((x> 155 &&x <225) &&(y> 15 &&y <85)) // 2 {if (board [2] ==0) {board [2] =1; drawX (155,15); } else error (); } if ((x> 15 &&x <85) &&(y> 85 &&y <155)) // 3 {if (board [3] ==0) {board [3] =1; drawX (15,85); } else error (); } if ((x> 85 &&x <155) &&(y> 85 &&y <155)) // 4 {if (board [4] ==0) {board [4] =1; drawX (85,85); } else error (); } if ((x> 155 &&x <225) &&(y> 85 &&y <155)) // 5 {if (board [5] ==0) {board [5] =1; drawX (155,85); } else error (); } if ((x> 15 &&x <85) &&(y> 155 &&y <225)) // 6 {if (board [6] ==0) {board [6] =1; drawX (15,155); } else error (); } if ((x> 85 &&x <155) &&(y> 155 &&y <225)) // 7 {if (board [7] ==0) {board [7] =1; drawX (85,155); } else error (); } if ((x> 155 &&x <225) &&(y> 155 &&y <225)) // 8 {if (board [8] ==0) {board [8] =1; drawX (155,155); } else error (); }} erro vazio () {cursor + =10; tft.setCursor (240, cursor); tft.setTextSize (1); tft.println ("Erro"); atraso (1000); cursor + =10; tft.setCursor (240, cursor); tft.println ("Tente novamente."); playerMove ();} short unsigned int checkOpponent (unsigned short int x, unsigned short int y) {if (board [1] ==x &&board [2] ==x &&board [0] ==y) {if ( y ==0) {return 0; } else return 1; } if (board [3] ==x &&board [6] ==x &&board [0] ==y) {if (y ==0) {return 0; } else return 6; } if (board [0] ==y &&board [4] ==x &&board [8] ==x) {if (y ==0) {return 0; } else return 8; } if (board [0] ==x &&board [1] ==y &&board [2] ==x) {if (y ==0) {return 1; } else return 0; } if (board [4] ==x &&board [7] ==x &&board [1] ==y) {if (y ==0) {return 1; } else return 7; } if (board [0] ==x &&board [1] ==x &&board [2] ==y) {if (y ==0) {return 2; } else return 0; } if (board [5] ==x &&board [8] ==x &&board [2] ==y) {if (y ==0) {return 2; } else return 8; } if (board [4] ==x &&board [6] ==x &&board [2] ==y) {if (y ==0) {return 2; } else return 6; } if (board [4] ==x &&board [5] ==x &&board [3] ==y) {if (y ==0) {return 3; } else return 5; } if (board [0] ==x &&board [6] ==x &&board [3] ==y) {if (y ==0) {return 3; } else return 6; } if (board [3] ==x &&board [4] ==y &&board [5] ==x) {if (y ==0) {return 4; } else return 3; } if (board [1] ==x &&board [7] ==x &&board [4] ==y) {if (y ==0) {return 4; } else return 1; } if (board [0] ==x &&board [8] ==x &&board [4] ==y) {if (y ==0) {return 4; } else return 0; } if (board [2] ==x &&board [6] ==x &&board [4] ==y) {if (y ==0) {return 4; } else return 2; } if (board [3] ==x &&board [4] ==x &&board [5] ==y) {if (y ==0) {return 5; } else return 3; } if (tabuleiro [2] ==x &&tabuleiro [8] ==x &&tabuleiro [5] ==y) {if (y ==0) {return 5; } else return 2; } if (board [7] ==x &&board [8] ==x &&board [6] ==y) {if (y ==0) {return 6; } else return 8; } if (board [0] ==x &&board [3] ==x &&board [6] ==y) {if (y ==0) {return 6; } else return 0; } if (board [4] ==x &&board [2] ==x &&board [6] ==y) {if (y ==0) {return 6; } else return 2; } if (board [1] ==x &&board [4] ==x &&board [7] ==y) {if (y ==0) {return 7; } else return 1; } if (tabuleiro [6] ==x &&tabuleiro [8] ==x &&tabuleiro [7] ==y) {if (y ==0) {return 7; } else return 6; } if (tabuleiro [6] ==x &&tabuleiro [7] ==x &&tabuleiro [8] ==y) {if (y ==0) {return 8; } else return 6; } if (board [5] ==x &&board [2] ==x &&board [8] ==y) {if (y ==0) {return 8; } else return 2; } if (board [4] ==x &&board [0] ==x &&board [8] ==y) {if (y ==0) {return 8; } else return 0; } else return 100;} void arduinoMove () {if (moves <2) {do {unsigned short int randomMove =random (4); short unsigned int c =firstMoves [randomMove]; if (placa [c] ==0) {placa [c] =2; drawCpuMove (firstMoves [randomMove]); Retorna; }} enquanto (move <2); } if (move <3) {if (board [4] ==0) {board [4] =2; drawCpuMove (4); Retorna; }} unsigned short int twoPlayer =checkOpponent (2,0); // CPU dois em uma linha? if (twoPlayer <9) {board [twoPlayer] =2; drawCpuMove (twoPlayer); Retorna; } unsigned short int nextMove =checkOpponent (1,0); // Jogador dois em uma linha? if (nextMove <9) {board [nextMove] =2; drawCpuMove (nextMove); Retorna; } unsigned short int next =checkOpponent (0,2); if (next <9) {board [next] =2; drawCpuMove (próximo); Retorna; } faça {unsigned short int randomMove =random (9); if (tabuleiro [randomMove] ==0) {tabuleiro [randomMove] =2; drawCpuMove (randomMove); Retorna; }} while (nextMove ==100);} void drawCircle (unsigned short int x, unsigned short int y) {tft.drawBitmap (x, y, circle, 65,65, ILI9341_RED);} void drawX (unsigned short int x , int y curto sem sinal) {tft.drawBitmap (x, y, x_bitmap, 65,65, ILI9341_BLUE);} void drawCpuMove (movimento int curto sem sinal) {switch (move) {case 0:drawCircle (15,15); pausa; caso 1:drawCircle (85,15); pausa; caso 2:drawCircle (155,15); pausa; caso 3:drawCircle (15,85); pausa; caso 4:drawCircle (85,85); pausa; caso 5:drawCircle (155,85); pausa; caso 6:drawCircle (15,155); pausa; caso 7:drawCircle (85,155); break; caso 8:drawCircle (155,155); break; }} void checkWinner () // verifica o quadro para ver se há um vencedor // resultados de lugares na variável global 'vencedor' {// noughts win? if (tabuleiro [0]> 0 &&tabuleiro [1] ==tabuleiro [0] &&tabuleiro [2] ==tabuleiro [0]) {vencedor =tabuleiro [0]; tft.fillRect (15, 45, 205, 5, ILI9341_WHITE); } if (tabuleiro [3]> 0 &&tabuleiro [4] ==tabuleiro [3] &&tabuleiro [5] ==tabuleiro [3]) {vencedor =tabuleiro [3]; tft.fillRect (15, 115, 205, 5, ILI9341_WHITE); } if (tabuleiro [6]> 0 &&tabuleiro [7] ==tabuleiro [6] &&tabuleiro [8] ==tabuleiro [6]) {vencedor =tabuleiro [6]; tft.fillRect (15, 185, 205, 5, ILI9341_WHITE); } if (tabuleiro [0]> 0 &&tabuleiro [3] ==tabuleiro [0] &&tabuleiro [6] ==tabuleiro [0]) {vencedor =tabuleiro [0]; tft.fillRect (45, 15, 5, 205, ILI9341_WHITE); } if (tabuleiro [1]> 0 &&tabuleiro [4] ==tabuleiro [1] &&tabuleiro [7] ==tabuleiro [1]) {vencedor =tabuleiro [1]; tft.fillRect (115, 15, 5, 205, ILI9341_WHITE); } if (tabuleiro [2]> 0 &&tabuleiro [5] ==tabuleiro [2] &&tabuleiro [8] ==tabuleiro [2]) {vencedor =tabuleiro [2]; tft.fillRect (185, 15, 5, 205, ILI9341_WHITE); } if (tabuleiro [0]> 0 &&tabuleiro [4] ==tabuleiro [0] &&tabuleiro [8] ==tabuleiro [0]) {vencedor =tabuleiro [0]; para (int curto sem sinal xx =0; xx <6; xx ++) {tft.drawLine (20 + xx, 20, 210 + xx, 210, ILI9341_WHITE); }} if (tabuleiro [2]> 0 &&tabuleiro [4] ==tabuleiro [2] &&tabuleiro [6] ==tabuleiro [2]) {vencedor =tabuleiro [2]; para (int curto sem sinal xx =0; xx <6; xx ++) {tft.drawLine (210 + xx, 20, 20 + xx, 210, ILI9341_WHITE); }}} void waitonetouch (unsigned short int * x, unsigned short int * y) {do {delay (10); if (myTouch.dataAvailable () ==true) {myTouch.read (); * x =myTouch.getX (); // Obter ponto de contato * y =myTouch.getY (); Retorna; }} while (myTouch.dataAvailable () ==false); } 
TicTacToe_new Arduino
Um único jogador invencível Tic Tac Toe no Arduino Due
 /////////////////////////////////////////// //////// // 2.8 "TOUCH SCREEN TIC TAC TOE // // // // http://www.educ8s.tv // // // // modificado em 08.2017 por rom3 // // // /////////////////////////////////////////////// # include  #include  #include  #include  #define TFT_RST 8 # define TFT_DC 9 # define TFT_CS 10 # define TOUCH_ORIENTATION LANDSCAPEAdafruit_ILI9341 tft_Fruit_Fruit_341 tft_Fruit_ft_Fruit_341 tft_Fruit_ft_Tt_Fruit_341 tft_Fruit_ft_344 Tft_Fruit_ft_341 tft_Fruit_ft_344 tft_Fruit_uit_341 tft_Fruit_341 tft_Fruit_341 tft_Fruit_341 tft_Fruit_ft9341 tft_Fruit_ft) [9]; URTouch myTouch (30, 28, 26, 24, 22); char start [10] ={"Gamestart"}; char you [4] ={"YOU"}; char cpu [4] ={" CPU "}; char again [7] ={" Again? "}; Int player; int dificuldade =8; unsigned short int x, y, b; // toque de posição # define BLACK 0x0000 # define BLUE 0x001F # define RED 0xF800 # define GREEN 0x07E0 # define CYAN 0x07FF # define MAGENTA 0xF81F # define YELLOW 0xFFE0 # define WHITE 0xFFFFint board [] ={0,0,0,0,0,0,0,0,0}; // mantém os dados de posição 0 está em branco, 1 humano, 2 é a vez não assinada por computador; c onst unsigned char circle [] PROGMEM ={0b0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0 , 0x0,0x0,0x0,0x0,0x0,0x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,0x0,0x0,0x0,0x0}; void setup () {myTouch.InitTouch (); myTouch.setPrecision (PREC_HI); tft.begin (); tft.setRotation (3);} void loop () {int board [9] ={0,0,0,0,0,0,0,0,0}; drawStartScreen (); faça {myTouch.read (); x =myTouch.getX (); // Obter ponto de contato y =myTouch.getY (); atraso (100); } while (! (botões [0] .contains (x, y))); tft.fillScreen (PRETO); // Desenhar quadro branco tft.drawRect (0,0,320,240, WHITE); // Imprimir texto "Jogo da velha" tft.setCursor (30,30); tft.setTextColor (WHITE); tft.setTextSize (4); tft.print ("Jogo da velha"); // Imprima "YouTube!" text tft.setCursor (30.100); tft.setTextColor (GREEN); tft.setTextSize (4); tft.print ("Quem começa"); // Criar botão vermelho // criar botões // x, y, w, h, contorno, preenchimento, botões de texto [0] .initButton (&tft, 100,200,80,40, BRANCO, VERMELHO, BRANCO, você, 2); botões [0] .drawButton (); // criar botões // x, y, w, h, contorno, preenchimento, botões de texto [1] .initButton (&tft, 200,200,80,40, BRANCO, VERMELHO, BRANCO, cpu, 2); botões [1] .drawButton (); b =1; faça {myTouch.read (); x =myTouch.getX (); // Obter ponto de contato y =myTouch.getY (); if (botões [0] .contém (x, y)) {b =0; jogador =1; tft.fillScreen (PRETO); // Desenhar quadro branco tft.drawRect (0,0,320,240, WHITE); tft.setCursor (30,30); tft.setTextColor (WHITE); tft.setTextSize (2); tft.print ("Ok, você começa."); atraso (2000); } if (botões [1] .contém (x, y)) {b =0; jogador =2; tft.fillScreen (PRETO); // Desenhar quadro branco tft.drawRect (0,0,320,240, WHITE); tft.setCursor (30,30); tft.setTextColor (WHITE); tft.setTextSize (2); tft.print ("Ok, a CPU começa."); atraso (2000); }} enquanto (b); tft.fillScreen (PRETO); tft.drawRect (0,0,319,240, BRANCO); drawVerticalLine (125); drawVerticalLine (195); drawHorizontalLine (80); drawHorizontalLine (150); for (turn =0; turn <9 &&win (board) ==0; ++ turn) {if ((turn + player)% 2 ==0) computerMove (board); else {// desenhar (tabuleiro); playerMove (tabuleiro); }} switch (win (board)) {case 0:Serial.println ("É um empate. \ n"); pausa; caso 1:// sorteio (tabuleiro); Serial.println ("Você perde. \ N"); pausa; caso -1:Serial.println ("Você ganhou! \ n"); pausa; } faça {} while (myTouch.dataAvailable () ==false); // x =map (tp.y, 930, 88, 0, 480); // y =map (tp.x, 908, 125, 0, 320); // delay (250);}} void drawHorizontalLine (int y) {int i =0; para (i =0; i <7; i ++) {tft.drawLine (60, y + i, 270, y + i, BRANCO); }} void drawVerticalLine (int x) {int i =0; para (i =0; i <7; i ++) {tft.drawLine (x + i, 20, x + i, 220, BRANCO); }} void drawStartScreen () {tft.fillScreen (PRETO); // Desenhar quadro branco tft.drawRect (0,0,319,240, WHITE); // Imprimir texto "Jogo da velha" tft.setCursor (30,100); tft.setTextColor (WHITE); tft.setTextSize (4); tft.print ("Jogo da velha"); // Imprima "YouTube!" text tft.setCursor (80,30); tft.setTextColor (GREEN); tft.setTextSize (4); tft.print ("Arduino"); botões [0] .initButton (&tft, 160,200,200,40, BRANCO, VERMELHO, BRANCO, iniciar, 2); botões [0] .drawButton (); } void drawCircle (int x, int y) {drawBitmap (x, y, circle, 65,65, RED);} void drawX (int x, int y) {drawBitmap (x, y, x_bitmap, 65,65, AZUL );} void drawBitmap (int16_t x, int16_t y, const uint8_t * bitmap, int16_t w, int16_t h, uint16_t cor) {int16_t i, j, byteWidth =(w + 7) / 8; uint8_t byte; for (j =0; j  score) {score =tempScore; mover =i; }}} // retorna uma pontuação baseada na árvore minimax em um determinado nó. tabuleiro [movimento] =1; drawCpuMove (mover); atraso (100);} void playerMove (int board [9]) {int move =0; b =1; faça {if (myTouch.dataAvailable () ==true) {myTouch.read (); x =myTouch.getX (); // Obter ponto de contato y =myTouch.getY (); if ((x> 55 &&x <125) &&(y> 0 &&y <80)) // 0 {if (board [0] ==0) {move =0; b =0; }} else if ((x> 125 &&x <195) &&(y> 0 &&y <80)) // 1 {if (board [1] ==0) {move =1; b =0; }} else if ((x> 195 &&x <265) &&(y> 0 &&y <80)) // 2 {if (board [2] ==0) {move =2; b =0; }} else if ((x> 55 &&x <125) &&(y> 80 &&y <155)) // 3 {if (board [3] ==0) {move =3; b =0; }} else if ((x> 125 &&x <195) &&(y> 80 &&y <155)) // 4 {if (board [4] ==0) {move =4; b =0; }} else if ((x> 195 &&x <265) &&(y> 80 &&y <155)) // 5 {if (board [5] ==0) {move =5; b =0; }} else if ((x> 55 &&x <125) &&(y> 155 &&y <235)) // 6 {if (board [6] ==0) {move =6; b =0; }} else if ((x> 125 &&x <195) &&(y> 155 &&y <235)) // 7 {if (board [7] ==0) {move =7; b =0; }} else if ((x> 195 &&x <265) &&(y> 155 &&y <235)) // 8 {if (board [8] ==0) {move =8; b =0; }}}} enquanto (b); tabuleiro [movimento] =-1; drawPlayerMove (mover); delay (100);} int win (const int board [9]) {// lista de possíveis posições vencedoras vitórias não assinadas [8] [3] ={{0,1,2}, {3,4,5}, {6,7,8}, {0,3,6}, {1,4,7}, {2,5,8}, {0,4,8}, {2,4,6}}; int winPos; para (winPos =0; winPos <8; ++ winPos) {if (tabuleiro [ganha [winPos] [0]]! =0 &&tabuleiro [ganha [winPos] [0]] ==tabuleiro [ganha [winPos] [ 1]] &&tabuleiro [ganha [winPos] [0]] ==tabuleiro [ganha [winPos] [2]]) retorno do tabuleiro [ganha [winPos] [2]]; } return 0;} int minimax (int tabuleiro [9], int player, int depth) {// verificar as posições dos jogadores int vencedor =win (tabuleiro); se (vencedor! =0) retornar vencedor * jogador; movimento interno =-1; pontuação int =-2; int i; para (i =0; i <9; ++ i) {if (tabuleiro [i] ==0) {tabuleiro [i] =jogador; int thisScore =0; if (profundidade  score) {score =thisScore; mover =i; } // escolha o pior lance para o tabuleiro adversário [i] =0; }} if (move ==-1) return 0; retornar pontuação;} void drawCpuMove (int move) {switch (move) {case 0:drawCircle (55,15); pausa; caso 1:drawCircle (130,15); pausa; caso 2:drawCircle (205,15); pausa; caso 3:drawCircle (55,85); pausa; caso 4:drawCircle (130,85); pausa; caso 5:drawCircle (205,85); pausa; caso 6:drawCircle (55,155); pausa; caso 7:drawCircle (130,155); break; caso 8:drawCircle (205,155); break; }} void drawPlayerMove (int move) {switch (move) {case 0:drawX (55,15); pausa; caso 1:drawX (130,15); pausa; caso 2:drawX (205,15); pausa; caso 3:drawX (55,85); pausa; caso 4:drawX (130,85); pausa; caso 5:drawX (205,85); pausa; caso 6:drawX (55,155); pausa; caso 7:drawX (130,155); quebrar; caso 8:drawX (205,155); quebrar; }} 

Esquemas

Fiação

Processo de manufatura

  1. Cartão de visita do jogo Tic Tac Toe
  2. Monitoramento de CO2 com Sensor K30
  3. Comunicação para surdos-cegos com 1Sheeld / Arduino
  4. Aceitar moeda de controle com Arduino
  5. Arduino com Bluetooth para controlar um LED!
  6. Sensor capacitivo de impressão digital com um Arduino ou ESP8266
  7. Brincando com Nextion Display
  8. Braço robótico controlado por Nunchuk (com Arduino)
  9. Medindo a radiação solar com Arduino
  10. Mini Radar com Arduino