반응형
글자를 갱신할 때 전체를 배경색으로 칠하면 Flicker(깜빡이) 현상이 나타난다.
글자 부분만 배경색으로 칠해도 당연히 깜빡일 수 밖에 없다. 누가 이런 방법을 팁이라고 ㅡㅡ^
(ON-OFF-ON-OFF 무반 반복 깜빡임)
깜빡임을 방지하려면 출력할 내용으로 덮어쓰기 해야 한다.
Adafruit GFX 라이브러리에는 버퍼 처럼 사용할 수 있는 GFXcanvas1 클래스가 있다.
// In global declarations:
GFXcanvas1 canvas(128, 32); // 128x32 pixel canvas
// In code later:
canvas.println("I like cake");
tft.drawBitmap(x, y, canvas.getBuffer(), 128, 32, foreground, background); // Copy
to screen
필요한 크기 만큼 canvas(width, heigh); 를 만들고, 그 안에 글자나 도형을 그려준다.
그 다음 갱신할 위치에 drawBitmap(); 으로 덮어씌우면 된다.
drawBitmap 메서드의 단점은 단색만 된다는 것이다. 컬러의 도형을 여러개 겹쳐서 갱신할 때는 어쩔 수 없이 화면을 지워야 한다.
GFXcanvas1은 인스턴스를 중복해서 만들 수 있다.
아래와 같은 함수를 임시로 만들어 사용 중이다. (클래스화는 나중에...)
uint16_t *printText(const char *str, int16_t x, int16_t y, uint16_t fgcolor, uint16_t bgcolor)
{
uint16_t size[2] = {0, 0};
int16_t x1 = x, y1 = y;
OLED.getTextBounds(str, x, y, &x1, &y1, &size[0], &size[1]);
GFXcanvas1 CANBAS(size[0], size[1]); // 캔버스
CANBAS.print(str);
// void drawBitmap(int16_t x, int16_t y, uint8_t *bitmap, int16_t w, int16_t h, uint16_t color);
OLED.drawBitmap(x1, y1, CANBAS.getBuffer(), (int16_t)size[0], (int16_t)size[1], fgcolor, bgcolor);
return size;
}
결과물
반응형
'PC&웹 > Arduino' 카테고리의 다른 글
(Arduino) ESP32, Modbus TCP 통신 성능 Test (0) | 2021.12.28 |
---|---|
(Arduino) ESP32 WiFi Event 상수 (0) | 2021.12.19 |
(Arduino) Adafruit GFX Canvas 사용, 깜빡이 방지 (0) | 2021.12.14 |
(Arduino) Waveshare e-Paper 5.65" 7 Color & GxEPD2 (0) | 2021.12.10 |
Arduino, ESP32 + Adafruit GFX 3D 렌더링 sample (0) | 2021.11.25 |
(Arduino) ESP32 Core WROOM + Adafruit SSD1351 1.5 RGB OLED H/W SPI 4wire 연결 테스트 (0) | 2021.11.24 |
댓글0