아두이노 터치스크린 터치 그리고 Display <소스파일> <결과물> https://youtu.be/bY6el40VmZI 기타 <한글 출력 방법> https://blog.naver.com/kwy1052aa/221763898675 <사용방법> https://orasman.tistory.com/276 |
- #include <Adafruit_GFX.h> // Core graphics library
- #include <Adafruit_TFTLCD.h> // Hardware-specific library
- /////////////////////////////////////////////////////////////
- #include <TouchScreen.h>
- #define YP A2 // must be an analog pin, use "An" notation!
- #define XM A3 // must be an analog pin, use "An" notation!
- #define YM 8 // can be a digital pin
- #define XP 9 // can be a digital pin
- #define TS_MINX 350
- #define TS_MINY -230
- #define TS_MAXX 1000
- #define TS_MAXY 960
- #define MINPRESSURE 10
- #define MAXPRESSURE 1000
- TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);
- ////////////////////////////////////////////////////////////////////
- #define LCD_CS A3 // Chip Select goes to Analog 3
- #define LCD_CD A2 // Command/Data goes to Analog 2
- #define LCD_WR A1 // LCD Write goes to Analog 1
- #define LCD_RD A0 // LCD Read goes to Analog 0
- #define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin
- #define BLACK 0x0000
- #define BLUE 0x001F
- #define RED 0xF800
- #define GREEN 0x07E0
- #define CYAN 0x07FF
- #define MAGENTA 0xF81F
- #define YELLOW 0xFFE0
- #define WHITE 0xFFFF
- Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
- // If using the shield, all control and data lines are fixed, and
- // a simpler declaration can optionally be used:
- // Adafruit_TFTLCD tft;
- int a;
- void setup(void) {
- Serial.begin(9600);
- Serial.println(F("TFT LCD test"));
- #ifdef USE_ADAFRUIT_SHIELD_PINOUT
- Serial.println(F("Using Adafruit 2.8\" TFT Arduino Shield Pinout"));
- #else
- Serial.println(F("Using Adafruit 2.8\" TFT Breakout Board Pinout"));
- #endif
- Serial.print("TFT size is "); Serial.print(tft.width()); Serial.print("x"); Serial.println(tft.height());
- tft.reset();
- uint16_t identifier = 0x9327;//tft.readID();
- if(identifier == 0x9325) {
- Serial.println(F("Found ILI9325 LCD driver"));
- } else if(identifier == 0x9327) {
- Serial.println(F("Found ILI9327 LCD driver"));
- } else if(identifier == 0x9328) {
- Serial.println(F("Found ILI9328 LCD driver"));
- } else if(identifier == 0x7575) {
- Serial.println(F("Found HX8347G LCD driver"));
- } else if(identifier == 0x9341) {
- Serial.println(F("Found ILI9341 LCD driver"));
- } else if(identifier == 0x8357) {
- Serial.println(F("Found HX8357D LCD driver"));
- } else if(identifier == 0x0154) {
- Serial.println(F("Found S6D0154 LCD driver"));
- } else {
- Serial.print(F("Unknown LCD driver chip: "));
- Serial.println(identifier, HEX);
- Serial.println(F("If using the Adafruit 2.8\" TFT Arduino shield, the line:"));
- Serial.println(F(" #define USE_ADAFRUIT_SHIELD_PINOUT"));
- Serial.println(F("should appear in the library header (Adafruit_TFT.h)."));
- Serial.println(F("If using the breakout board, it should NOT be #defined!"));
- Serial.println(F("Also if using the breakout, double-check that all wiring"));
- Serial.println(F("matches the tutorial."));
- return;
- }
- #define LCDROTATION 3
- tft.begin(identifier);
- Serial.print(F("Text "));
- delay(1000);
- tft.fillScreen(BLACK); //배경 까망색
- tft.drawRect(0,0,130,120,WHITE); // 네모 테두리 있는 상자 넣기
- }
- void loop(void) {
- TSPoint p = ts.getPoint();
- pinMode(XM, OUTPUT);
- pinMode(YP, OUTPUT);
- if (p.z > MINPRESSURE && p.z < MAXPRESSURE) {
- p.x=map(p.x,TS_MINX, TS_MAXX, tft.width(),0);
- p.y=map(p.y,TS_MINY, TS_MAXY, tft.height(),0);
- if( p.x>0 && p.x<160){ //터치스크린 X좌표 0~160
- if(p.y>0 && p.y<160){ //터치스크린 Y좌표 0~160 두조건 만족하면 아래 조건 성립
- testText();
- delay(500);}}
- }
- }
- unsigned long testText() {
- tft.setRotation(3);
- unsigned long start = micros();
- tft.fillScreen(BLACK);
- tft.setCursor(0, 0);
- tft.setTextColor(WHITE); tft.setTextSize(2);
- tft.println("Hello BAK CHAN YEOP");
- tft.fillRect(180,30,130,120,RED);
- tft.setTextColor(WHITE); tft.setTextSize(3);
- tft.setCursor(20, 40);
- tft.println("<TEMP>");
- tft.setCursor(30, 70);
- tft.setTextColor(YELLOW); tft.setTextSize(2);
- tft.println(a);
- tft.setTextColor(WHITE); tft.setTextSize(3);
- tft.setCursor(180, 40);
- tft.println("<Count>");
- tft.setCursor(190, 70);
- tft.setTextColor(YELLOW); tft.setTextSize(2);
- tft.println(a);
- return micros() - start;
- }
아래 링크로 쓸수 있는 디자인들
'아두이노' 카테고리의 다른 글
아두이노 I2C Bitmap(비트맵)파일 OLED Display 하기(소스링크) (0) | 2021.08.29 |
---|---|
로보티즈 AX-12+(=AX-12A) Motor 제어하기 (2) | 2020.07.14 |
아두이노 Servo Motor를 이용한 물고기 Feeder기 제작 (0) | 2020.04.02 |
자이로 센서 TEST (0) | 2020.02.27 |