BASIC4MCU | 질문게시판 | 답변 : TFT LCD 버튼값 출력하기 2번째 질문입니다! 제발 도와주세요ㅠㅠ
페이지 정보
작성자 master 작성일2020-03-01 10:42 조회20,904회 댓글5건본문
// MCU BASIC: https://www.basic4mcu.com// DateTime : 2020-03-01 오전 10:44:20// by Ok-Hyun Park//#include <MCUFRIEND_kbv.h>#include <Adafruit_GFX.h>// Core graphics library// wiring with UNO or Mega2560://--------------POWER Pins--------------------------------// 5V connects to DC 5V// GND connects to Ground// 3V3 do not need to connect(NC)//--------------LCD Display Pins--------------------------// LCD_RD connects to Analog pin A0// LCD_WR connects to Analog pin A1// LCD_RS connects to Analog pin A2// LCD_CS connects to Analog pin A3// LCD_RST connects to Analog pin A4// LCD_D0 connects to digital pin 8// LCD_D1 connects to digital pin 9// LCD_D2 connects to digital pin 2// LCD_D3 connects to digital pin 3// LCD_D4 connects to digital pin 4// LCD_D5 connects to digital pin 5// LCD_D6 connects to digital pin 6// LCD_D7 connects to digital pin 7//--------------SD-card fuction Pins----------------------//This Connection Only for UNO,Do not support Mega2560//because they use different Hardware-SPI Pins//SD_SS connects to digital pin 10//SD_DI connects to digital pin 11//SD_DO connects to digital pin 12//SD_SCK connects to digital pin 13#define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin#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 Button_pin 33//#define BLACK 0x0000#define BLUE 0x001F#define RED 0xF800#define GREEN 0x07E0#define CYAN 0x07FF#define MAGENTA 0xF81F#define YELLOW 0xFFE0#define WHITE 0xFFFF//MCUFRIEND_kbv tft;//void disp(){tft.setCursor(0,0); tft.setTextColor(WHITE); tft.setTextSize(3);tft.println("Push the Button");tft.print("value: "); tft.println(Button_value);}//int Button_value=0,Button_flag=0;//void setup(void){Serial.begin(9600); Serial.println(F("TFT LCD test"));tft.reset();uint16_t identifier=tft.readID();if (identifier==0x9325){ Serial.println(F("Found ILI9325 LCD driver ")); }else if(identifier==0x9328){ Serial.println(F("Found ILI9328 LCD driver ")); }else if(identifier==0x4535){ Serial.println(F("Found LGDP4535 LCD driver")); }else if(identifier==0x7575){ Serial.println(F("Found HX8347G LCD driver ")); }else if(identifier==0x9595){ Serial.println(F("Found HX8347-I LCD driver")); }else if(identifier==0x4747){ Serial.println(F("Found HX8347-D LCD driver")); }else if(identifier==0x8347){ Serial.println(F("Found HX8347-A LCD driver")); }else if(identifier==0x9341){ Serial.println(F("Found ILI9341 LCD driver ")); }else if(identifier==0x7783){ Serial.println(F("Found ST7781 LCD driver ")); }else if(identifier==0x8230){ Serial.println(F("Found UC8230 LCD driver ")); }else if(identifier==0x8357){ Serial.println(F("Found HX8357D LCD driver ")); }else if(identifier==0x0101){ Serial.println(F("Found 0x9341 LCD driver ")); identifier=0x9341; }else if(identifier==0x7793){ Serial.println(F("Found ST7793 LCD driver ")); }else if(identifier==0xB509){ Serial.println(F("Found R61509 LCD driver ")); }else if(identifier==0x9486){ Serial.println(F("Found ILI9486 LCD driver ")); }else if(identifier==0x9488){ Serial.println(F("Found ILI9488 LCD driver ")); }else { Serial.print(F("Unknown LCD driver chip: ")); Serial.println(identifier,HEX); identifier=0x9486; }tft.begin(identifier);disp();}//void loop(void){if(digitalRead(Button_pin)){if(Button_flag){ Button_flag=0;Button_value++; Serial.print("value: "); Serial.println(Button_value);disp();delay(100);}}else{if(Button_flag==0){ Button_flag=1; delay(100); }}}
댓글 5
조회수 20,904쉘쉘김쉘쉘님의 댓글
쉘쉘김쉘쉘 작성일
C:\Users\scjin\Desktop\naver1\___1\___1.ino: In function 'void disp()':
___1:49:23: error: 'lcd' was not declared in this scope
tft.setCursor(0,0); lcd.setTextColor(WHITE); lcd.setTextSize(3);
^
___1:51:37: error: 'Button_value' was not declared in this scope
lcd.print("value: "); lcd.println(Button_value);
^
C:\Users\scjin\Desktop\naver1\___1\___1.ino: In function 'void loop()':
___1:80:8: error: 'Button_flag' was not declared in this scope
if(Button_flag){ Button_flag=0;
^
___1:81:7: error: 'Button_value' was not declared in this scope
Button_value++; Serial.print("value: "); Serial.println(Button_value);
^
___1:87:8: error: 'Button_flag' was not declared in this scope
if(Button_flag==0){ Button_flag=1; delay(100); }
^
exit status 1
'lcd' was not declared in this scope
컴파일 하니까 이런 오류가 생기네요..
1. 'lcd'부분은 'tft'로 변경하면 되는지
2. Button_flag 부분은 어떻게 해야하는지
질문 드립니다ㅜㅜ
master님의 댓글
master
간단한 오류는 수정할 수 있어야합니다.
다시 복사해서 돌려보세요
쉘쉘김쉘쉘님의 댓글
쉘쉘김쉘쉘 작성일
이부분은 덕분에 수정해서 성공했습니다.
추가 질문으로 버튼 값이 아니고
조도센서 값이 예를들어 700 이상이면
숫자 값이 1씩 올라가게 표현하려면 어떻게 해야할까요?
밝기에 따른 조도센서 값을 lcd에 표현하는건 할 수 있는데 값이 아니라
일정 값 이상일 때 숫자가 1씩 올라가는..
master님의 댓글
master 작성일
int mode=0;
//
void loop(void){
int a=analogRead(A0);
if(a>700){
if(mode!=1){ mode=1;
Button_value++; Serial.print("value: "); Serial.println(Button_value);
disp();
}
}
else if(a>650){} // 650~700
else{
if(mode!=-1){ mode=-1; }
}
}
여기서
아나로그 값은 일정부분 흔들림이 있는데 700 근처에서 값이 흔들리게 되면 카운트가 계속 증가하게 됩니다.
else if(a>650){} // 650~700
만약 흔들림의 크기가 최대 50 미만이라면 650~700 범위는 오차로 보고서 아무런 처리를 하지 않도록 하면 됩니다.
쉘쉘김쉘쉘님의 댓글
쉘쉘김쉘쉘 작성일
ㄱㅅ합니다.
추가 의문점이 두개 있는데요
1. 혹시 아두이노내에서
디지털 1번핀과 2번핀을 직접 전선으로
연결해서
디지털 1번핀이 내보내는 신호를
디지털 2번핀이 입력받을 수 있나요?
불 안날까요?
2. 소스코드를 푸시버튼을 눌렀을 시 숫자
값이 1씩 올라가도록한 상태에서,
푸시버튼을 대신
디지털 신호를 보내도 작동 될까요?
확인하고 싶은게
회로를 디지털 1번핀과 2번핀으로 직접
연결한 상태에서, (2번 핀은 버튼입력 시
숫자값이 올라가는 소스코드를 해둘겁니다.)
이때,
먼저, 아날로그 1번핀(조도센서) 값이
700 이상일 때 디지털 1번핀으로
신호를 내보내도록 하고,
디지털 1번핀의 출력신호를 디지털 2번 핀이 입력받아 (푸시버튼을 대체한) 숫자값이 올라가도록 하고싶은데
가능할까요?