Industriële fabricage
Industrieel internet der dingen | Industriële materialen | Onderhoud en reparatie van apparatuur | Industriële programmering |
home  MfgRobots >> Industriële fabricage >  >> Manufacturing Technology >> Productieproces

Arduino Touch Breakout-spel

Componenten en benodigdheden

Arduino UNO
× 1
AZ-Delivery 2.4 TFT LCD-aanraakscherm Arduino Shield
× 1

Apps en online services

Arduino IDE

Over dit project

Dit is een kleine versie van de klassieke breakout-videogame voor Arduino UNO en TFT LCD-scherm (240x320 pixels), driver ILI9341 met 8-bits parallelle communicatie.

Het spel

Deze Breakout heeft meerdere schermen met verschillende configureerbare rijen en kolommen met stenen, tot acht rijen, met elke twee rijen een andere kleur, die aan of uit kunnen worden geprogrammeerd met verschillende patronen. Met behulp van een enkele bal, met behulp van het aanraakpaneel, moet de speler zoveel mogelijk stenen omverwerpen door de muren en/of de peddel eronder te gebruiken om de bal tegen de stenen te laten afketsen en ze te elimineren. Als de peddel van de speler de rebound van de bal mist, verliest hij een beurt.

Elke rij stenen levert elk verschillende punten op.

uint8_t pointsForRow[] ={7, 7, 5, 5, 3, 3 , 1, 1}; 

Elk niveau kan de peddelgrootte en de balgrootte configureren. De balsnelheid neemt toe bij elke slag, u kunt de beginsnelheid voor elk scherm configureren. Afhankelijk van het punt van de peddel die de bal raakt, verandert ook de horizontale snelheid

U kunt nieuwe schermen met verschillende wandpatronen definiëren:

Hoe te spelen

Houd het apparaat met uw handen vast en gebruik uw duimvingers over het scherm om de paddle naar links of naar rechts te bewegen.

Definieer een nieuw scherm

Deze structuur wordt gebruikt om een ​​nieuw scherm te definiëren:

typedef struct game_type {
int ballsize;
int playerwidth;
int playerheight;
int exponent;
int top;
int rijen;
int kolommen;
int brickGap;
int levens;
int muur[GAMES_NUMBER];
int initVelx;
int initVely;
} game_type;

en voeg het nieuwe scherm toe aan de set:

game_type games[GAMES_NUMBER] =
// ballsize, playerwidth, playerheight, exponent, top, rows, columns, brickGap, lives, wall[8], initVelx, initVely
{
{ 10, 60, 8, 6, 40, 8, 8, 3, 3, {0x18, 0x66, 0xFF, 0xDB, 0xFF, 0x7E, 0x24, 0x3C}, 28, -28},

Muurpatroon

Wandpatroon wordt gedefinieerd als 8x8 bit array

ej.

{0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA} 

die overeenkomt met deze bit-array

1,0,1,0,1,0,1,0
1,0,1,0,1,0,1,0
1,0,1, 0,1,0,1,0
1,0,1,0,1,0,1,0
1,0,1,0,1,0,1,0
1,0,1,0,1,0,1,0
1,0,1,0,1,0,1,0
1,0,1,0,1,0 ,1,0

Zal deze muur produceren, merk op dat deze gespiegeld is:

Hardware

Dit project maakt gebruik van een AZ-Delivery 2,4 inch TFT LCD-scherm met resistief 4-draads touchscreen en een geïntegreerde SD-kaartlezer. AZ-Delivery 2,4 inch TFT LCD-scherm.

Meer over dit schild in mijn artikel "Op de weg testen van een AZ-Delivery 2, 4 TFT LCD-aanraakscherm"

Het schild monteren

U hoeft alleen het schild over de Aduino aan te sluiten.

Bibliotheken

#include  // Grafische kernbibliotheek
#include
#include

Het aanraakscherm kalibreren

U moet het display kalibreren zodat de positie-informatie correct is wanneer u het display aanraakt. De bibliotheek MCUFriend_kbv biedt een voorbeeld met de naam "TouchScreen_Calibr_native". Het voorbeeld stuurt de resultaten naar de seriële poort. Start de seriële monitor van de Arduino IDE zodat u de code kunt kopiëren die door het voorbeeld is gegenereerd.

Volg de instructies op het aanraakscherm, houd de weergegeven positiemarkeringen ingedrukt, die wit gemarkeerd zijn. Nadat u alle positiemarkeringen hebt uitgevoerd, wordt de kalibratie van het display naar u uitgevoerd op het aanraakscherm en via de seriële poort.

Voor dit project heb je de gegevens nodig voor de "portretkalibratie".

TouchScreen.h GFX-kalibratie
Alle besturings- en buspinnen maken INPUT_PULLUP
Typische 30k analoge pullup met bijbehorende pin
zou laag zijn als digitaal wordt geschreven LOW
bijv. leest ~25 voor 300R X-richting
bijv. leest ~30 voor 500R Y-richting
Testen:(A2, D8) =26
Testen:(A3, D9) =28
ID =0x9341
cx=153 cy=103 cz=534 X, Y, Druk
cx=150 cy=475 cz=406 X, Y, Druk
cx=155 cy=868 cz=231 X, Y, Druk
cx=517 cy=103 cz=561 X, Y, Druk
cx=535 cy=855 cz=364 X, Y, Druk
cx=884 cy=88 cz=650 X, Y, Druk
cx=908 cy=478 cz=557 X, Y, Druk
cx=902 cy=864 cz=488 X, Y, Druk
*** KOPIE-PASTE van seriële terminal:
const int XP=8,XM=A2,YP=A3,YM=9; //240x320 ID=0x9341
const int TS_LEFT=118,TS_RT=931,TS_TOP=72,TS_BOT=887;
PORTRET KALIBRATIE 240 x 320
x =map(px, LEFT=118 , RT=931, 0, 240)
y =kaart(py, TOP=72, BOT=887, 0, 320)
LANDSCHAP KALIBRATIE 320 x 240
x =kaart(py, LEFT=72, RT=887, 0, 320)
y =map(px, TOP=931, BOT=118, 0, 240)

Animatie

Om de afbeelding in de loop van de tijd over het scherm te verplaatsen, gebruikt u een statische snelheid en past u deze elke tijdstap toe op de positie van een afbeelding.

pos +=vel * dt;

Zwevende-kommaberekeningen vermijden

De ILI9341-resolutie is 240 x 320, dus we hebben twee 9-bits gehele getallen nodig om naar een pixel op het scherm te verwijzen. Als we 16-bits gehele getallen gebruiken, zijn we 6 bits vrij om een ​​decimaal deel weer te geven.

nnnn nnnn nndd dddd

We noemen dit getal, 6, de binaire exponent. En we kunnen deze zes bits gebruiken om een ​​decimaal deel te krijgen van 0,000 tot 0,63. We kunnen dus wiskunde met gehele getallen gebruiken om drijvende-kommaberekeningen te vermijden.

Om het gehele deel van het getal te krijgen, maken we een rekenkundige verschuiving naar rechts.

getal>> exponent

state.ballx +=state.velx;
state.bally +=state.vely;

// check balbotsingen en sluit af
checkBallCollisions(game , &state, staat.ballx>> spel->exponent, staat.bally>> spel->exponent);
checkBallExit(game, &state, staat.ballx>> spel->exponent, staat.bally>> spel ->exponent);

Demomodus

Maak een commentaar op de Define-richtlijn en de peddel zal de bal volgen zoals te zien is in de demo-video's:

#define DEMO_MODE 

Geniet ervan!

Maak nieuwe patronen en niveaus en deel ze!

Code

  • Arduino-uitbraak
Arduino BreakoutArduino
/* Arduino Touch TFT Breakout Klassiek breakout-spel Benodigde onderdelen:Ardunio UNO AZ-Delivery 2.4 TFT LCD-touchscreen Arduino Shield of compatibel Deze voorbeeldcode is in het publieke domein. Gewijzigd 07 11 2020 Door Enrique Albertos*/// #define DEMO_MODE#include  // Core graphics library#include #include #define BLACK 0x0000#define BLUE 0x001F#define ROOD 0xF800#define GREEN 0x07E0#define CYAAN 0x07FF#define MAGENTA 0xF81F#define GEEL 0xFFE0#define WHITE 0xFFFF#define PRIMARY_COLOR 0x4A11#define PRIMARY_LIGHT_COLOR 0x7A17#define_ PRIMARY_DAF. #define LCD_CD A2 // Commando/Data gaat naar Analoog 2#define LCD_WR A1 // LCD Write gaat naar Analoog 1#define LCD_RD A0 // LCD Read gaat naar Analoog 0#define LCD_RESET A4 // Kan afwisselend gewoon verbinding maken met Arduino's reset pinAdafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);#define LOWFLASH (defined(__AVR_ATmega328P__) &&defined(MCUFRIEND_KBV_H_))// Drempelwaarde aanraakschermdruk#define MINPRESSURE 40#define MINPRESSURE 40#define MAXPRESSURE XPconst 1000/define MAXPRESSURE XPconst 1000/define 8, XM =A2, YP =A3, YM =9; //240x320 ID=0x9341const int16_t TS_LEFT =122, TS_RT =929, TS_TOP =77, TS_BOT =884;const TouchScreen ts =TouchScreen(XP, YP, XM, YM, 300);#define SCORE_SIZE 30char score[] ="%Format [] 04d";typedef struct gameSize_type {int16_t x, y, width, height;} gameSize_type;gameSize_type gameSize;uint16_t backgroundColor =BLACK;int level;const uint8_t BIT_MASK[] ={0x01, 0x02, 0x04, 0x 0x20, 0x10x , 0x80};uint8_t pointsForRow[] ={7, 7, 5, 5, 3, 3 , 1, 1};#define GAMES_NUMBER 16typedef struct game_type { int ballsize; int spelerbreedte; int spelerhoogte; int exponent; int boven; int-rijen; int kolommen; int baksteenGap; int leeft; int muur [GAMES_NUMBER]; int initVelx; int initVely;} game_type;game_type games[GAMES_NUMBER] =// ballsize, playerwidth, playerheight, exponent, top, rows, columns, brickGap, lives, wall[8], initVelx, initVely{ { 10, 60, 8, 6, 40 , 8, 8, 3, 3, {0x18, 0x66, 0xFF, 0xDB, 0xFF, 0x7E, 0x24, 0x3C} , 28, -28}, { 10, 50, 8, 6, 40, 8, 8, 3 , 3, {0xFF, 0x99, 0xFF, 0xE7, 0xBD, 0xDB, 0xE7, 0xFF} , 28, -28}, { 10, 50, 8, 6, 40 , 8, 8, 3, 3, {0xAA, 0x55 , 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55} , 28, -28}, { 8, 50, 8, 6, 40 , 8, 8, 3, 3, {0xFF, 0xC3, 0xC3, 0xC3, 0xC3, 0xC3, 0xC3, 0xFF} , 34, -34}, { 10, 40, 8, 6, 40 , 8, 8, 3, 3, {0xFF, 0xAA, 0xAA, 0xFF, 0xFF, 0xAA, 0xAA, 0xFF} , 28, -28}, { 10, 40, 8, 6, 40, 8, 8, 3, 3, {0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA} , 28, -28}, { 12, 64, 8, 6, 60, 4, 2, 3, 4, {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF} , 20, -20}, { 12, 60, 8, 6 , 60 , 5, 3, 3, 4, {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF} , 22, -22}, { 10, 56, 8, 6, 30 , 6, 4, 3, 4, {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF} , 24, -24}, { 10, 52, 8, 6, 30, 7, 5, 3, 4, {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF} , 26, -26 }, { 8, 48, 8, 6, 30, 8, 6, 3, 3, {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF} , 28, -28}, { 8, 44, 8, 6, 30, 8, 7, 3, 3, {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF} , 30, -30}, { 8, 40, 8, 6, 30, 8 , 8, 3, 3, {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF} , 32, -32}, { 8, 36, 8, 6, 40 , 8, 8, 3, 3, {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF} , 34, -34}, { 8, 36, 8, 6, 40, 8, 8, 3, 3, {0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA} , 34, -34}};game_type* game;typedef struct game_state_type { uint16_t ballx; uint16_t bally; uint16_t ballxold; uint16_t ballyold; int velx; int sterk; int spelerx; int spelerxold; int wallState[8]; int-score; int resterendeLives; int boven; int bodem; int wandblad; int muurbodem; int steenhoogte; int brickwidth;};game_state_type state;////////////////////////////////////////// ////////////////////// ARDUINO-INSTELLING////////////////////////// ////////////////////////////////////void setup(){ initTft(tft); gameSize ={0, 0, tft.width(), tft.height()}; newGame(&games[0], &state, tft);}///////////////////////////////////// /////////////////////////// ARDUINO LOOP///////////////////// /////////////////////////////////////////int selectie =-1;void loop( void){ selection =readUiSelection(game, &state, selection); drawPlayer(spel, &staat); // bewaar oude positie om oude pixels te verwijderen state.playerxold =state.playerx; // bereken nieuwe balpositie x1 =x0 + vx * dt // controleer max. snelheid if (abs( state.vely)> ((1 <exponent) - 1)) { state.vely =((1 <exponent) - 1) * ((state.vely> 0) - (state.vely <0)); } if (abs( staat.velx)> ((1 <exponent) - 1)) { staat.velx =((1 <exponent) - 1) * ((staat.velx> 0 ) - (staat.velx <0)); } staat.ballx +=staat.velx; staat.bally +=staat.vely; // controleer balbotsingen en verlaat checkBallCollisions(game, &state, state.ballx>> game->exponent, state.bally>> game->exponent); checkBallExit(spel, &staat, staat.ballx>> spel->exponent, staat.bally>> spel->exponent); // teken bal in nieuwe positie drawBall(state.ballx>> spel->exponent, staat.bally>> spel->exponent, staat.ballxold>> spel->exponent, staat.ballyold>> spel->exponent, spel -> balgrootte); // bewaar oude positie om oude pixels te verwijderen state.ballxold =state.ballx; staat.ballyold =staat.bally; // snelheidstoename state.velx =(20 + (state.score>> 3 )) * ( (state.velx> 0) - (state.velx <0)); state.vely =(20 + (state.score>> 3 )) * ( (state.vely> 0) - (state.vely <0)); // als er geen stenen naar het volgende niveau gaan if (noBricks(game, &state) &&level levens, staat->remainingLives); updateScore(staat->score); setupWall (spel, staat); touchToStart(); clearDialog (spelgrootte); updateLives(game->levens, staat->remainingLives); updateScore(staat->score); setupWall(game, staat);}void setupStateSizes(game_type* game, game_state_type * state, Adafruit_TFTLCD &tft) { state->bottom =tft.height() - 30; state->brickwidth =tft.width() / game->kolommen; state->brickheight =tft.height() / 24;}void setupState(game_type* game, game_state_type * state, Adafruit_TFTLCD &tft) { setupStateSizes(game, staat, tft); for (int i =0; i rows; i ++) { state->wallState[i] =0; } state->playerx =tft.width() / 2 - game->playerwidth / 2; state->remainingLives =game->levens; state->bally =state->bottom <exponent; state->ballyold =state->bottom <exponent; state->velx =spel->initVelx; state->vely =game->initVely;}void updateLives(int lives, int leftLives) { for (int i =0; i walltop =game->top + 40; state->wallbottom =state->walltop + game->rows * state->brickheight; for (int i =0; i rijen; i++) { for (int j =0; j kolommen; j++) { if (isBrickIn(game->wall, j, i)) { setBrick (state->wallState, j, i); drawBrick (staat, j, i, kleuren [i]); } } }} ongeldig drawBrick(game_state_type * state, int xBrick, int yBrickRow, uint16_t backgroundColor) { tft.fillRect((state->brickwidth * xBrick) + game->brickGap, state->walltop + (state->brickheight * yBrickRow) + game->brickGap , state->brickwidth - game->brickGap * 2, state->brickheight - game->brickGap * 2, backgroundColor);}boolean noBricks(game_type * game, game_state_type * state) { for ( int i =0; i rows; i++) { if (state->wallState[i]) return false; } return true;} ongeldig drawPlayer(game_type * game, game_state_type * state) { // paint tft.fillRect(state->playerx, state->bottom, game->playerwidth, game->playerheight, GEEL); if (state->playerx !=state->playerxold) { // verwijder oude pixels if (state->playerx playerxold) { tft.fillRect(state->playerx + game->playerwidth, state->bottom , abs(status->playerx - status->playerxold), game->spelerhoogte, backgroundColor); } else { tft.fillRect(state->playerxold, state->bottom, abs(state->playerx - state->playerxold), game->playerheight, backgroundColor); } }} ongeldig drawBall (int x, int y, int xold, int yold, int ballsize) { // verwijder oude pixels // if (xold !=x &&yold !=y) { if (xold <=x &&yold <=y) { tft.fillRect(xold, yold, ballsize, y - yold, BLACK); tft.fillRect(xold, yold, x - xold, ballsize, ZWART); } else if (xold>=x &&yold>=y) { tft.fillRect(x + ballsize , yold, xold - x, ballsize, BLACK); tft.fillRect(xold , y + ballsize, ballsize, yold - y, BLACK); } else if (xold <=x &&yold>=y) { tft.fillRect(xold , yold, x - xold, ballsize, BLACK); tft.fillRect(xold , y + ballsize, ballsize, yold - y, BLACK); } else if (xold>=x &&yold <=y) { tft.fillRect(xold , yold, ballsize, y - yold, BLACK); tft.fillRect(x + ballsize, yold, xold - x, ballsize, ZWART); } // verf nieuwe bal tft.fillRect (x , y, ballsize, ballsize, GEEL); // }} ongeldig touchToStart () { drawBoxedString (0, 200, " BREAKOUT", 3, GEEL, ZWART); drawBoxedString (0, 240, "TOUCH TO START", 2, ROOD, ZWART); while (waitForTouch() <0) {}}void gameOverTouchToStart() { drawBoxedString(0, 180, "GAME OVER", 3, GEEL, ZWART); drawBoxedString (0, 220, "TOUCH TO START", 2, ROOD, ZWART); while (waitForTouch() <0) {}}void updateScore (int score) { char buffer [5]; snprintf(buffer, sizeof(buffer), scoreFormaat, score); drawBoxedString(tft.width() - 50, 6, buffer, 2, YELLOW, PRIMARY_DARK_COLOR);}void checkBrickCollision(game_type* game, game_state_type * state, uint16_t x, uint16_t y) {int x1 =x + game->ballsize; int y1 =y + spel-> balgrootte; int botsingen =0; botsingen +=checkCornerCollision(spel, staat, x, y); botsingen +=checkCornerCollision(spel, staat, x1, y1); botsingen +=checkCornerCollision(spel, staat, x, y1); botsingen +=checkCornerCollision(spel, staat, x1, y); if (botsingen> 0 ) { state->vely =(-1 * state->vely); if ((((x % staat->brickwidth) ==0) &&( state->velx <0 )) || (((((x + game->ballsize) % state->brickwidth) ==0) &&( staat->velx> 0 ))) { staat->velx =(-1 * staat->velx); } }}int checkCornerCollision(game_type * game, game_state_type * state, uint16_t x, uint16_t y) { if ((y> state->walltop) &&(y wallbottom)) {int yBrickRow =( y - state->walltop) / staat->baksteenhoogte; int xBrickColumn =(x / staat-> baksteenbreedte); if (isBrickIn(state->wallState, xBrickColumn, yBrickRow) ) { hitBrick(state, xBrickColumn, yBrickRow); retour 1; } } return 0;} ongeldig hitBrick (game_state_type * state, int xBrick, int yBrickRow) { state->score +=pointsForRow[yBrickRow]; drawBrick(staat, xBrick, yBrickRij, WIT); vertraging (16); drawBrick (staat, xBrick, yBrickRow, BLAUW); vertraging(8); drawBrick (staat, xBrick, yBrickRow, backgroundColor); unsetBrick(state->wallState, xBrick, yBrickRow); updateScore(staat->score);}void checkBorderCollision(game_type * game, game_state_type * state, uint16_t x, uint16_t y) { // check muurbotsing if (x + game->ballsize>=tft.width()) { state ->velx =-abs(staat->velx); } if (x <=0 ) { staat->velx =abs(staat->velx); } if (y <=SCORE_SIZE) { state->vely =abs(state->vely); } if (((y + spel->balmaat)>=staat->onder) &&((y + spel->balmaat) <=(staat->onder + spel->spelerhoogte)) &&(x>=staat->playerx) &&(x <=(state->playerx + game->playerwidth))) { // verander vel x bij spelersgrenzen if (x> (state->playerx + game->playerwidth - 6)) { state ->velx =staat->velx - 1; } else if (x playerx + 6) { state->velx =state->velx + 1; } state->vely =-abs(state->vely); }} ongeldig checkBallCollisions(game_type * game, game_state_type * state, uint16_t x, uint16_t y) { checkBrickCollision(game, state, x, y); checkBorderCollision(game, state, x, y);}void checkBallExit(game_type * game, game_state_type * state, uint16_t x, uint16_t y) { if (((y + game->ballsize)>=tft.height())) { staat->remainingLives--; updateLives(game->levens, staat->remainingLives); vertraging (500); state->vely =-abs(state->vely); }}void setBrick(int wall[], uint8_t x, uint8_t y) { wall[y] =wall[y] | BIT_MASK[x];}void unsetBrick(int wall[], uint8_t x, uint8_t y) { wall[y] =wall[y] &~BIT_MASK[x];}boolean isBrickIn(int wall[], uint8_t x, uint8_t y) { retourmuur[y] &BIT_MASK[x];}/////////////////////////////////// ///////////////////////////// TFT-INSTELLING/////////////////// ///////////////////////////////////////////void initTft(Adafruit_TFTLCD &tft) { tft.reset(); uint16_t ID =tft.readID(); tft.begin(ID); tft.setRotation(0);}////////////////////////////////////////// ////////////////////// Methoden voor het schilderen van schermen///////////////////////// //////////////////////////////////////** Druk een tekst in voorkleur af over een gevuld vak met Achtergrond kleur. De rechthoekgrootte wordt berekend om de hele tekst zonder marges op te nemen @param x horizontale coördinaat in punten linkerbovenhoek @param y verticale coördinaat in punten linkerbovenhoek @param lettergrootte lettergrootte van de af te drukken tekst @param foreColor voorkleur van de af te drukken tekst @param backgroundColor kleur van de gevulde rect @return void*/void drawBoxedString(const uint16_t x, const uint16_t y, const char* string, const uint16_t fontsize, const uint16_t foreColor, const uint16_t backgroundColor) { tft.setTextSize(fontsize); int16_t x1, y1; uint16_t w, h; tft.getTextBounds(string, x, y, &x1, &y1, &w, &h); tft.fillRect(x, y, w, h, backgroundColor); tft.setCursor(x, y); tft.setTextColor(voorkleur); tft.print(string);}/** Wis het scherm naar de standaardachtergronden @param void @return void*/void clearDialog(gameSize_type gameSize) { tft.fillRect(gameSize.x, gameSize.y, gameSize.width, gameSize .hoogte, achtergrondkleur); tft.fillRect(gameSize.x, gameSize.y, gameSize.width, SCORE_SIZE, PRIMARY_DARK_COLOR);}//////////////////////////// //////////////////////////////////// LEES UI SELECTIE/////////// ////////////////////////////////////////////////// //* Controleert of de gebruiker een van de zichtbare ingeschakelde ui-elementen selecteert. De onTap-callback van het geselecteerde element wordt aangeroepen en ingesteld als ingedrukt @param lastSelected the last selection @return the new selection*/int readUiSelection(game_type * game, game_state_type * state, const int16_t lastSelected) { int16_t xpos, ypos; // schermcoördinaten TSPoint tp =ts.getPoint(); //tp.x, tp.y zijn ADC-waarden // als je pinnen deelt, moet je de richting van de touchscreen-pinnen aanpassen pinMode(XM, OUTPUT); pinMode (YP, UITGANG); // we hebben een minimale druk die we als 'geldig' beschouwen // druk van 0 betekent niet drukken! if (tp.z> MINDRUK &&tp.z  tft.width() / 2) { state->playerx +=2; } else { state->playerx -=2; } if (state->playerx>=tft.width() - game->playerwidth) state->playerx =tft.width() - game->playerwidth; if (state->playerx <0) state->playerx =0; retour 1; }#ifdef DEMO_MODE state->playerx =(state->ballx>> game->exponent) - game->spelerbreedte / 2; if (state->playerx>=tft.width() - game->playerwidth) state->playerx =tft.width() - game->playerwidth; if (state->playerx <0) state->playerx =0;#endif return -1;}int waitForTouch() { int16_t xpos, ypos; // schermcoördinaten TSPoint tp =ts.getPoint(); //tp.x, tp.y zijn ADC-waarden // als je pinnen deelt, moet je de richting van de touchscreen-pinnen aanpassen pinMode(XM, OUTPUT); pinMode (YP, UITGANG); // we hebben een minimale druk die we als 'geldig' beschouwen // druk van 0 betekent niet drukken! if (tp.z> MINDRUK &&tp.z   

Schema's


Productieproces

  1. Arduino-gyroscoopspel met MPU-6050
  2. Arduino Pong Game - OLED-scherm
  3. Draagbare capacitieve aanraakpiano
  4. Arduino-gamecontroller
  5. Arduino Pong Game op 24x16 Matrix met MAX7219
  6. Giant Animatronics Lego Minfig Operation Game
  7. USB-BLE draadloze MIDI-adapters
  8. Pixel Chaser-game
  9. Spraakherkenning en synthese met Arduino
  10. Geautomatiseerd Dino-spel met arduino
  11. Touch Controlled Light met Arduino