Cov txheej txheem:
- Kauj ruam 1: Arduino Mega 2560
- Kauj Ruam 2: TFT LCD Shield 2.4 "
- Kauj ruam 3: Tsev qiv ntawv
- Kauj Ruam 4: Kev Ua Haujlwm
- Kauj Ruam 5: Piv txwv
- Kauj Ruam 6: Cov tsev qiv ntawv
- Kauj ruam 7: Txhais
- Kauj ruam 8: Teeb tsa
- Kauj ruam 9: Loop
- Kauj Ruam 10: Txheeb Yog tias Peb Kov Lub Vajvoog
- Kauj Ruam 11: Kev Ua Haujlwm ntawm Tsim Cov Duab Duab
- Kauj Ruam 12: Txheeb Yog tias Peb Kov Lub Duab Plaub
- Kauj Ruam 13: Txheeb Yog tias Peb Kov Lub Vajvoog
- Kauj Ruam 14: Txheeb Yog Peb Kov Daim Duab Peb Hlis
- Kauj Ruam 15: Muaj nuj nqi Luam Lub Npe Lub Hom Phiaj Touched
- Kauj ruam 16: Cov ntaub ntawv
Video: Arduino Nrog Kov Screen Zaub: 16 Cov Kauj Ruam
2024 Tus sau: John Day | [email protected]. Kawg hloov kho: 2024-01-30 09:29
Koj puas xav tsim ntau cov ntawv tshwj xeeb thiab tib neeg/tshuab cuam tshuam zoo dua? Rau cov haujlwm zoo li no, koj tuaj yeem siv Arduino thiab Touch Screen Display. Lub tswv yim no puas ntxim nyiam? Yog tias yog, tshawb xyuas cov vis dis aus hnub no, qhov twg kuv yuav qhia koj qhov kev sib dhos nrog Mega Arduino thiab Touch Screen Display. Koj yuav pom yuav ua li cas thiaj tsim cov qauv koj xav tau ntawm lub vijtsam, thiab tseem yuav txiav txim siab thaj tsam ntawm lub vijtsam li cas txhawm rau txhawm rau thiab qhib qhov kev hais kom ua tshwj xeeb. Kuv hais meej tias kuv tau xaiv los siv Arduino Mega vim nws cov koob.
Yog li hnub no, Kuv yuav qhia koj li Touch Screen zaub, nws cov duab nraaj, thiab yuav ua li cas thiaj rub tau qhov kov ntawm lub vijtsam. Cia peb tseem tsim qhov piv txwv uas muaj txhua lub ntsiab lus, xws li kev tso chaw, sau ntawv, tsim cov duab, xim, thiab kov.
Kauj ruam 1: Arduino Mega 2560
Kauj Ruam 2: TFT LCD Shield 2.4"
Cov zaub no uas peb siv hauv peb txoj haujlwm muaj qhov ntxim nyiam: nws muaj daim npav SD. Txawm li cas los xij, kev sau thiab nyeem ntawv koom nrog hauv qhov no yuav raug qhia hauv lwm cov vis dis aus, uas kuv yuav tsim tawm sai sai no. Lub hom phiaj ntawm zaj lus qhia niaj hnub no yog txhawm rau hais txog cov duab thiab kov lub ntsej muag ntawm cov zaub no.
Yam ntxwv:
Screen Dimension: 2.4 nti
MicroSD daim npav qhov
Xim LCD: 65K
Tsav tsheb: ILI9325
Daws teeb meem: 240 x 320
Touchscreen: 4-xaim resistive touchscreen
Interface: 8 ntsis cov ntaub ntawv, ntxiv rau 4 kab tswj
Kev khiav hauj lwm muaj zog: 3.3-5V
Medidas: 71 x 52 x 7 mm
Kauj ruam 3: Tsev qiv ntawv
Ntxiv cov tsev qiv ntawv:
"Adafruit_GFX"
"SWTFT"
"Kov npo"
Nyem rau ntawm qhov txuas thiab rub cov tsev qiv ntawv.
Unzip cov ntawv thiab muab tso rau hauv cov ntawv qiv ntawm Arduino IDE.
C: / Program Files (x86) / Arduino / qiv
Nco tseg
Ua ntej peb pib peb txoj haujlwm, peb yuav tsum hais txog qee yam tseem ceeb: TOUCH calibration.
Siv cov phiaj xwm yooj yim kom tau txais cov ntsiab lus kov ntawm cov zaub, khaws tus nqi ntawm cov ntsiab lus (x, y) ntawm txhua qhov kawg (hais txog xim daj hauv daim duab hauv qab no). Cov txiaj ntsig no yog qhov tseem ceeb rau kev kos duab kov mus rau cov duab nraaj ntawm lub vijtsam.
#include // Portas de leitura das coordenadas ua touchvoid #define YP A1 // Y+ yog ntawm Analog1 #define XM A2 // X- yog ntawm Analog2 #define YM 7 // Y- yog ntawm Digital7 #define XP 6 // X+ yog nyob ntawm Digital6 // objeto para manipulacao dos eventos de toque na tela TouchScreen ts = TouchScreen (XP, YP, XM, YM); teeb tsa tsis muaj dab tsi () {Serial.begin (9600); } void loop () {TSPoint touchPoint = ts.getPoint (); // pega o kov (x, y, z = pressao) Serial.print ("X:"); Serial.println (touchPoint.x); Serial.print ("Y:"); Serial.println (touchPoint.y); ncua (1000); }
Kauj Ruam 4: Kev Ua Haujlwm
Tam sim no cia peb saib qee qhov ua haujlwm zoo uas cov tsev qiv ntawv tuaj yeem muab rau peb.
1. drawPixel
Lub luag haujlwm DrawPixel yog lub luag haujlwm pleev xim rau ib qho ntawm lub vijtsam ntawm qhov chaw muab.
void drawPixel (int16_t x, int16_t thiab, uint16_t xim);
2. drawLine
Txoj haujlwm drawLine yog lub luag haujlwm rau kos kab los ntawm ob lub ntsiab lus.
void drawLine (int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t xim);
3. drawFastVLine
DrawFastVLine ua haujlwm yog lub luag haujlwm rau kos kab ntsug los ntawm ib qho taw tes thiab qhov siab.
void drawFastVLine (int16_t x, int16_t y, int16_t h, uint16_t xim);
4. drawFastHLine
DrawFastHLine ua haujlwm yog lub luag haujlwm rau kos kab kab rov tav los ntawm qhov taw tes thiab qhov dav.
void drawFastHLine (int16_t x, int16_t y, int16_t w, uint16_t xim);
5. drawRect
Txoj haujlwm kos duab yog lub luag haujlwm rau kos duab plaub fab ntawm lub vijtsam, dhau los ntawm lub hauv paus chiv keeb, nws qhov siab thiab dav.
void drawRect (int16_t x, int16_t y, int16_t w, int16_t h, uint16_t xim);
6. fillRect
Kev ua haujlwm fillRect zoo ib yam li drawRect, tab sis lub duab plaub yuav ua tiav nrog cov xim muab.
void fillRect (int16_t x, int16_t y, int16_t w, int16_t h, uint16_t xim);
7. drawRoundRect
DrawRoundRect muaj nuj nqi zoo ib yam li drawRect, tab sis lub duab plaub yuav muaj cov npoo sib npaug.
void drawRoundRect (int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius, uint16_t xim);
8. fillRoundRect
Kev ua haujlwm fillRoundRect zoo ib yam li drawRoundRect, tab sis lub duab plaub yuav tau ntim nrog cov xim muab.
void fillRoundRect (int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius, uint16_t xim);
9. drawTriangle
Txoj haujlwm drawTriangle yog lub luag haujlwm rau kos duab daim duab peb sab ntawm lub vijtsam, hla lub ntsiab lus ntawm 3 qhov siab.
void drawTriangle (int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t xim);
10. fillTriangle
Kev ua haujlwm fillTriangle yog tib yam li kosTriangle, tab sis daim duab peb sab yuav raug sau nrog cov xim muab.
void fillTriangle (int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t xim);
11. drawCircle
Lub luag haujlwm DrawCircle yog lub luag haujlwm rau kos lub voj voog los ntawm qhov chaw taw tes thiab lub vojvoog.
void drawCircle (int16_t x0, int16_t y0, int16_t r, uint16_t xim);
12. fillCircle
Qhov kev ua haujlwm fillCircle zoo ib yam li kos duab, tab sis lub voj voog yuav tau ntim nrog cov xim muab.
void fillCircle (int16_t x0, int16_t y0, int16_t r, uint16_t xim);
13. puv npo
Kev ua haujlwm fillScreen yog lub luag haujlwm ua kom puv lub vijtsam nrog ib qho xim.
void fillScreen (uint16_t xim);
14. setCursor
Kev ua haujlwm setCursor yog lub luag haujlwm rau tso tus cursor rau kev sau rau ib kis.
void setCursor (int16_t x, int16_t y);
15. setTextColor
Kev teeb tsa setTextColor yog lub luag haujlwm rau muab cov xim rau cov ntawv kom sau. Peb muaj ob txoj hauv kev los siv nws:
void setTextColor (uint16_t c); // teev cov xim ntawm kev sau ntawv nkaus xwb tsis muaj setTextColor (uint16_t c, uint16_t bg); // teeb cov xim sau thiab xim tom qab
16. setTextSize
Kev ua haujlwm setTextSize yog lub luag haujlwm rau muab qhov loj me rau cov ntawv uas yuav sau.
void setTextSize (uint8_t s);
17. setTextWrap
SetTextWrap muaj nuj nqi yog txhawm rau txhawm rau kab yog tias nws mus txog qhov txwv ntawm qhov screen.
tsis muaj dab tsi setTextWrap (boolean w);
18. setRotation
Kev teeb tsa kev ua haujlwm yog lub luag haujlwm rau tig lub vijtsam (toj roob hauv pes, duab puab).
void setRotation (uint8_t r); // 0 (tus qauv), 1, 2, 3
Kauj Ruam 5: Piv txwv
Peb yuav tsim ib txoj haujlwm uas peb yuav siv feem ntau ntawm cov peev txheej uas cov zaub muab rau peb.
Cia peb sau qee cov hlua hauv qhov sib txawv sib txawv, tsim peb daim duab duab, thiab khaws qhov tshwm sim kov rau lawv, txhua lub sijhawm peb kov ib qho ntawm cov duab, peb yuav muaj cov lus tawm tswv yim ntawm lub npe nyob hauv qab lawv.
Kauj Ruam 6: Cov tsev qiv ntawv
Ua ntej cia peb txhais cov tsev qiv ntawv uas peb yuav siv.
#include // responsável pela parte gráfica
#include // responsável por pegar os toques na tela
#include // comunicação com o zaub
#include // comunicação com o zaub
#suav nrog "lej.h" // cov lej muaj zog
Kauj ruam 7: Txhais
Peb yuav txhais qee qhov macros rau tus pin, thiab tseem ceeb qhov tseem ceeb uas peb yuav siv.
// Portas de leitura das coordenadas ua kov #txhais YP A1 // Y+ #define XM A2 // X- #define YM 7 // Y- #define XP 6 // X+ // valores encontrados através da calibração do touch // faça um código simples para imprimir os valores (x, y) a cada toque // então encontre os valores nas extremidades max/min (x, y) #define TS_MINX 130 #define TS_MINY 80 #define TS_MAXX 900 #define TS_MAXY 900 // tamanho dos textos #define TEXT_SIZE_L 3 #define TEXT_SIZE_M 2 #define TEXT_SIZE_S 1 // posicionamento dos textos de feedback #define FEEDBACK_LABEL_X 10 #define FEEDBACK_LABEL_Y 200 #define FEEDBACK_TOUCH_Description #defineDescriptionDescription: 10 #define siab tshaj 1000
Peb txuas ntxiv nrog lub ntsiab lus ntawm qee qhov macros.
// Associa o nome das cores aos valores correspondentes #txhais BLACK 0x0000 #define RED 0xF800 #define GREEN 0x07E0 #define CYAN 0x07FF #define YELLOW 0xFFE0 #define WHITE 0xFFFF // dados de criação ua circulo const int_; const int circle_x = 240; const int cov_y = 125; // objeto para manipulacao dos eventos de toque na tela TouchScreen ts = TouchScreen (XP, YP, XM, YM); // objeto para manipulacao da parte grafica SWTFT tft;
Kauj ruam 8: Teeb tsa
Hauv kev teeb tsa, peb yuav pib ua peb cov duab tswj cov khoom thiab ua thawj qhov teeb tsa.
teeb tsa tsis muaj dab tsi () {Serial.begin (9600); // reseta ob objeto da lib grafica tft.reset (); // inicializa objeto controlador da lib grafica tft.begin (); ncua (500); // rotaciona a tela para toj roob hauv pes tft.setRotation (1); // pinta a tela toda de preto tft.fillScreen (BLACK); // chama a função para iniciar nossas configurações initialSettings (); }
Kauj ruam 9: Loop
Hauv lub voj, peb yuav khaws lub ntsiab lus uas peb kov lub vijtsam, thiab saib yog qhov kov tshwm sim hauv ib qho ntawm cov duab.
void loop () {TSPoint touchPoint = ts.getPoint (); // pega o kov (x, y, z = pressao) pinMode (XM, OUTPUT); tus pinMode (YP, OUTPUT); // mapeia o ponto de touch para o (x, y) grafico // o fato de termos rotacionado a tela para toj roob hauv pes implica tsis muaj X receber o mapeamento de Y TSPoint p; p.x = daim ntawv qhia (touchPoint.y, TS_MINY, TS_MAXY, 0, 320); p.y = map (touchPoint.x, TS_MINX, TS_MAXX, 240, 0); // verifica se a pressão no toque foi suficiente yog (touchPoint.z> MINPRESSURE && touchPoint.z <MAXPRESSURE) {// verifica se tocou no retangulo if (pointInRect (p)) {writeShape ("Rect"); } // verifica se tocou no triangulo lwm yog (pointInsideTriangle (TSPoint (110, 150, 0), TSPoint (150, 100, 0), TSPoint (190, 150, 0), p)) {writeShape ("Daim duab peb sab"); } // verifica se tocou no circulo lwm yog (pointInCircle (p)) {writeShape ("Vajvoog"); }}}
Kauj Ruam 10: Txheeb Yog tias Peb Kov Lub Vajvoog
Hauv theem no peb cuam tshuam nrog kev pib tshuaj ntsuam thiab txhais cov xim ntawm cov ntawv kom pom.
/ *Desenha na tela os elementos */ void initialSettings () {tft.setTextColor (WHITE); tft.setTextSize (TEXT_SIZE_S); tft.println ("ACESSE"); tft.setTextColor (YELLOW); tft.setTextSize (TEXT_SIZE_M); tft.println ("MEU BLOG"); tft.setTextColor (GREEN); tft.setTextSize (TEXT_SIZE_L); tft.println ("FERNANDOK. COM"); createRect (); createTriangle (); createCircle (); tft.setCursor (FEEDBACK_LABEL_X, FEEDBACK_LABEL_Y); tft.setTextColor (CYAN); tft.setTextSize (TEXT_SIZE_L); tft.println ("QAUV:"); }
Kauj Ruam 11: Kev Ua Haujlwm ntawm Tsim Cov Duab Duab
Peb tsim cov duab plaub, daim duab peb sab, thiab lub voj voog nrog lub hauv paus uas peb txiav txim siab.
// cria um retangulo com origem (x, y) = (10, 100) // dav = 80 e qhov siab = 50 void createRect () {tft.fillRect (10, 100, 80, 50, RED); tft.drawRect (10, 100, 80, 50, WHITE); } // cria um triangulo com os vertices: // A = (110, 150); B = (150, 100); C = (190, 150) void createTriangle () {tft.fillTriangle (110, 150, 150, 100, 190, 150, YELLOW); tft.drawTriangle (110, 150, 150, 100, 190, 150, WHITE); } // cria um circulo com origem no ponto (x, y) = (240, 125) e raio = 30 void createCircle () {tft.fillCircle (240, 125, 30, GREEN); tft.drawCircle (240, 125, 30, WHITE); }
Kauj Ruam 12: Txheeb Yog tias Peb Kov Lub Duab Plaub
Txoj haujlwm no kuaj xyuas yog tias lub ntsiab lus nyob sab hauv lub duab plaub.
// Função que verifica se o ponto está dentro do retângulobool pointInRect (TSPoint p) {// max/min X do retangulo if (px> = 10 && px <= 90) {// max/min Y do retangulo if (py = 100) {rov tseeb; }} rov tsis tseeb; }
Kauj Ruam 13: Txheeb Yog tias Peb Kov Lub Vajvoog
Qhov no yog tib yam li nrog lub voj voog.
// distancia entre pontos D = raiz ((xb-xa)^2 + (yb-ya)^2) // vefifica se o ponto está dentro do circulo // se a distancia do ponto pra origem do circulo for menor ou igual ao raio, ele está dentro bool pointInCircle (TSPoint p) {ntab nrug = sqrt (pow (px - circle_x, 2) + pow (py - circle_y, 2)); yog (nrug <= circle_radius) {rov muaj tseeb; } rov tsis tseeb; }
Kauj Ruam 14: Txheeb Yog Peb Kov Daim Duab Peb Hlis
Kev txheeb xyuas tib yam ntawm cov ntsiab lus kuj tshwm sim hauv daim duab peb sab.
// Função que verifica se o ponto p esta dentro do triangulo ABC // Se estiver dentro retorna TRUE senão retorna FALSE bool pointInsideTriangle (TSPoint a, TSPoint b, TSPoint c, TSPoint p) {ntab ABC = triangleArea (a, b, c); ntab ACP = triangleArea (a, c, p); ntab ABP = triangleArea (a, b, p); ntab CPB = triangleArea (c, p, b); yog tias (ABC == ACP+ABP+CPB) {rov tseeb; } rov tsis tseeb; } // Função que calcula a area de um triangulo com base nos pontos x, y float triangleArea (TSPoint a, TSPoint b, TSPoint c) {return fabs (((bx - ax)*(cy - ay) - (cx - ax) * (by - ay))/2); }
Kauj Ruam 15: Muaj nuj nqi Luam Lub Npe Lub Hom Phiaj Touched
Ntawm no peb sau rau ntawm lub vijtsam lub npe ntawm daim duab geometric uas tau siv.
// escreve na tela o nome da figura geométrica que foi tocadavoid writeShape (String shape) {tft.fillRect (FEEDBACK_TOUCH_X, FEEDBACK_TOUCH_Y, 170, 30, BLACK); tft.setCursor (FEEDBACK_TOUCH_X, FEEDBACK_TOUCH_Y); tft.setTextSize (TEXT_SIZE_G); tft.setTextColor (WHITE); tft.println (puab); }
Kauj ruam 16: Cov ntaub ntawv
Rub tawm cov ntawv:
INO
Pom zoo:
ESP32 Raws Li RFID Reader Nrog Kov Zaub: 7 Cov Kauj Ruam
ESP32 Raws Li Kev Nyeem Ntawv RFID Nrog Kov Zaub: Ntawm cov lus qhia no kuv yuav qhia yuav ua li cas thiaj tsim tau yooj yim RFID nyeem ntawv nrog TFT tso tawm rau phab ntsa teeb tsa siv ESP32 DEV KIT C module, RC-522 raws li nyeem ntawv pcb thiab AZ-Touch ESP cov khoom siv. Koj tuaj yeem siv tus nyeem ntawv no nkag mus rau lub qhov rooj lossis nkag mus rau qhov tsis nkag siab
Loj hlob Zaub Zaub Ntxiv Hauv Qhov Chaw Tsawg Los Yog Loj hlob Zaub Zaub Hauv Chaw, (Ntau lossis Tsawg): 10 Kauj Ruam
Loj Hlob Ntau Cov Zaub Zaub Hauv Tsawg Chaw lossis … Loj hlob Zaub Zaub Hauv Chaw, (Ntau lossis Tsawg).: Qhov no yog kev tshaj lij tshaj lij rau Kev Loj Hlob Tshaj Ntiaj Teb, Kev Tsim Khoom Sib Tw, xa los ntawm Cov Lus Qhia. Kuv tsis tuaj yeem muaj kev zoo siab dua los tsim rau thaj chaw cog qoob loo thiab tshaj tawm kuv thawj Cov Lus Qhia. Yuav pib, kev sib tw nug peb kom
Chaw Zaub Zaub Zaub Qhia Tau Zoo- Airline High School Robotics: 8 Kauj Ruam
Space Lettuce Chamber Instructable- Airline High School Robotics: Nov yog Kev Qhia Ua los ntawm peb tus tub ntxhais kawm theem siab cuv npe hauv chav kawm neeg hlau. Peb yuav tsim chav rau cog cov zaub xas lav hauv qhov chaw rau Kev Loj Hlob Tshaj Ntiaj Teb Kev Sib Tw los ntawm NASA. Peb tab tom yuav qhia koj yuav tsim lub thawv li cas. Cia peb
Peb Kov Sensor Cov Hluav Taws Xob + Kov Timer Circuit: 4 Cov Kauj Ruam
Peb Kov Sensor Cov Hluav Taws Xob + Kov Timer Circuit: Kov Sensor yog lub voj voog uas tig rau thaum nws pom qhov kov ntawm Kov Pins. Nws ua haujlwm nyob rau ib ntus piv txwv li lub nra yuav ON tsuas yog rau lub sijhawm kov tau ua rau ntawm tus pin. Ntawm no, kuv yuav qhia koj peb txoj hauv kev sib txawv los ua kov sen
Ua Hnab looj tes Ua Haujlwm Nrog Kov Screen: 3 Kauj Ruam (nrog Duab)
Ua Hnab looj tes Ua Haujlwm Nrog Kov Screen: Koj tuaj yeem ua qhov no hauv ob peb feeb yam tsis muaj kev paub ntau npaum li cas. Lub caij ntuj no los txog (yog tias koj nyob rau Sab Qaum Teb Qaum Teb) thiab nrog lub caij ntuj no los txias huab cua, thiab nrog huab cua txias los hnab looj tes. Tab sis txawm nyob hauv qhov txias koj lub xov tooj