
Një nga sobat më të fuqishme të disponueshme Arduino Është versioni DUEFalë mikrokontrolluesit, memories dhe numrit të kunjave që ka, është një nga më të kërkuarit kur duhet të kryeni projekte komplekse.
Per kete arsye Ne e kemi përgatitur këtë artikull në mënyrë që të mësoni se për çfarë përdoret ky lloj pllake dhe cilat janë karakteristikat e tij kryesore. që u ofron përdoruesve.
Përveç kësaj, do të shpjegojmë se çfarë duhet të keni parasysh Kur punoni me një Arduino DUE, cilat janë ndryshimet në mjedisin e zhvillimit për programimin e pllakës?. Shikoni.
Çfarë është Arduino DUE dhe për çfarë përdoren këto borde zhvillimi me burim të hapur?
Arduino PUER shkak Është një pllakë që përmban një mikrokontrollues Atmel SAM3X8E, duke ofruar performancë shtesë për projekte në shkallë të gjerëKy kriter mbështetet edhe nga një numër më i madh i kunjave dixhitale hyrje dhe dalje dhe kunjat analoge. Funksionon me një tension prej 3.3V dhe ka 4 porte për pajisje, nga të cilat 2 janë për kabllo MicroUSB Këto përdoren për të lidhur pllakën me kompjuterin. Mund të përdoren sistemet operative Arduino Due. Windows, Linux y MacOS.
Karakteristikat e Arduino DUE: Cilat janë karakteristikat e tij më interesante?
Karakteristikat kryesore të Arduino DUE janë:
- Dimensionet e tij janë 101,52 × 53,3 mm dhe ka një peshë prej 36 gramësh.
- Ka një MCU Atmel SAM3X8E ARM Cortex-M3 Bërthamë 32-bit që funksionon në 84 MHz.
- Ka një kujtesë pasive 96 KB SRAMMegjithatë, nuk ka memorie EEPROM si pllakat e tjera Arduino. Memoria e saj flash është 512 KB.
- Tensioni në të cilin funksionon është 3Vme një limit maksimal hyrjeje prej 16V.
- karakteristika 54 kunja dixhitale, në të cilat 12 janë për modulim të pulsit.
- Kunjat e hyrjet analoge janë 12 dhe ata që largohen, 2.
- Ka 2 porta MicroUSB, Një JTAG, un SPI, dos Twi butonat e rivendosjes dhe fshirjes.
Çfarë duhet të keni parasysh kur punoni me një pllakë Arduino DUE?
Gjëja e parë që duhet të mbani mend është se kjo pllakë funksionon me një intensitet rryme prej 3.3V.Kjo do të thotë se funksionon me një tension dukshëm më të lartë se shumica e pllakave Arduino 5V. Prandaj, duhet të keni kujdes që të mos dëmtoni mikrokontrollorin, memorien dhe komponentët e tjerë për shkak të mbitensionit.
Një faktor tjetër për t'u marrë në konsideratë, megjithëse pak më pak i rëndësishëm, është madhësia dhe pesha e tij. Së fundmi, Duhet të merrni në konsideratë të gjitha kunjat dixhitale dhe analoge që keni në dispozicion. (me këtë nënkuptojmë nevojën që ka projekti juaj për i zënë të gjitha, pasi nëse kërkohet më pak, mund të zgjidhni një pllakë tjetër 5V më pak të kushtueshme).
A është mjedisi i zhvillimit (Arduino IDE) i ndryshëm për pllakat Arduino DUE?
El Mjedisi Arduino DUE nuk është i ndryshëm nga ai i bordeve të tjera. Thjesht duhet të mbash në mend se IDE ka konfiguruar për Pllaka Arduino UNOPrandaj, do të duhet të ndryshoni llojin e Arduino në program.
Për ta bërë këtë, do t'ju duhet të ndiqni këto hapa:
- Pasi ta keni hapur IDE shko te Tools.
- Pastaj zgjidhni Pllaka.
- Zgjidhni opsionin DATË.
Përdorimet e pllakës: Në cilat projekte mund të përdoret Arduino DUE?
Ju mund të përdorni Pllaka Arduino DUE në një numri i madh i projekteve.
Për shembull, mund të krijoni:
- Një pedal për të shtrembëruar tingullin e një kitare elektrike.
https://create.arduino.cc/projecthub/electrosmash-team/arduino-due-programmable-guitar-pedal-edfe8b - pajisje për të kryer elektrokardiograma.
https://create.arduino.cc/projecthub/javiergonzalezb/heart-rate-estimation-using-arduino-due-a2271a - gjenerator të formave të valëve.
https://create.arduino.cc/projecthub/search?q=due&type=Project
Përveç kësaj, Nëse doni të mësoni rreth një projekti në detaje, mund të krijoni një lojë me Zero dhe Kryqe.Për këtë pajisje do t'ju duhet një pllakë DUE, një kontrollues ose ekran me prekje LED TFT LCD 2,8 inç dhe kabllot e nevojshme për instalim.
Sa i përket montimit, do të duhet ta bëni sipas diagramit të mëposhtëm:
Kur të keni mbaruar, do t'ju duhet të hapni Arduino IDE dhe të shkruani këto kode:
#përfshij #përfshij #përfshij #përfshij #përfshij #define TFT_RST 8 #define TFT_DC 9 #define TFT_CS 10 #define ORIENTIMI I PREKJES PEIZAZH Adafruit_ILI9341 tft = Adafruit_ILI9341 (TFT_CS, TFT_DC, TFT_RST); Adafruit_GFX_Buttons [9]; URTouch myTouch (30, 28, 26, 24, 22); lëvizje të shkurtra int të pashënuara = 1; lëvizje të shkurtra int të pashënuara winner = 0; lëvizje të shkurtra int të pashënuara x, y; lëvizje të shkurtra int të pashënuara cursor; lëvizje të shkurtra int të pashënuara firstMoves [] = { 0, 2, 6, 8}; tabelë e shkurtër e pashënuar[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; lojtar bool; bool b = 1; char start[10] = {"Fillimi i Lojës"}; char you[4] = {"JU"}; char cpu[4] = {"CPU"}; char again[7] = {"Përsëri?"} };
const unsigned char círculo [] PROGMEM = {
0 b0 , 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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x0,0x0,0x0,0x3,0xff,0xff,0xc0,0x1,0xff,0xff,0xe0,0x0,
0x1 , 0xff , 0xff , 0xE0 , 0x1 , 0xff , 0xff , 0xC0 , 0x0 , 0x1 , 0xff , 0xff , 0xF0 , 0x3 , 0xff , 0xff , 0xC0 , 0x0 , 0x0 , 0xff , 0xff , 0xF0 , 0x7 , 0xff , 0xff , 0x80 , 0x0 , 0x0 ,0xff,0xff,0xf8,0x7,0xff,0xff,0x80,0x0,0x0,0x7f,0xff,0xf8,0xf,0xff,0xff,0x0,0x0,
0x0 , 0x3f , 0xff , 0xfc , 0xf , 0xff , 0xfe , 0x0 , 0x0 , 0x0 , 0x3f , 0xff , 0xfe , 0x1f , 0xff , 0xfe , 0x0 , 0x0 , 0x0 , 0x1f , 0xff , 0xfc , 0x1f , 0xff , 0xfc , 0x1f 0x0 , 0x0 , 0x0 ,0x1f,0xff,0xff,0x3f,0xff,0xfc,0x0,0x0,0x0,0xf,0xff,0xff,0x7f,0xff,0xf8,0x0,0x0,
0x0 , 0xf , 0xff , 0xff , 0xff , 0xff , 0xF8 , 0x0 , 0x0 , 0x0 , 0x7 , 0xff , 0xff , 0xff , 0xff , 0xF0 , 0x0 , 0x0 , 0x0 , 0x3 , 0xff , 0xff , 0xff , 0xff , 0xE0 , 0x0 , 0x0 , 0x0 ,0x3,0xff,0xff,0xff,0xff,0xe0,0x0,0x0,0x0,0x1,0xff,0xff,0xff,0xff,0xc0,0x0,0x0,
0x0 , 0x1 , 0xff , 0xff , 0xff , 0xff , 0xC0 , 0x0 , 0x0 , 0x0 , 0x0 , 0xff , 0xff , 0xff , 0xff , 0x80 , 0x0 , 0x0 , 0x0 , 0x0 , 0xff , 0xff , 0xff , 0xff , 0x80 , 0x0 , 0x0 , 0x0 ,0x0,0x7f,0xff,0xff,0xff,0x0,0x0,0x0,0x0,0x0,0x3f,0xff,0xff,0xfe,0x0,0x0,0x0,
0x0 , 0x0 , 0x3f , 0xff , 0xff , 0xfe , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x1f , 0xff , 0xff , 0xFC , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x1f , 0xff , 0xff , 0xFC , 0x0 , 0x0 , 0x0 , 0x0 ,0x0,0x1f,0xff,0xff,0xfc,0x0,0x0,0x0,0x0,0x0,0x3f,0xff,0xff,0xfe,0x0,0x0,0x0,
0x0 , 0x0 , 0x3f , 0xff , 0xff , 0xfe , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x7f , 0xff , 0xff , 0xff , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0xff , 0xff , 0xff , 0xff , 0x80 , 0x0 , 0x0 , 0x0 ,0x0,0xff,0xff,0xff,0xff,0x80,0x0,0x0,0x0,0x1,0xff,0xff,0xff,0xff,0xc0,0x0,0x0,
0x0 , 0x1 , 0xff , 0xff , 0xff , 0xff , 0xC0 , 0x0 , 0x0 , 0x0 , 0x3 , 0xff , 0xff , 0xff , 0xff , 0xE0 , 0x0 , 0x0 , 0x0 , 0x3 , 0xff , 0xff , 0xff , 0xff , 0xE0 , 0x0 , 0x0 , 0x0 ,0x7,0xff,0xff,0xff,0xff,0xf0,0x0,0x0,0x0,0xf,0xff,0xff,0xff,0xff,0xf8,0x0,0x0,
0x0 , 0xf , 0xff , 0xff , 0xff , 0xff , 0xf8 , 0x0 , 0x0 , 0x0 , 0x1f , 0xff , 0xff , 0x7f , 0xff , 0xfc , 0x0 , 0x0 , 0x0 , 0x1f , 0xff , 0xfc , 0x3f , 0xff , 0xfc , 0x3 0x0 , 0x0 , 0x0 ,0x3f,0xff,0xfc,0x3f,0xff,0xfe,0x0,0x0,0x0,0x3f,0xff,0xfc,0x1f,0xff,0xfe,0x0,0x0,
0x0 , 0x7f , 0xff , 0xF8 , 0x1f , 0xff , 0xff , 0x0 , 0x0 , 0x0 , 0xff , 0xff , 0xF8 , 0xf , 0xff , 0xff , 0x80 , 0x0 , 0x0 , 0xff , 0xff , 0xF0 , 0x7 , 0xff , 0xff , 0x80 , 0x0 , 0x1 ,0xff,0xff,0xe0,0x7,0xff,0xff,0xc0,0x0,0x1,0xff,0xff,0xe0,0x3,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
};
configuración vacía () {
myTouch . InitTouch(); myTouch. setPrecision (PREC_HI); tft. fillimi(); tft. vendosRotacionin (3); tft. fillScreen(ILI9341_BLACK); // Vizato një kornizë TFT të bardhë. drawRect (0, 0, 320, 240, ILI9341_WHITE); // Printo tekstin tft të "Arduino". vendosKursorin (80, 30); tft. setTextColor(ILI9341_GREEN); tft. vendos Madhësinë e Tekstit(4); tft. print ("Arduino"); // Printo tekstin "Tic Tac Toe" tft. vendosKursorin (30, 100); tft. setTextColor(ILI9341_WHITE); tft. vendos Madhësinë e Tekstit(4); tft. print("Tik-Tak-Gojë"); // Krijo buton të kuq // krijo butona [0]. initButton (& tft, 160, 200, 200, 40, ILI9341_WHITE, ILI9341_RED, ILI9341_WHITE, fillim, 2); butonat [0]. drawButton(); bëj { prit për një trokitje të lehtë (& x, & y); nëse (buttons[0). përmban (x, y)) b = 0; } ndërsa (b > 0); } loop void () { for (unsigned short int i = 0; i < 9; i++) { board [i] = 0; } tft. fillScreen(ILI9341_BLACK); // Vizato një kornizë TFT të bardhë. drawRect (0, 0, 320, 240, ILI9341_WHITE); // Printo tekstin "Tic Tac Toe" tft. vendosKursorin (30, 30); tft. setTextColor(ILI9341_WHITE); tft. vendos Madhësinë e Tekstit(4); tft. print("Tik-taku-gisht"); // Printon "YouTube!" Teksti TFT. vendosKursorin (30, 100); tft. setTextColor(ILI9341_GREEN); tft. vendos Madhësinë e Tekstit(4); tft. print("Kush fillon"); // Krijo buton të kuq // krijo butona [0]. initButton (& tft, 100, 200, 80, 40, ILI9341_WHITE, ILI9341_RED, ILI9341_WHITE, ju, 2); butonat [0]. drawButton(); // krijo butona // x, y, w, h, skicë, mbushje, butona teksti[1]. initButton (& tft, 200, 200, 80, 40, ILI9341_WHITE, ILI9341_RED, ILI9341_WHITE, cpu, 2); butona [1]. drawButton(); b = 1; bëj { prit për një prekje(&x, &y); nëse(buttons[0]. përmban (x, y)) { b = 0; lojtari = 1; tft. fillScreen(ILI9341_BLACK); // Vizato një kornizë TFT të bardhë. drawRect (0, 0, 320, 240, ILI9341_WHITE); tft. vendosKursorin (30, 30); tft. setTextColor(ILI9341_WHITE); tft. vendos Madhësinë e Tekstit(2); tft. print("Në rregull, ju filloni"); delay(2000); } if(buttons[1]. përmban (x, y)) { b = 0; lojtari = 0; tft. fillScreen(ILI9341_BLACK); // Vizato një kornizë TFT të bardhë. drawRect (0, 0, 320, 240, ILI9341_WHITE); tft. vendosKursorin (30, 30); tft. setTextColor(ILI9341_WHITE); tft. vendos Madhësinë e Tekstit(2); tft. print("Në rregull, CPU fillon"); delay(2000); } } while (b > 0); b = 1; lëviz = 1; winner = 0; cursor = 10; tft. fillScreen(ILI9341_BLACK); // Vizato kornizën TFT. drawRect(0, 0, 320, 240, ILI9341_WHITE); // Vizato një vijë vertikale tft. fillRect (80, 15, 5, 205, ILI9341_WHITE); tft. fillRect (150, 15, 5, 205, ILI9341_WHITE); // Vizato një vijë horizontale fillRect(15,80,205,5,ILI9341_WHITE); fillRect(15,150,205,5,ILI9341_WHITE); drawRect(230,10,80,220,ILI9341_WHITE); { do { if(moves%2==1 && player==false || moves%2==0 && player==true) { cursor+=10; setCursor(240,cursor); setTextSize(1); println("Unë vizatoj"); arduinoMove(); checkWinner(); }else { cursor+=10; setCursor(240,cursor); setTextSize(1); println("Lëvizja juaj"); playerMove(); checkWinner(); } delay(1000); moves++; }while (winner==0 && moves<10); waitonetouch(&x,&y); fillScreen(ILI9341_BLACK); //Vizato kornizën drawRect(0,0,320,240,ILI9341_WHITE); //Shtyp Tekstin "Loja Mbaroi" setCursor(50,30); setTextColor(ILI9341_WHITE); setTextSize(4); print("LOJA MBAROI"); if(winner == 0) { //Shtyp "VIZATO!" text setCursor(110,100); setTextColor(ILI9341_YELLOW); setTextSize(4); print("VARATIM"); } if(winner == 1) { //Shtyp "NJERIU FITON!" text setCursor(40,100); setTextColor(ILI9341_BLUE); setTextSize(4); print("FITORE NJERIU"); } if(winner == 2) { //Shtyp "FITORE CPU!" text
setCursor(60,100);
setTextColor(ILI9341_RED);
setTextSize(4);
print("CPU WINS");
}
buttons[0].initButton(&tft, 160,200,200,40,ILI9341_WHITE, ILI9341_RED, ILI9341_WHITE,
again, 2);
buttons[0].drawButton();
do{
waitonetouch(&x,&y);
if (buttons[0].contains(x,y))
b=0;
}while(b>0);
}
}
void playerMove()
{
waitonetouch(&x,&y);
if((x>15 && x<85) && (y>15 && y<85))
{
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();
}
si (( x > 85 && x < 155 ) && ( y > 85 && y < 155 )) // 4
{
si ( tablero [ 4 ] == 0 )
{
tablero [ 4 ] = 1 ;
dibujarX ( 85 , 85 );
}
else error ();
}
if (( x > 155 && x < 225 ) && ( y > 85 && y < 155 )) // 5
{
if ( tablero [ 5 ] == 0 )
{
tablero [ 5 ] = 1 ;
dibujarX ( 155 , 85 );
}
else error ();
}
si (( x > 15 && x < 85 ) && ( y > 155 && y < 225 )) // 6
{
si ( tablero [ 6 ] == 0 )
{
tablero [ 6 ] = 1 ;
dibujarX ( 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();
}
}
void error(){
cursor+=10;
setCursor(240,cursor);
setTextSize(1);
println("Error");
delay(1000);
cursor+=10;
setCursor(240,cursor);
println("Try again.");
playerMove();
}
{
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;
}
de lo contrario, devuelve 7 ;
}
if ( tablero [ 0 ] == x && tablero [ 1 ] == x && tablero [ 2 ] == y ) {
si ( y == 0 ) {
volver 2 ;
}
de lo contrario, devuelve 0 ;
}
if ( tablero [ 5 ] == x && tablero [ 8 ] == x && tablero [ 2 ] == y ) {
si ( y == 0 ) {
volver 2 ;
}
si no, devuelve 8 ;
}
if ( tablero [ 4 ] == x && tablero [ 6 ] == x && tablero [ 2 ] == y ) {
si ( y == 0 ) {
volver 2 ;
}
de lo contrario, devuelve 6 ;
}
if ( tablero [ 4 ] == x && tablero [ 5 ] == x && tablero [ 3 ] == y ) {
si ( y == 0 ) {
volver 3 ;
}
si no, devuelve 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(board[2]==x && board[8]==x && board[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(board[6]==x && board[8]==x && board[7]==y){
if(y==0){
return 7;
}
else return 6;
}
if(board[6]==x && board[7]==x && board[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);
unsigned short int c=firstMoves[randomMove];
if(board[c]==0){
board[c]=2;
drawCpuMove(firstMoves[randomMove]);
return;
}
}while(moves<2);
}
if(moves<3)
{
if(board[4]==0)
{
board[4]=2;
drawCpuMove(4);
return;
}
}
unsigned short int twoPlayer = checkOpponent(2,0);
if(twoPlayer < 9)
{
board[twoPlayer]=2;
drawCpuMove(twoPlayer);
return;
}
unsigned short int nextMove = checkOpponent(1,0);
if(nextMove < 9)
{
board[nextMove]=2;
drawCpuMove(nextMove);
return;
}
unsigned short int next = checkOpponent(0,2);
if(next < 9)
{
board[next]=2;
drawCpuMove(next);
return;
}
do
{
unsigned short int randomMove =random(9);
if (board[randomMove]==0)
{
board[randomMove]=2;
drawCpuMove(randomMove);
return;
}
}while(nextMove == 100);
}
{
drawBitmap(x,y,circle,65,65,ILI9341_RED);
}
{
drawBitmap(x,y,x_bitmap,65,65,ILI9341_BLUE);
}
{
switch(move)
{
case 0: drawCircle(15,15); break;
case 1: drawCircle(85,15); break;
case 2: drawCircle(155,15); break;
case 3: drawCircle(15,85); break;
case 4: drawCircle(85,85); break;
case 5: drawCircle(155,85); break;
case 6: drawCircle(15,155); break;
case 7: drawCircle(85,155);break;
case 8: drawCircle(155,155);break;
}
}
void checkWinner()
{
// noughts win?
nëse (board[0]>0 && board[1]==board[0] && board[2]==board[0]) { fitues=board[0]; fillRect(15, 45, 205, 5, ILI9341_WHITE); } nëse (board[3]>0 && board[4]==board[3] && board[5]==board[3]) { fitues=board[3]; fillRect(15, 115, 205, 5, ILI9341_WHITE); } nëse (board[6] > 0 && board[7] == board[6] && board[8] == board[6]) { fitues = board[6]; tft. fillRect(15, 185, 205, 5, ILI9341_WHITE); } nëse (board[0] > 0 && board[3] == board[0] && board[6] == board[0]) { fituesi = board[0]; tft. fillRect(45, 15, 5, 205, ILI9341_WHITE); } nëse (board[1] > 0 && board[4] == board[1] && board[7] == board[1]) { fituesi = board[1]; tft. fillRect (115, 15, 5, 205, ILI9341_WHITE); } nëse (board[2]>0 && board[5]==board[2] && board[8]==board[2]) { fitues=board[2]; fillRect(185, 15, 5, 205, ILI9341_WHITE); } nëse (board[0]>0 && board[4]==board[0] && board[8]==board[0]) { fitues=board[0]; për(int short unsigned xx=0;xx<6;xx++){ drawLine(20+xx, 20, 210+xx, 210, ILI9341_WHITE); } } nëse (board[2]>0 && board[4]==board[2] && board[6]==board[2]) { fitues=board[2]; për(unsigned short int xx=0;xx<6;xx++){ drawLine(210+xx, 20, 20+xx, 210, ILI9341_WHITE); } } } void waitonetouch(unsigned short int *x,unsigned short int *y){ do { delay(10); nëse (myTouch. të dhëna të disponueshme () == e vërtetë) { myTouch. lexo(); x = myTouch. getX(); y = myTouch. getY(); return; } } ndërsa (Prekja ime). dataAvailable () == false ); }
















