#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
//#include "URTouch.h"
#define TFT_DC 9
#define TFT_CS 10
#define TFT_RST 8
#define TFT_MISO 12
#define TFT_MOSI 11
#define TFT_CLK 13
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);
#define t_SCK 3
#define t_CS 4
#define t_MOSI 5
#define t_MISO 6
#define t_IRQ 7
int bientroX = A0;
int bientroY = A1;
int button = 2;
//URTouch ts(t_SCK, t_CS, t_MOSI, t_MISO, t_IRQ);
int BLOCK_GRASS[] = {
116, 180, 74, 118, 182, 76, 115, 179, 73, 102, 166, 60, 102, 166, 60, 111, 175, 69, 95, 159, 53, 108, 172, 66, 126, 190, 84, 118, 182, 76, 106, 170, 64, 103, 167, 61, 105, 169, 63, 97, 161, 55, 80, 144, 38, 109, 173, 67,
117, 181, 75, 108, 172, 66, 138, 185, 90, 129, 176, 81, 131, 178, 83, 89, 61, 41, 104, 168, 62, 98, 162, 56, 95, 159, 53, 147, 194, 99, 144, 191, 96, 115, 179, 73, 97, 161, 55, 108, 172, 66, 103, 167, 61, 107, 171, 65,
141, 188, 93, 89, 61, 41, 156, 203, 108, 100, 164, 58, 105, 169, 63, 89, 61, 41, 112, 176, 70, 89, 61, 41, 116, 180, 74, 127, 191, 85, 146, 193, 98, 151, 198, 103, 89, 61, 41, 87, 151, 45, 96, 160, 54, 89, 61, 41,
89, 61, 41, 108, 108, 108, 89, 61, 41, 89, 61, 41, 113, 177, 71, 89, 61, 41, 89, 61, 41, 89, 61, 41, 95, 159, 53, 89, 61, 41, 109, 173, 67, 89, 61, 41, 121, 85, 58, 89, 61, 41, 89, 61, 41, 121, 85, 58,
150, 108, 74, 121, 85, 58, 150, 108, 74, 185, 133, 92, 89, 61, 41, 150, 108, 74, 121, 85, 58, 121, 85, 58, 89, 61, 41, 89, 61, 41, 89, 61, 41, 108, 108, 108, 121, 85, 58, 150, 108, 74, 89, 61, 41, 121, 85, 58,
121, 85, 58, 89, 61, 41, 150, 108, 74, 150, 108, 74, 121, 85, 58, 150, 108, 74, 89, 61, 41, 89, 61, 41, 89, 61, 41, 121, 85, 58, 121, 85, 58, 89, 61, 41, 121, 85, 58, 121, 85, 58, 121, 85, 58, 185, 133, 92,
185, 133, 92, 121, 85, 58, 121, 85, 58, 121, 85, 58, 135, 135, 135, 121, 85, 58, 121, 85, 58, 185, 133, 92, 185, 133, 92, 121, 85, 58, 185, 133, 92, 185, 133, 92, 121, 85, 58, 150, 108, 74, 121, 85, 58, 150, 108, 74,
121, 85, 58, 121, 85, 58, 185, 133, 92, 185, 133, 92, 150, 108, 74, 150, 108, 74, 121, 85, 58, 121, 85, 58, 150, 108, 74, 89, 61, 41, 150, 108, 74, 150, 108, 74, 121, 85, 58, 121, 85, 58, 150, 108, 74, 150, 108, 74,
150, 108, 74, 121, 85, 58, 121, 85, 58, 150, 108, 74, 121, 85, 58, 150, 108, 74, 121, 85, 58, 89, 61, 41, 121, 85, 58, 150, 108, 74, 150, 108, 74, 121, 85, 58, 121, 85, 58, 121, 85, 58, 89, 61, 41, 121, 85, 58,
121, 85, 58, 150, 108, 74, 89, 61, 41, 121, 85, 58, 121, 85, 58, 89, 61, 41, 89, 61, 41, 121, 85, 58, 121, 85, 58, 121, 85, 58, 121, 85, 58, 121, 85, 58, 185, 133, 92, 185, 133, 92, 121, 85, 58, 150, 108, 74,
121, 85, 58, 150, 108, 74, 121, 85, 58, 185, 133, 92, 185, 133, 92, 121, 85, 58, 185, 133, 92, 150, 108, 74, 89, 61, 41, 185, 133, 92, 185, 133, 92, 89, 61, 41, 150, 108, 74, 150, 108, 74, 135, 135, 135, 121, 85, 58,
150, 108, 74, 121, 85, 58, 121, 85, 58, 150, 108, 74, 150, 108, 74, 185, 133, 92, 121, 85, 58, 150, 108, 74, 108, 108, 108, 150, 108, 74, 150, 108, 74, 121, 85, 58, 89, 61, 41, 150, 108, 74, 121, 85, 58, 89, 61, 41,
121, 85, 58, 89, 61, 41, 150, 108, 74, 121, 85, 58, 150, 108, 74, 150, 108, 74, 185, 133, 92, 121, 85, 58, 121, 85, 58, 121, 85, 58, 121, 85, 58, 121, 85, 58, 121, 85, 58, 121, 85, 58, 185, 133, 92, 185, 133, 92,
121, 85, 58, 150, 108, 74, 121, 85, 58, 121, 85, 58, 116, 88, 68, 121, 85, 58, 150, 108, 74, 150, 108, 74, 121, 85, 58, 89, 61, 41, 185, 133, 92, 89, 61, 41, 121, 85, 58, 185, 133, 92, 150, 108, 74, 150, 108, 74,
150, 108, 74, 121, 85, 58, 89, 61, 41, 185, 133, 92, 121, 85, 58, 89, 61, 41, 121, 85, 58, 89, 61, 41, 185, 133, 92, 185, 133, 92, 121, 85, 58, 150, 108, 74, 121, 85, 58, 121, 85, 58, 150, 108, 74, 150, 108, 74,
150, 108, 74, 121, 85, 58, 185, 133, 92, 150, 108, 74, 150, 108, 74, 121, 85, 58, 135, 135, 135, 121, 85, 58, 150, 108, 74, 150, 108, 74, 121, 85, 58, 121, 85, 58, 150, 108, 74, 150, 108, 74, 121, 85, 58, 89, 61, 41
};
void setup(){
pinMode(2, INPUT);
pinMode(A0, INPUT);
pinMode(A1, INPUT);
Serial.begin(9600);
tft.begin();
tft.setRotation(3);
//ts.InitTouch();
//ts.setPrecision(PREC_EXTREME);
tft.fillScreen(tft.color565(135, 206, 235));
for (int w = 0; w < 22; w++) {
renderBlock(BLOCK_GRASS, w, 14);
}
}
void loop()
{
int x = analogRead(bientroX); // doc gia tri cua truc X
int y = analogRead(bientroY); // doc gia tri cua truc Y
int KEY = digitalRead(button); // doc gia tri cua nut nhan
// Xuat ra cong Serial
Serial.print("X="); Serial.println(x);
Serial.print("Y="); Serial.println(y);
Serial.print("KEY="); Serial.print(KEY); Serial.println();
delay(200);//delay để ổn định hơn
}
int * getBlockData(int id) {
if (id == 1) {
int* data = {};
for (int i = 0; i < 768; i++) {
data[i] = 255;
}
return data;
}
else {
return {};
}
}
void renderBlock(int blockData[], int x, int y) {
x = x * 16;
y = y * 16;
int colorIndex = 0;
for (int h = 0; h < 16; h++) {
for (int w = 0; w < 16; w++) {
int r = blockData[colorIndex];
int g = blockData[colorIndex+1];
int b = blockData[colorIndex+2];
tft.fillRect(x+w, y+h, 1, 1, tft.color565(r, g, b)); // Corrected the arguments here
colorIndex = colorIndex + 3;
}
}
}