Cov txheej txheem:

Arduino TFT Interfacing Basics: 10 Kauj Ruam (nrog Duab)
Arduino TFT Interfacing Basics: 10 Kauj Ruam (nrog Duab)

Video: Arduino TFT Interfacing Basics: 10 Kauj Ruam (nrog Duab)

Video: Arduino TFT Interfacing Basics: 10 Kauj Ruam (nrog Duab)
Video: Arduino TFT LCD Touch Screen Tutorial 2024, Kaum ib hlis
Anonim
Arduino TFT Interfacing Basics
Arduino TFT Interfacing Basics

TFT touchscreens yog qhov ua tau zoo siv tau uas tuaj yeem siv nrog microcontrollers xws li Atmel, PIC, STM, vim nws muaj ntau yam xim sib txawv, thiab muaj peev xwm ua tau zoo thiab daim duab qhia tau zoo.

Hnub no, peb tab tom mus rau Interface 2.4 nti TFT LCD Shield nrog Arduino.

Cov ntaub thaiv npog no yog rau Arduino UNO, tab sis kuv yuav qhia siv nws li cas nrog Arduino Mega rau qhov laj thawj zoo, "Program Memory".

Los ntawm kev siv cov xim TFT LCD tiv thaiv no peb tuaj yeem qhia cov cim, cov hlua, khawm cuam tshuam, cov duab bitmap, thiab lwm yam ntawm cov xim TFT LCD.

Kauj ruam 1: Kho vajtse thiab Software yuav tsum tau

Kho vajtse thiab Software yuav tsum tau
Kho vajtse thiab Software yuav tsum tau
Kho vajtse thiab Software yuav tsum tau
Kho vajtse thiab Software yuav tsum tau

Txhawm rau ua cov ntaub thaiv npog nrog Arduino mega, peb xav tau cov hauv qab no.

HARDWARE:

• Arduino mega

• TFT 2.4/2.8/3.2 nti LCD

• USB Cable

SOFTWARE

• Arduino IDE

• UTFT Library / spfd5408 Library

Cov ntaub thaiv npog yog xub tsim rau Arduino UNO cov laug cam, uas tuaj yeem siv nrog Arduino mega.

Muaj ob qhov teeb meem tseem ceeb thaum siv nws nrog Arduino UNO: "Cia nco" thiab siv tus pin.

Nws nyuaj rau siv tus pin tsis siv uas muaj nyob ntawm UNO, qhov uas nws zoo dua nrog Arduino MEGA vim peb muaj I/O pins ntau dua.

Hauv cov kauj ruam tom ntej, Kuv yuav qhia yuav hloov kho lub tsev qiv ntawv UTFT kom siv daim npog TFT li cas

Kauj ruam 2: Tweaking UTFT Lib

Tweaking UTFT Lib
Tweaking UTFT Lib

Lub tsev qiv ntawv no yog txuas ntxiv ntawm kuv ITDB02_Graph, ITDB02_Graph16 thiab RGB_GLCD cov tsev qiv ntawv rau Arduino thiab chipKit. Raws li tus lej ntawm cov khoom txhawb nqa cov qauv thiab cov tswj tau pib nce Kuv xav tias nws yog lub sijhawm los ua ib leeg, cov tsev qiv ntawv thoob ntiaj teb raws li nws yuav yooj yim dua los tswj hwm yav tom ntej.

Arduino MEGA muaj 256kb ntawm qhov kev pab cuam nco. Ntxiv rau, muaj 54 tus pin.

Feem ntau ntawm lawv tau siv dawb, thiab qhov sib piv tsuas yog 5 tau coj los ntawm 16.

Lub tsev qiv ntawv no txhawb tus lej ntawm 8 ntsis, 16 ntsis, thiab cov duab qhia ntxaws, thiab yuav ua haujlwm nrog ob qho tib si Arduino, chipKit boards thiab xaiv TI LaunchPads.

NCO TSEG: Vim qhov loj ntawm lub tsev qiv ntawv kuv tsis pom zoo siv nws ntawm ATmega328 (Arduino Uno) thiab ATmega32U4 (Arduino Leonardo) vim lawv tsuas muaj 32KB ntawm lub cim xeeb nco. Nws yuav ua haujlwm, tab sis koj yuav raug txwv tsis pub siv flash nco rau koj daim ntawv thov

Cov kauj ruam

  • Rub tawm UTFT Library
  • Unzip lub tsev qiv ntawv
  • Qhib UTFT / kho vajtse / avr thaum Arduino lossis nyob ntawm seb lub microcontroller siv
  • Qhib HW_AVR_defines siv Notepad
  • Tsis Pom Zoo Kab 7 kom pab UNO daim thaiv rau MEGA
  • Txuag cov ntawv thiab Ntxiv Cov Tsev Qiv Ntawv no rau Arduino IDE

Tam sim no peb tau ua tiav nrog cov kauj ruam no! Hauv cov kauj ruam tom ntej, kuv yuav qhia siv lub tsev qiv ntawv thiab txhais cov pins rau Arduino Mega.

Kauj Ruam 3: Pib ua daim TFT Shield

Kev pib ua TFT Shield
Kev pib ua TFT Shield

Tom qab kho lub tsev qiv ntawv, Ntxiv rau Arduino cov npe.

Tom ntej no, Kuv yuav qhia koj yuav txheeb xyuas txoj cai TFT module uas koj muaj

peb yuav tsum pom nws lub npe module hauv lub tsev qiv ntawv.

  • qhib lub tsev qiv ntawv cov ntaub ntawv
  • mus rau cov ntaub ntawv

Koj tuaj yeem pom cov ntaub ntawv no hauv Cov Ntaub Ntawv

• UTFT:

Cov ntaub ntawv no qhia tag nrho cov haujlwm thiab cov lus txib suav nrog hauv lub tsev qiv ntawv no.

• UTFT_Requirement

Cov ntaub ntawv no muaj cov ntaub ntawv hais txog cov qauv thiab nws cuam tshuam nrog lub tsev qiv ntawv li cas, zoo li tus pin teeb tsa

• UTFT_Supported_display_modules _ & _ maub los

Nov yog peb lub hom phiaj, cov ntaub ntawv no muaj cov npe ntawm cov qauv thiab cov ntaub thaiv npog uas tau txais kev txhawb nqa los ntawm lub tsev qiv ntawv no, koj tuaj yeem pom hauv nws cov npe cov npe khoom thiab cov npe qauv rau UTFT uas koj yuav tsum siv los txheeb xyuas koj cov qauv.

Cov kauj ruam los txhais TFT:

Qhib UTFT_Supported_display_modules _ & _ cov ntaub ntawv tswj los ntawm lub tsev qiv ntawv

  • Qhib UTFT_Supported_display_modules _ & _ cov ntaub ntawv tswj los ntawm lub tsev qiv ntawv
  • Nrhiav Cov Qauv rau UTFT rau Cov Qauv (ntaub thaiv npog) uas koj muaj.
  • Tam sim no txhawm rau txheeb xyuas UTFT ua haujlwm ntawm Arduino IDE, peb siv cov lus txib:

UTFT lub npe (module, Rs, Wr, Cs, Rst);

Qhib UTFT_Requirement cov ntaub ntawv los ntawm lub tsev qiv ntawv

Los ntawm daim ntawv, peb paub tias cov pins nyob ntawm A5, A4, A3, thiab A2 pins.

peb siv cov lus txib:

UTFT myGLCD (ITDB28, 19, 18, 17, 16); # nco ntsoov tias pins 19, 18, 17, 16 hauv Arduino Mega

UTFT myGLCD (ITDB28, A5, A4, A3, A2); # ceeb toom tias pins A5, A4, A3, A2 hauv Arduino UNO

Thiab ua tiav! Tam sim no koj tuaj yeem siv cov piv txwv ntawm lub tsev qiv ntawv ntawm Arduino IDE nrog cov kev hloov hauv qab no.

Kauj Ruam 4: Nyob Zoo Hauv Ntiaj Teb

Nyob Zoo Ntiaj Teb
Nyob Zoo Ntiaj Teb

#suav nrog // Tshaj tawm cov fonts twg peb yuav siv

sab nrauv uint8_t BigFont ; sab nrauv uint8_t SevenSegNumFont ; // Nco ntsoov hloov tus qauv ntsuas kom haum rau koj cov qauv zaub! UTFT myGLCD (ITDB28, A5, A4, A3, A2); teeb tsa tsis muaj dabtsis () {myGLCD. InitLCD (); myGLCD.clrScr (); myGLCD.setFont (BigFont); } void loop () {myGLCD.setColor (0, 255, 0); // ntsuab myGLCD.print ("HELLO WORLD", 45, 100); thaum (tseeb) {}; }

Kauj ruam 5: UTFT Fonts

UTFT Fonts Cov
UTFT Fonts Cov

#suav nrog // Tshaj tawm cov fonts twg peb yuav siv

sab nrauv uint8_t SmallFont ; sab nrauv uint8_t BigFont ; sab nrauv uint8_t SevenSegNumFont ; // Teeb tus pin rau qhov raug rau koj daim thaiv thaiv kev txhim kho // ----------------------------------- ------------------------- // Arduino Uno / 2009: // ---------------- --- // Txheem Arduino Uno/2009 daim thaiv:, A5, A4, A3, A2 // DisplayModule Arduino Uno TFT daim thaiv:, A5, A4, A3, A2 // // Arduino Mega: // ----- -------------- // Txheem Arduino Mega/Cov ntaub thaiv npog:, 38, 39, 40, 41 // CTE TFT LCD/SD Shield rau Arduino Mega:, 38, 39, 40, 41 // // Nco ntsoov hloov pauv tus qauv ntsuas kom haum rau koj cov qauv zaub! UTFT myGLCD (ITDB32S, 38, 39, 40, 41); void teeb () {myGLCD. InitLCD () myGLCD.clrScr (); } void loop () {myGLCD.setColor (0, 255, 0); myGLCD.setBackColor (0, 0, 0); myGLCD.setFont (BigFont); myGLCD.print ("! \"#$%& '()*+, -./", CENTER, 0); myGLCD.print (" 0123456789:;? ", CENTER, 16); myGLCD.print ("@ ABCDEFGHIJKLMNO ", CENTER, 32); myGLCD.print (" PQRSTUVWXYZ ^_ ", CENTER, 48); myGLCD.print (" `abcdefghijklmno", CENTER, 64); myGLCD.print ("pqrstuvwxyz {} ~ ", CENTER, 80); myGLCD.setFont (SmallFont); myGLCD.print ("! / "#$%& '()*+, -./0123456789:;?", CENTER, 120); myGLCD.print ("@ABCDEFGHIJKLMNOPQRSTUVWXYZ ^_", CENTER, 132); myGLCD.print ("` abcdefghijklmnopqrstuvwxyz {|} ~ ", CENTER, 144); myGLCD.setFont (SevenSegNumFont); myGLCD.print ("0123456789", CENTER, 190); thaum (1) {}; }

Kauj Ruam 6: UTFT Cov Duab, Kab thiab Qauv

UTFT Cov Duab, Kab thiab Qauv
UTFT Cov Duab, Kab thiab Qauv

#include "UTFT.h" // Tshaj tawm cov fonts uas peb yuav siv sab nraud uint8_t SmallFont ; // Teeb tsa tus pin rau qhov raug rau koj daim thaiv thaiv kev txhim kho // -------------- ---------------------------------------------- // Arduino Uno / 2009: // ------------------- // Txheem Arduino Uno/ 2009 ntaub thaiv npog:, A5, A4, A3, A2 // DisplayModule Arduino Uno TFT ntaub thaiv npog:, A5, A4, A3, A2 // // Arduino Mega: // ------------------- // Txheem Arduino Mega/Cov ntaub thaiv npog:, 38, 39, 40, 41 // CTE TFT LCD/SD Shield rau Arduino Mega:, 38, 39, 40, 41 // // Nco ntsoov hloov cov qauv ntsuas kom haum rau koj cov qauv zaub! UTFT myGLCD (ITDB32S, 38, 39, 40, 41); tsis muaj teeb tsa teeb tsa () {randomSeed (analogRead (0)); // Teeb lub LCD myGLCD. InitLCD (); myGLCD.setFont (SmallFont); }

void lub voj ()

{int ib [318]; ib, x2;. koj y, y2. int r; // Ntshiab qhov screen thiab kos kab duab myGLCD.clrScr (); myGLCD.setColor (255, 0, 0); myGLCD.fillRect (0, 0, 319, 13); myGLCD.setColor (64, 64, 64); myGLCD.fillRect (0, 226, 319, 239); myGLCD.setColor (255, 255, 255); myGLCD.setBackColor (255, 0, 0); myGLCD.print (" * Universal Color TFT Display Library *", CENTER, 1); myGLCD.setBackColor (64, 64, 64); myGLCD.setColor (255, 255, 0); myGLCD.print ("", CENTER, 227); myGLCD.setColor (0, 0, 255); myGLCD.drawRect (0, 14, 319, 225); // Kos crosshairs myGLCD.setColor (0, 0, 255); myGLCD.setBackColor (0, 0, 0); myGLCD.drawLine (159, 15, 159, 224); myGLCD.drawLine (1, 119, 318, 119); rau (int i = 9; i <310; i+= 10) myGLCD.drawLine (i, 117, i, 121); rau (int i = 19; i <220; i+= 10) myGLCD.drawLine (157, i, 161, i); // Kos sin-, cos- thiab tan-kab myGLCD.setColor (0, 255, 255); myGLCD.print ("Kev txhaum", 5, 15); rau (int i = 1; i <318; i ++) {myGLCD.drawPixel (i, 119+ (sin (((i*1.13)*3.14)/180)*95))); } myGLCD.setColor (255, 0, 0); myGLCD.print ("Cos", 5, 27); rau (int i = 1; i <318; i ++) {myGLCD.drawPixel (i, 119+ (cos (((i*1.13)*3.14)/180)*95))); } myGLCD.setColor (255, 255, 0); myGLCD.print ("Tan", 5, 39); rau (int i = 1; i <318; i ++) {myGLCD.drawPixel (i, 119+ (tan (((i*1.13)*3.14)/180)))); } ncua (2000); myGLCD.setColor (0, 0, 0); myGLCD.fillRect (1, 15, 318, 224); myGLCD.setColor (0, 0, 255); myGLCD.setBackColor (0, 0, 0); myGLCD.drawLine (159, 15, 159, 224); myGLCD.drawLine (1, 119, 318, 119); // Kos qhov txav sinewave x = 1; rau (int i = 1; i319) {if ((x == 159) || (buf [x-1] == 119)) myGLCD.setColor (0, 0, 255); lwm tus myGLCD.setColor (0, 0, 0); myGLCD.drawPixel (x, buf [x-1]); } myGLCD.setColor (0, 255, 255); y = 119+(sin (((i*1.1)*3.14) / 180)*(90- (i / 100))); myGLCD.drawPixel (x, y); buf [x-1] = y; } ncua (2000); myGLCD.setColor (0, 0, 0); myGLCD.fillRect (1, 15, 318, 224); // Kos ib co duab plaub uas puv rau (int i = 1; i <6; i ++) {hloov (i) {case 1: myGLCD.setColor (255, 0, 255)); tawg; rooj plaub 2: myGLCD.setColor (255, 0, 0); tawg; rooj plaub 3: myGLCD.setColor (0, 255, 0); tawg; rooj plaub 4: myGLCD.setColor (0, 0, 255); tawg; rooj plaub 5: myGLCD.setColor (255, 255, 0); tawg; } myGLCD.fillRect (70+ (i*20), 30+ (i*20), 130+ (i*20), 90+ (i*20)); } ncua (2000); myGLCD.setColor (0, 0, 0); myGLCD.fillRect (1, 15, 318, 224); // Kos qee qhov ua tiav, cov duab plaub sib npaug rau (int i = 1; i <6; i ++) {hloov (i) {rooj plaub 1: myGLCD.setColor (255, 0, 255); tawg; rooj plaub 2: myGLCD.setColor (255, 0, 0); tawg; rooj plaub 3: myGLCD.setColor (0, 255, 0); tawg; rooj plaub 4: myGLCD.setColor (0, 0, 255); tawg; rooj plaub 5: myGLCD.setColor (255, 255, 0); tawg; } myGLCD.fillRoundRect (190- (i*20), 30+ (i*20), 250- (i*20), 90+ (i*20)); } ncua (2000); myGLCD.setColor (0, 0, 0); myGLCD.fillRect (1, 15, 318, 224); // Kos qee lub voj voos puv rau (int i = 1; i <6; i ++) {hloov (i) {case 1: myGLCD.setColor (255, 0, 255)); tawg; rooj plaub 2: myGLCD.setColor (255, 0, 0); tawg; rooj plaub 3: myGLCD.setColor (0, 255, 0); tawg; rooj plaub 4: myGLCD.setColor (0, 0, 255); tawg; rooj plaub 5: myGLCD.setColor (255, 255, 0); tawg; } myGLCD.fillCircle (100+ (i*20), 60+ (i*20), 30); } ncua (2000); myGLCD.setColor (0, 0, 0); myGLCD.fillRect (1, 15, 318, 224); // Kos qee kab hauv tus qauv myGLCD.setColor (255, 0, 0); rau (int i = 15; i <224; i+= 5) {myGLCD.drawLine (1, i, (i*1.44) -10, 224); } myGLCD.setColor (255, 0, 0); rau (int i = 224; i> 15; i- = 5) {myGLCD.drawLine (318, i, (i*1.44) -11, 15); } myGLCD.setColor (0, 255, 255); rau (int i = 224; i> 15; i- = 5) {myGLCD.drawLine (1, i, 331- (i*1.44), 15); } myGLCD.setColor (0, 255, 255); rau (int i = 15; i <224; i+= 5) {myGLCD.drawLine (318, i, 330- (i*1.44), 224); } ncua (2000); myGLCD.setColor (0, 0, 0); myGLCD.fillRect (1, 15, 318, 224); // Kos qee lub voj voos random rau (int i = 0; i <100; i ++) {myGLCD.setColor (random (255), random (255), random (255)))); x = 32+random (256); y = 45+random (146); r = random (30); myGLCD.drawCircle (x, y, r); } ncua (2000); myGLCD.setColor (0, 0, 0); myGLCD.fillRect (1, 15, 318, 224); // Kos qee qhov duab plaub sib txawv rau (int i = 0; i <100; i ++) {myGLCD.setColor (random (255), random (255), random (255)))); x = 2+random (316); y = 16+random (207); x2 = 2+random (316); y2 = 16+random (207); myGLCD.drawRect (x, y, x2, y2); } ncua (2000); myGLCD.setColor (0, 0, 0); myGLCD.fillRect (1, 15, 318, 224); // Kos ib co duab sib npaug sib npaug rau (int i = 0; i <100; i ++) {myGLCD.setColor (random (255), random (255), random) 255)); x = 2+random (316); y = 16+random (207); x2 = 2+random (316); y2 = 16+random (207); myGLCD.drawRoundRect (x, y, x2, y2); } ncua (2000); myGLCD.setColor (0, 0, 0); myGLCD.fillRect (1, 15, 318, 224); rau (int i = 0; i <100; i ++) {myGLCD.setColor (random (255), random (255), random (255))); x = 2+random (316); y = 16+random (209); x2 = 2+random (316); y2 = 16+random (209); myGLCD.drawLine (x, y, x2, y2); } ncua (2000); myGLCD.setColor (0, 0, 0); myGLCD.fillRect (1, 15, 318, 224); rau (int i = 0; kuv <10000; i ++) {myGLCD.setColor (random (255), random (255), random (255))); myGLCD.drawPixel (2+random (316), 16+random (209)); } ncua (2000); myGLCD.fillScr (0, 0, 255); myGLCD.setColor (255, 0, 0); myGLCD.fillRoundRect (80, 70, 239, 169); myGLCD.setColor (255, 255, 255); myGLCD.setBackColor (255, 0, 0); myGLCD.print ("Yog lawm!", Chaw, 93); myGLCD.print ("Rov pib dua hauv", CENTER, 119); myGLCD.print ("ob peb feeb …", CENTER, 132); myGLCD.setColor (0, 255, 0); myGLCD.setBackColor (0, 0, 255); myGLCD.print ("Runtime: (msecs)", CENTER, 210); myGLCD.printNumI (millis (), CENTER, 225); ncua (10000); }

Kauj Ruam 7: UTFT Bitmap

UTFT Bitmap
UTFT Bitmap

#suav nrog

#include // Tshaj tawm cov fonts twg peb yuav siv sab nrauv uint8_t SmallFont ; // Teeb tsa tus pin rau qhov raug rau koj daim thaiv thaiv kev txhim kho // ------------------ ------------------------------------------ // Arduino Uno / 2009: / / ------------------- // Txheem Arduino Uno/ 2009 daim thaiv:, A5, A4, A3, A2 // DisplayModule Arduino Uno TFT daim thaiv:, A5, A4, A3, A2 // // Arduino Mega: // ------------------- // Txheem Arduino Mega/Cov ntaub thaiv npog:, 38, 39, 40, 41 // CTE TFT LCD/SD Shield rau Arduino Mega:, 38, 39, 40, 41 // // Nco ntsoov hloov tus qauv ntsuas kom haum rau koj cov qauv zaub! UTFT myGLCD (ITDB32S, A5, A4, A3, A2); extern unsigned int info [0x400]; extern unsigned int icon [0x400]; extern unsigned int tux [0x400]; void setup () {myGLCD. InitLCD (); myGLCD.setFont (SmallFont); } void loop () {myGLCD.fillScr (255, 255, 255); myGLCD.setColor (255, 255, 255); myGLCD.print ("*** A 10 los ntawm 7 daim phiaj ntawm 32x32 cim ***", CENTER, 228); rau (int x = 0; x <10; x ++) rau (int y = 0; y <7; y ++) myGLCD.drawBitmap (x*32, y*32, 32, 32, info); ncua (5000); myGLCD.fillScr (255, 255, 255); myGLCD.setColor (255, 255, 255); myGLCD.print ("Ob lub cim sib txawv hauv nplai 1 txog 4", CENTER, 228); int x = 0; rau (int s = 0; s0; s--) {myGLCD.drawBitmap (x, 224- (s*32), 32, 32, icon, s); x+= (s*32); } ncua (5000); }

Kauj Ruam 8: Khawm cuam tshuam

Khawm cuam tshuam
Khawm cuam tshuam

#include #include // Initialize display // ------------------ // Teeb tsa tus pin rau qhov raug rau koj li kev txhim kho pawg thawj coj // ------- ----------------------------------------------------------------------- - // Txheem Arduino Uno/2009 Shield:, 19, 18, 17, 16 // Txheem Arduino Mega/Cov ntaub thaiv npog:, 38, 39, 40, 41 // CTE TFT LCD/SD Shield rau Arduino Due:, 25, 26, 27, 28 // Teensy 3.x TFT Test Board:, 23, 22, 3, 4 // ElecHouse TFT LCD/SD Shield rau Arduino Due:, 22, 23, 31, 33 // // Nco ntsoov hloov cov qauv ntsuas ntsuas kom haum rau koj cov zaub module! UTFT myGLCD (ITDB32S, 38, 39, 40, 41); // Pib lub touchscreen // ---------------------- // Teeb tsa tus pin kom raug ib qho rau koj pawg tswj hwm kev txhim kho // ------------------------------------------- ---------------- // Txheem Arduino Uno/2009 Shield: 15, 10, 14, 9, 8 // Txheem Arduino Mega/Cov ntaub thaiv npog: 6, 5, 4, 3, 2 // CTE TFT LCD/SD Shield rau Arduino Due: 6, 5, 4, 3, 2 // Teensy 3.x TFT Test Board: 26, 31, 27, 28, 29 // ElecHouse TFT LCD/SD Shield rau Arduino Due: 25, 26, 27, 29, 30 // URTouch myTouch (6, 5, 4, 3, 2); // Tshaj tawm cov fonts twg peb yuav siv extern uint8_t BigFont ; int x, y; char stCurrent [20] = ""; int stCurrentLen = 0; char stLast [20] = "";/************************* ** Cov haujlwm tshwj xeeb ** ********* ****************/void drawButtons () {// Kos rau kab sab saud ntawm cov nyees khawm rau (x = 0; x <5; x ++) {myGLCD.setColor (0, 0, 255); myGLCD.fillRoundRect (10+ (x*60), 10, 60+ (x*60), 60); myGLCD.setColor (255, 255, 255); myGLCD.drawRoundRect (10+ (x*60), 10, 60+ (x*60), 60); myGLCD.printNumI (x+1, 27+ (x*60), 27); } // Kos kab kab nruab nrab ntawm cov nyees khawm rau (x = 0; x <5; x ++) {myGLCD.setColor (0, 0, 255); myGLCD.fillRoundRect (10+ (x*60), 70, 60+ (x*60), 120); myGLCD.setColor (255, 255, 255); myGLCD.drawRoundRect (10+ (x*60), 70, 60+ (x*60), 120); yog (x <4) myGLCD.printNumI (x+6, 27+ (x*60), 87); } myGLCD.print ("0", 267, 87); // Kos kab qis ntawm cov nyees khawm myGLCD.setColor (0, 0, 255); myGLCD.fillRoundRect (10, 130, 150, 180); myGLCD.setColor (255, 255, 255); myGLCD.drawRoundRect (10, 130, 150, 180); myGLCD.print ("Clear", 40, 147); myGLCD.setColor (0, 0, 255); myGLCD.fillRoundRect (160, 130, 300, 180); myGLCD.setColor (255, 255, 255); myGLCD.drawRoundRect (160, 130, 300, 180); myGLCD.print ("Nkag mus", 190, 147); myGLCD.setBackColor (0, 0, 0); } void updateStr (int val) {if (stCurrentLen = 10) && (y = 10) && (x = 70) && (x = 130) && (x = 190) && (x = 250) && (x = 70) && (y = 10) && (x = 70) && (x = 130) && (x = 190) && (x = 250) && (x = 130) && (y = 10) && (x = 160) && (x0) (rau (x = 0; x

Kauj Ruam 9: Flappy Bird

Flappy noog
Flappy noog

#include #include #include // ==== Tsim Lub Hom Phiaj UTFT myGLCD (SSD1289, 38, 39, 40, 41); // Cov ntsuas yuav tsum tau hloov kho rau koj Cov Zaub/Schield qauv UTouch myTouch (6, 5, 4, 3, 2); // ==== Txhais Fonts extern uint8_t SmallFont ; sab nrauv uint8_t BigFont ; extern uint8_t SevenSegNumFont ; sab nrauv tsis kos npe rau int bird01 [0x41A]; // Noog Bitmapint x, y; // Variables for coordinates where the display has been pressed // Floppy Bird int xP = 319; int yP = 100; int yB = 50; int txavRate = 3; int fallRateInt = 0; ntab fallRate = 0; int tau = 0; int lastSpeedUpScore = 0; int siab tshaj plaws; boolean screenPressed = tsis tseeb; boolean gameStarted = tsis tseeb; tsis muaj teeb meem teeb tsa () {// Pib tso saib myGLCD. InitLCD (); myGLCD.clrScr (); myTouchInitTouch (); myTouch.setPrecision (PREC_MEDIUM); qhab nia siab tshaj = EEPROM.read (0); // Nyeem cov qhab nia siab tshaj los ntawm EEPROM pib game (); // Pib qhov game} void loop () {xP = xP-movingRate; // xP - x kev koom tes ntawm cov pilars; range: 319 - (-51) drawPilars (xP, yP); // Kos tus ncej // yB - y sib koom ntawm cov noog uas nyob ntawm tus nqi ntawm qhov poob qis nce yB+= fallRateInt; fallRate = fallRate+0.4; // Txhua qhov inetration qhov poob qis nce ntxiv kom peb tuaj yeem cuam tshuam qhov nrawm/ nqus lub ntiaj teb fallRateInt = int (fallRate); // Txheeb xyuas kev sib tsoo yog tias (yB> = 180 || yB <= 0) {// gameOver saum thiab hauv qab (); } yog ((xP = 5) && (yB <= yP-2)) {// sab saud gameOver (); } yog ((xP = 5) && (yB> = yP+60)) {// qis dua gameOver (); } // Kos tus noog drawBird (yB); // Tom qab tus ncej tau dhau los ntawm qhov screen yog (xPRESET = 250) && (x = 0) && (y = 0) && (x = 30) && (y = 270) {myGLCD.setColor (0, 200, 20)); myGLCD.fillRect (318, 0, x, y-1); myGLCD.setColor (0, 0, 0); myGLCD.drawRect (319, 0, x-1, y); myGLCD.setColor (0, 200, 20); myGLCD.fillRect (318, y+81, x, 203); myGLCD.setColor (0, 0, 0); myGLCD.drawRect (319, y+80, x-1, 204); } lwm tus yog (x siab tshaj qhov qhab nia) {siab tshaj qhov qhab nias = qhab nia; EEPROM.write (0, qhov qhab nia siab tshaj); } // Pib dua qhov hloov pauv los pib txoj haujlwm qhov tseem ceeb xP = 319; yB = 50; fallRate = 0; tau = 0; lastSpeedUpScore = 0; txavRate = 3; gameStarted = tsis tseeb; // Rov pib ua si pib gameGame (); }

Kauj Ruam 10: Ua Haujlwm ntawm Txoj Haujlwm

Koj tuaj yeem pom qhov chaws nyob hauv kuv Github chaw cia khoom.

Txuas:

Muab tus ntiv tes xoo yog tias nws tau pab koj tiag tiag thiab ua raws kuv li channel rau cov phiaj xwm txaus nyiam:)

Muab daim vis dis aus no yog koj nyiam.

Zoo siab tau koj los koom:

Ua tsaug rau kev nyeem ntawv!

Pom zoo: