From ecbdb78fe4912fa83d088b1b4a8bc63ed6fe0cdc Mon Sep 17 00:00:00 2001 From: lewis he Date: Tue, 23 Jun 2020 17:36:15 +0800 Subject: [PATCH] Update TFTeSPI examples --- examples/Basic unit/AXP20x_ADC/AXP20x_ADC.ino | 26 +- .../AXP20x_ChargeCurrent.ino | 2 +- examples/Basic unit/AXP20x_IRQ/AXP20x_IRQ.ino | 20 +- .../PlayMP3FromSDToDAC/PlayMP3FromSDToDAC.ino | 16 +- .../Audio/ExternalDAC/SD_Play/SD_Play.ino | 10 +- .../external_dac_play/external_dac_play.ino | 12 +- .../Basic unit/BMA423_Accel/BMA423_Accel.ino | 28 +- .../BMA423_StepCount/BMA423_StepCount.ino | 10 +- examples/Basic unit/DeepSleep/DeepSleep.ino | 2 +- examples/Basic unit/DrawSD_BMP/DrawSD_BMP.ino | 2 +- examples/Basic unit/Motor/Motor.ino | 14 +- examples/Basic unit/RTC/RTC.ino | 24 +- examples/Basic unit/SDCard/SDCard.ino | 28 +- examples/Basic unit/TouchPad/TouchPad.ino | 10 +- examples/Basic unit/UserButton/UserButton.ino | 20 +- examples/Module/Fingerprint/Fingerprint.ino | 2 +- examples/Module/VEMl6075/VEMl6075.ino | 2 +- .../Module/VEMl6075_LVGL/VEMl6075_LVGL.ino | 2 +- examples/Other/AlarmClock/AlarmClock.ino | 14 +- examples/Other/FlappyBird/FlappyBird.ino | 108 +-- examples/Other/IOTA_Price/IOTA_Price.ino | 2 +- examples/Shield/BBQKeyboard/BBQKeyboard.ino | 2 +- examples/Shield/GameControl/GameControl.ino | 14 +- examples/Shield/HeartRate/HeartRate.ino | 16 +- examples/Shield/LoRa_SX127x/LoRa_SX127x.ino | 2 +- examples/Shield/M6_GPS/M6_GPS.ino | 2 +- examples/Shield/NFC_Lock/NFC_Lock.ino | 2 +- examples/Shield/S7xG_GPS/S7xG_GPS.ino | 4 +- examples/Shield/S7xG_LoRa/S7xG_LoRa.ino | 2 +- .../All_Free_Fonts_Demo.ino | 494 +++++++------- .../TFT_eSPI/Arduino_Life/Arduino_Life.ino | 135 ++-- examples/TFT_eSPI/Pong_v3/Pong_v3.ino | 238 ++++--- .../TFT_eSPI/RLE_Font_test/RLE_Font_test.ino | 184 ++--- .../TFT_Char_times/TFT_Char_times.ino | 81 +-- examples/TFT_eSPI/TFT_Clock/TFT_Clock.ino | 62 +- .../TFT_Clock_Digital/TFT_Clock_Digital.ino | 63 +- examples/TFT_eSPI/TFT_Ellipse/TFT_Ellipse.ino | 19 +- examples/TFT_eSPI/TFT_Meter_5/TFT_Meter_5.ino | 128 ++-- .../TFT_graphicstest_PDQ3.ino | 639 +++++++++--------- .../TFT_graphicstest_small.ino | 411 +++++------ .../UTFT_demo_fast/UTFT_demo_fast.ino | 124 ++-- examples/TFT_eSPI/fillScreen/fillScreen.ino | 13 +- 42 files changed, 1519 insertions(+), 1470 deletions(-) diff --git a/examples/Basic unit/AXP20x_ADC/AXP20x_ADC.ino b/examples/Basic unit/AXP20x_ADC/AXP20x_ADC.ino index 6b75f64..2d78a85 100644 --- a/examples/Basic unit/AXP20x_ADC/AXP20x_ADC.ino +++ b/examples/Basic unit/AXP20x_ADC/AXP20x_ADC.ino @@ -10,10 +10,10 @@ void setup() ttgo->begin(); ttgo->openBL(); - ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->drawString("T-Watch AXP202", 25, 50, 4); - ttgo->eTFT->setTextFont(4); - ttgo->eTFT->setTextColor(TFT_WHITE, TFT_BLACK); + ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->drawString("T-Watch AXP202", 25, 50, 4); + ttgo->tft->setTextFont(4); + ttgo->tft->setTextColor(TFT_WHITE, TFT_BLACK); ttgo->power->adc1Enable(AXP202_VBUS_VOL_ADC1 | AXP202_VBUS_CUR_ADC1 | AXP202_BATT_CUR_ADC1 | AXP202_BATT_VOL_ADC1, true); } @@ -24,15 +24,15 @@ void loop() float batt_v = ttgo->power->getBattVoltage(); int per = ttgo->power->getBattPercentage(); - ttgo->eTFT->fillRect(85, 100, 145, 85, TFT_BLACK); - ttgo->eTFT->setCursor(20, 100); - ttgo->eTFT->print("Vbus: "); ttgo->eTFT->print(vbus_v); ttgo->eTFT->println(" mV"); - ttgo->eTFT->setCursor(20, 130); - ttgo->eTFT->print("Vbus: "); ttgo->eTFT->print(vbus_c); ttgo->eTFT->println(" mA"); - ttgo->eTFT->setCursor(20, 160); - ttgo->eTFT->print("BATT: "); ttgo->eTFT->print(batt_v); ttgo->eTFT->println(" mV"); - ttgo->eTFT->setCursor(20, 190); - ttgo->eTFT->print("Per: "); ttgo->eTFT->print(per); ttgo->eTFT->println(" %"); + ttgo->tft->fillRect(85, 100, 145, 85, TFT_BLACK); + ttgo->tft->setCursor(20, 100); + ttgo->tft->print("Vbus: "); ttgo->tft->print(vbus_v); ttgo->tft->println(" mV"); + ttgo->tft->setCursor(20, 130); + ttgo->tft->print("Vbus: "); ttgo->tft->print(vbus_c); ttgo->tft->println(" mA"); + ttgo->tft->setCursor(20, 160); + ttgo->tft->print("BATT: "); ttgo->tft->print(batt_v); ttgo->tft->println(" mV"); + ttgo->tft->setCursor(20, 190); + ttgo->tft->print("Per: "); ttgo->tft->print(per); ttgo->tft->println(" %"); delay(1000); } diff --git a/examples/Basic unit/AXP20x_ChargeCurrent/AXP20x_ChargeCurrent.ino b/examples/Basic unit/AXP20x_ChargeCurrent/AXP20x_ChargeCurrent.ino index 239bef1..3565ce7 100644 --- a/examples/Basic unit/AXP20x_ChargeCurrent/AXP20x_ChargeCurrent.ino +++ b/examples/Basic unit/AXP20x_ChargeCurrent/AXP20x_ChargeCurrent.ino @@ -9,7 +9,7 @@ void setup() ttgo = TTGOClass::getWatch(); ttgo->begin(); ttgo->openBL(); - tft = ttgo->eTFT; + tft = ttgo->tft; tft->fillScreen(TFT_BLACK); tft->drawString("T-Watch AXP202", 0, 50, 2); diff --git a/examples/Basic unit/AXP20x_IRQ/AXP20x_IRQ.ino b/examples/Basic unit/AXP20x_IRQ/AXP20x_IRQ.ino index cacf286..89809c7 100644 --- a/examples/Basic unit/AXP20x_IRQ/AXP20x_IRQ.ino +++ b/examples/Basic unit/AXP20x_IRQ/AXP20x_IRQ.ino @@ -11,10 +11,10 @@ void setup() ttgo->begin(); ttgo->openBL(); - ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->drawString("T-Watch AXP202", 25, 50, 4); - ttgo->eTFT->setTextFont(4); - ttgo->eTFT->setTextColor(TFT_WHITE, TFT_BLACK); + ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->drawString("T-Watch AXP202", 25, 50, 4); + ttgo->tft->setTextFont(4); + ttgo->tft->setTextColor(TFT_WHITE, TFT_BLACK); pinMode(AXP202_INT, INPUT_PULLUP); attachInterrupt(AXP202_INT, [] { @@ -32,16 +32,16 @@ void loop() irq = false; ttgo->power->readIRQ(); if (ttgo->power->isVbusPlugInIRQ()) { - ttgo->eTFT->fillRect(20, 100, 200, 85, TFT_BLACK); - ttgo->eTFT->drawString("Power Plug In", 25, 100); + ttgo->tft->fillRect(20, 100, 200, 85, TFT_BLACK); + ttgo->tft->drawString("Power Plug In", 25, 100); } if (ttgo->power->isVbusRemoveIRQ()) { - ttgo->eTFT->fillRect(20, 100, 200, 85, TFT_BLACK); - ttgo->eTFT->drawString("Power Remove", 25, 100); + ttgo->tft->fillRect(20, 100, 200, 85, TFT_BLACK); + ttgo->tft->drawString("Power Remove", 25, 100); } if (ttgo->power->isPEKShortPressIRQ()) { - ttgo->eTFT->fillRect(20, 100, 200, 85, TFT_BLACK); - ttgo->eTFT->drawString("PowerKey Press", 25, 100); + ttgo->tft->fillRect(20, 100, 200, 85, TFT_BLACK); + ttgo->tft->drawString("PowerKey Press", 25, 100); } ttgo->power->clearIRQ(); } diff --git a/examples/Basic unit/Audio/BuiltInDAC/PlayMP3FromSDToDAC/PlayMP3FromSDToDAC.ino b/examples/Basic unit/Audio/BuiltInDAC/PlayMP3FromSDToDAC/PlayMP3FromSDToDAC.ino index 009ea74..6e07cfd 100644 --- a/examples/Basic unit/Audio/BuiltInDAC/PlayMP3FromSDToDAC/PlayMP3FromSDToDAC.ino +++ b/examples/Basic unit/Audio/BuiltInDAC/PlayMP3FromSDToDAC/PlayMP3FromSDToDAC.ino @@ -27,23 +27,23 @@ void setup() ttgo = TTGOClass::getWatch(); ttgo->begin(); ttgo->openBL(); - ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->setTextFont(2); + ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->setTextFont(2); while (1) { if (ttgo->sdcard_begin()) { Serial.println("sd begin pass"); break; } - ttgo->eTFT->println("SD begin fail,wait 1 sec"); + ttgo->tft->println("SD begin fail,wait 1 sec"); Serial.println("sd begin fail,wait 1 sec"); delay(1000); } - - ttgo->eTFT->setCursor(0, 0); - ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->println("Sample MP3 playback begins"); - + + ttgo->tft->setCursor(0, 0); + ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->println("Sample MP3 playback begins"); + // pno_cs from https://ccrma.stanford.edu/~jos/pasp/Sound_Examples.html //!Turn on the audio power ttgo->enableLDO3(); diff --git a/examples/Basic unit/Audio/ExternalDAC/SD_Play/SD_Play.ino b/examples/Basic unit/Audio/ExternalDAC/SD_Play/SD_Play.ino index d7d6654..12863f2 100644 --- a/examples/Basic unit/Audio/ExternalDAC/SD_Play/SD_Play.ino +++ b/examples/Basic unit/Audio/ExternalDAC/SD_Play/SD_Play.ino @@ -57,12 +57,12 @@ void setup() ttgo = TTGOClass::getWatch(); ttgo->begin(); ttgo->openBL(); - ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->setTextFont(2); + ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->setTextFont(2); - ttgo->eTFT->setCursor(0, 0); - ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->println("Sample MP3 playback begins"); + ttgo->tft->setCursor(0, 0); + ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->println("Sample MP3 playback begins"); ttgo->button->setPressedHandler(pressed); diff --git a/examples/Basic unit/Audio/ExternalDAC/external_dac_play/external_dac_play.ino b/examples/Basic unit/Audio/ExternalDAC/external_dac_play/external_dac_play.ino index 5ca4d16..fcf5864 100644 --- a/examples/Basic unit/Audio/ExternalDAC/external_dac_play/external_dac_play.ino +++ b/examples/Basic unit/Audio/ExternalDAC/external_dac_play/external_dac_play.ino @@ -28,13 +28,13 @@ void setup() ttgo = TTGOClass::getWatch(); ttgo->begin(); ttgo->openBL(); - ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->setTextFont(2); + ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->setTextFont(2); + + ttgo->tft->setCursor(0, 0); + ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->println("Sample MP3 playback begins"); - ttgo->eTFT->setCursor(0, 0); - ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->println("Sample MP3 playback begins"); - //!Turn on the audio power ttgo->enableLDO3(); diff --git a/examples/Basic unit/BMA423_Accel/BMA423_Accel.ino b/examples/Basic unit/BMA423_Accel/BMA423_Accel.ino index 1d7253c..a3851bf 100644 --- a/examples/Basic unit/BMA423_Accel/BMA423_Accel.ino +++ b/examples/Basic unit/BMA423_Accel/BMA423_Accel.ino @@ -8,19 +8,19 @@ void setup() ttgo = TTGOClass::getWatch(); ttgo->begin(); ttgo->openBL(); - ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->setTextColor(random(0xFFFF)); + ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->setTextColor(random(0xFFFF)); if (!ttgo->bma->begin()) { - ttgo->eTFT->drawString("BMA423 Init FAIL", 25, 50, 4); + ttgo->tft->drawString("BMA423 Init FAIL", 25, 50, 4); while (1); } ttgo->bma->enableAccel(); - ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->drawString("T-Watch BMA423", 25, 50, 4); - ttgo->eTFT->setTextFont(4); - ttgo->eTFT->setTextColor(TFT_WHITE, TFT_BLACK); + ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->drawString("T-Watch BMA423", 25, 50, 4); + ttgo->tft->setTextFont(4); + ttgo->tft->setTextColor(TFT_WHITE, TFT_BLACK); } void loop() @@ -30,13 +30,13 @@ void loop() if (res == false) { Serial.println("getAccel FAIL"); } else { - ttgo->eTFT->fillRect(98, 100, 70, 85, TFT_BLACK); - ttgo->eTFT->setCursor(80, 100); - ttgo->eTFT->print("X:"); ttgo->eTFT->println(acc.x); - ttgo->eTFT->setCursor(80, 130); - ttgo->eTFT->print("Y:"); ttgo->eTFT->println(acc.y); - ttgo->eTFT->setCursor(80, 160); - ttgo->eTFT->print("Z:"); ttgo->eTFT->println(acc.z); + ttgo->tft->fillRect(98, 100, 70, 85, TFT_BLACK); + ttgo->tft->setCursor(80, 100); + ttgo->tft->print("X:"); ttgo->tft->println(acc.x); + ttgo->tft->setCursor(80, 130); + ttgo->tft->print("Y:"); ttgo->tft->println(acc.y); + ttgo->tft->setCursor(80, 160); + ttgo->tft->print("Z:"); ttgo->tft->println(acc.z); } delay(100); } diff --git a/examples/Basic unit/BMA423_StepCount/BMA423_StepCount.ino b/examples/Basic unit/BMA423_StepCount/BMA423_StepCount.ino index a0c1e52..10ef0f0 100644 --- a/examples/Basic unit/BMA423_StepCount/BMA423_StepCount.ino +++ b/examples/Basic unit/BMA423_StepCount/BMA423_StepCount.ino @@ -19,9 +19,9 @@ void setup() ttgo->bma->begin(); ttgo->bma->attachInterrupt(); - ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->setTextColor(random(0xFF10)); - ttgo->eTFT->drawString("T-Watch BMA423", 25, 50, 4); + ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->setTextColor(random(0xFF10)); + ttgo->tft->drawString("T-Watch BMA423", 25, 50, 4); } @@ -37,9 +37,9 @@ void loop() if (ttgo->bma->isStepCounter()) { Serial.println(ttgo->bma->getCounter()); - ttgo->eTFT->setTextColor(random(0xFFFF), TFT_BLACK); + ttgo->tft->setTextColor(random(0xFFFF), TFT_BLACK); snprintf(buf, sizeof(buf), "StepCount: %u", ttgo->bma->getCounter()); - ttgo->eTFT->drawString(buf, 45, 118, 4); + ttgo->tft->drawString(buf, 45, 118, 4); } } delay(20); diff --git a/examples/Basic unit/DeepSleep/DeepSleep.ino b/examples/Basic unit/DeepSleep/DeepSleep.ino index 8d7bddb..a822f9f 100644 --- a/examples/Basic unit/DeepSleep/DeepSleep.ino +++ b/examples/Basic unit/DeepSleep/DeepSleep.ino @@ -12,7 +12,7 @@ void setup() ttgo = TTGOClass::getWatch(); ttgo->begin(); ttgo->openBL(); - ttgo->eTFT->fillScreen(rand() % 0xFFFF); + ttgo->tft->fillScreen(rand() % 0xFFFF); delay(3000); ttgo->power->setPowerOutPut(0xFF, false); ttgo->displaySleep(); diff --git a/examples/Basic unit/DrawSD_BMP/DrawSD_BMP.ino b/examples/Basic unit/DrawSD_BMP/DrawSD_BMP.ino index 8d0c232..bd3b811 100644 --- a/examples/Basic unit/DrawSD_BMP/DrawSD_BMP.ino +++ b/examples/Basic unit/DrawSD_BMP/DrawSD_BMP.ino @@ -15,7 +15,7 @@ void setup() Serial.begin(115200); ttgo = TTGOClass::getWatch(); ttgo->begin(); - tft = ttgo->eTFT; + tft = ttgo->tft; tft->fillScreen(TFT_BLACK); ttgo->openBL(); diff --git a/examples/Basic unit/Motor/Motor.ino b/examples/Basic unit/Motor/Motor.ino index 2ce46ca..9b95560 100644 --- a/examples/Basic unit/Motor/Motor.ino +++ b/examples/Basic unit/Motor/Motor.ino @@ -13,20 +13,20 @@ void setup() ttgo->openBL(); //! begin motor attach to 33 pin , In TWatch-2020 it is IO4 - ttgo->motor_begin(); + ttgo->motor_begin(); - ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->setTextColor(TFT_WHITE, TFT_BLACK); - ttgo->eTFT->drawString("Please touch screen", 50, 100, 2); + ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->setTextColor(TFT_WHITE, TFT_BLACK); + ttgo->tft->drawString("Please touch screen", 50, 100, 2); //attach touch screen interrupt pin - pinMode(TP_INT,INPUT); + pinMode(TP_INT, INPUT); } void loop() { - if(digitalRead(TP_INT) == LOW){ - ttgo->motor->onec(); + if (digitalRead(TP_INT) == LOW) { + ttgo->motor->onec(); } delay(20); } diff --git a/examples/Basic unit/RTC/RTC.ino b/examples/Basic unit/RTC/RTC.ino index 6cafccd..0825458 100644 --- a/examples/Basic unit/RTC/RTC.ino +++ b/examples/Basic unit/RTC/RTC.ino @@ -11,8 +11,8 @@ void setup() ttgo = TTGOClass::getWatch(); ttgo->begin(); ttgo->openBL(); - - ttgo->eTFT->fillScreen(TFT_BLACK); + + ttgo->tft->fillScreen(TFT_BLACK); pinMode(RTC_INT, INPUT_PULLUP); attachInterrupt(RTC_INT, [] { @@ -30,25 +30,25 @@ void setup() void loop() { - ttgo->eTFT->setTextColor(random(0xFFFF)); - ttgo->eTFT->drawString("T-Watch RTC", 50, 50, 4); + ttgo->tft->setTextColor(random(0xFFFF)); + ttgo->tft->drawString("T-Watch RTC", 50, 50, 4); - ttgo->eTFT->setTextColor(TFT_YELLOW, TFT_BLACK); + ttgo->tft->setTextColor(TFT_YELLOW, TFT_BLACK); snprintf(buf, sizeof(buf), "%s", ttgo->rtc->formatDateTime()); - ttgo->eTFT->drawString(buf, 5, 118, 7); + ttgo->tft->drawString(buf, 5, 118, 7); if (rtcIrq) { rtcIrq = 0; detachInterrupt(RTC_INT); ttgo->rtc->resetAlarm(); int i = 3; while (i--) { - ttgo->eTFT->fillScreen(TFT_RED); - ttgo->eTFT->setTextColor(TFT_WHITE, TFT_RED); - ttgo->eTFT->drawString("RTC Alarm", 60, 118, 4); + ttgo->tft->fillScreen(TFT_RED); + ttgo->tft->setTextColor(TFT_WHITE, TFT_RED); + ttgo->tft->drawString("RTC Alarm", 60, 118, 4); delay(500); - ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->setTextColor(TFT_WHITE, TFT_BLACK); - ttgo->eTFT->drawString("RTC Alarm", 60, 118, 4); + ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->setTextColor(TFT_WHITE, TFT_BLACK); + ttgo->tft->drawString("RTC Alarm", 60, 118, 4); delay(500); } } diff --git a/examples/Basic unit/SDCard/SDCard.ino b/examples/Basic unit/SDCard/SDCard.ino index 87f5c5b..dc068a4 100644 --- a/examples/Basic unit/SDCard/SDCard.ino +++ b/examples/Basic unit/SDCard/SDCard.ino @@ -7,36 +7,36 @@ TTGOClass *ttgo; void listDir(fs::FS &fs, const char *dirname, uint8_t levels) { - ttgo->eTFT->setTextColor(TFT_GREEN, TFT_BLACK); - ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->setTextDatum(TL_DATUM); - ttgo->eTFT->setCursor(0, 0); + ttgo->tft->setTextColor(TFT_GREEN, TFT_BLACK); + ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->setTextDatum(TL_DATUM); + ttgo->tft->setCursor(0, 0); - ttgo->eTFT->println("Listing directory:" + String(dirname)); + ttgo->tft->println("Listing directory:" + String(dirname)); File root = fs.open(dirname); if (!root) { - ttgo->eTFT->println("- failed to open directory"); + ttgo->tft->println("- failed to open directory"); return; } if (!root.isDirectory()) { - ttgo->eTFT->println(" - not a directory"); + ttgo->tft->println(" - not a directory"); return; } File file = root.openNextFile(); while (file) { if (file.isDirectory()) { - ttgo->eTFT->print(" DIR : "); - ttgo->eTFT->println(file.name()); + ttgo->tft->print(" DIR : "); + ttgo->tft->println(file.name()); if (levels) { listDir(fs, file.name(), levels - 1); } } else { - ttgo->eTFT->print(" FILE: "); - ttgo->eTFT->print(file.name()); - ttgo->eTFT->print(" SIZE: "); - ttgo->eTFT->println(file.size()); + ttgo->tft->print(" FILE: "); + ttgo->tft->print(file.name()); + ttgo->tft->print(" SIZE: "); + ttgo->tft->println(file.size()); } file = root.openNextFile(); } @@ -76,7 +76,7 @@ void setup() uint64_t cardSize = SD.cardSize() / (1024 * 1024); Serial.printf("SD Card Size: %lluMB\n", cardSize); - ttgo->eTFT->fillScreen(TFT_BLACK); + ttgo->tft->fillScreen(TFT_BLACK); listDir(SD, "/", 2); } diff --git a/examples/Basic unit/TouchPad/TouchPad.ino b/examples/Basic unit/TouchPad/TouchPad.ino index 811172d..5c1eb14 100644 --- a/examples/Basic unit/TouchPad/TouchPad.ino +++ b/examples/Basic unit/TouchPad/TouchPad.ino @@ -12,10 +12,10 @@ void setup() ttgo = TTGOClass::getWatch(); ttgo->begin(); ttgo->openBL(); - ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->setTextFont(2); - ttgo->eTFT->setTextColor(TFT_WHITE, TFT_BLACK); - ttgo->eTFT->drawString("T-Watch Touch Test", 62, 90); + ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->setTextFont(2); + ttgo->tft->setTextColor(TFT_WHITE, TFT_BLACK); + ttgo->tft->drawString("T-Watch Touch Test", 62, 90); } void loop() @@ -23,7 +23,7 @@ void loop() if (ttgo->touch->touched()) { TP_Point p = ttgo->touch->getPoint(); sprintf(buf, "x:%03d y:%03d", p.x, p.y); - ttgo->eTFT->drawString(buf, 80, 118); + ttgo->tft->drawString(buf, 80, 118); } delay(5); } diff --git a/examples/Basic unit/UserButton/UserButton.ino b/examples/Basic unit/UserButton/UserButton.ino index 28c7400..136cbab 100644 --- a/examples/Basic unit/UserButton/UserButton.ino +++ b/examples/Basic unit/UserButton/UserButton.ino @@ -8,16 +8,16 @@ TTGOClass *ttgo; void pressed() { uint16_t color = random(0xFFFF); - ttgo->eTFT->fillScreen(color); - ttgo->eTFT->setTextColor(color, TFT_WHITE); - ttgo->eTFT->drawString("User Button pressed", 5, 100, 4); + ttgo->tft->fillScreen(color); + ttgo->tft->setTextColor(color, TFT_WHITE); + ttgo->tft->drawString("User Button pressed", 5, 100, 4); } void released() { uint16_t color = random(0xFFFF); - ttgo->eTFT->fillScreen(color); - ttgo->eTFT->setTextColor(color, TFT_WHITE); - ttgo->eTFT->drawString("User Button released", 5, 100, 4); + ttgo->tft->fillScreen(color); + ttgo->tft->setTextColor(color, TFT_WHITE); + ttgo->tft->drawString("User Button released", 5, 100, 4); } void setup() @@ -27,10 +27,10 @@ void setup() ttgo->begin(); ttgo->openBL(); - ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->setTextColor(TFT_WHITE, TFT_BLACK); - ttgo->eTFT->setTextFont(4); - ttgo->eTFT->drawString("User Button released", 5, 100, 4); + ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->setTextColor(TFT_WHITE, TFT_BLACK); + ttgo->tft->setTextFont(4); + ttgo->tft->drawString("User Button released", 5, 100, 4); ttgo->button->setPressedHandler(pressed); ttgo->button->setReleasedHandler(released); diff --git a/examples/Module/Fingerprint/Fingerprint.ino b/examples/Module/Fingerprint/Fingerprint.ino index eb33032..ed4e788 100644 --- a/examples/Module/Fingerprint/Fingerprint.ino +++ b/examples/Module/Fingerprint/Fingerprint.ino @@ -44,7 +44,7 @@ void setup() watch->begin(); - tft = watch->eTFT; + tft = watch->tft; tft->setTextFont(2); diff --git a/examples/Module/VEMl6075/VEMl6075.ino b/examples/Module/VEMl6075/VEMl6075.ino index 23da630..05caf14 100644 --- a/examples/Module/VEMl6075/VEMl6075.ino +++ b/examples/Module/VEMl6075/VEMl6075.ino @@ -20,7 +20,7 @@ void setup(void) ttgo->begin(); - tft = ttgo->eTFT; + tft = ttgo->tft; tft->fillScreen(TFT_BLACK); diff --git a/examples/Module/VEMl6075_LVGL/VEMl6075_LVGL.ino b/examples/Module/VEMl6075_LVGL/VEMl6075_LVGL.ino index a953f3e..210b401 100644 --- a/examples/Module/VEMl6075_LVGL/VEMl6075_LVGL.ino +++ b/examples/Module/VEMl6075_LVGL/VEMl6075_LVGL.ino @@ -27,7 +27,7 @@ void setup(void) ttgo->begin(); - tft = ttgo->eTFT; + tft = ttgo->tft; tft->fillScreen(TFT_BLACK); diff --git a/examples/Other/AlarmClock/AlarmClock.ino b/examples/Other/AlarmClock/AlarmClock.ino index 6974387..7433e69 100644 --- a/examples/Other/AlarmClock/AlarmClock.ino +++ b/examples/Other/AlarmClock/AlarmClock.ino @@ -31,12 +31,12 @@ void setup(void) ttgo->begin(); ttgo->openBL(); - ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->setTextFont(2); + ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->setTextFont(2); - ttgo->eTFT->setCursor(0, 0); - ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->println("Sample alarm clock begins"); + ttgo->tft->setCursor(0, 0); + ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->println("Sample alarm clock begins"); file = new AudioFileSourcePROGMEM(pika, sizeof(pika)); id3 = new AudioFileSourceID3(file); @@ -62,8 +62,8 @@ void loop(void) if (!mp3->loop()) mp3->stop(); } else { - ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->println("alarm clock play done , sleep now .."); + ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->println("alarm clock play done , sleep now .."); delay(1000); diff --git a/examples/Other/FlappyBird/FlappyBird.ino b/examples/Other/FlappyBird/FlappyBird.ino index 5925377..d38dd48 100644 --- a/examples/Other/FlappyBird/FlappyBird.ino +++ b/examples/Other/FlappyBird/FlappyBird.ino @@ -92,7 +92,7 @@ static short tmpx, tmpy; // --------------- // faster drawPixel method by inlining calls and using setAddrWindow and pushColor // using macro to force inlining -#define drawPixel(a, b, c) ttgo->eTFT->setAddrWindow(a, b, a, b); ttgo->eTFT->pushColor(c) +#define drawPixel(a, b, c) ttgo->tft->setAddrWindow(a, b, a, b); ttgo->tft->pushColor(c) void setup() @@ -126,14 +126,14 @@ void game_loop() unsigned char GAMEH = TFTH - FLOORH; // draw the floor once, we will not overwrite on this area in-game // black line - ttgo->eTFT->drawFastHLine(0, GAMEH, TFTW, TFT_BLACK); + ttgo->tft->drawFastHLine(0, GAMEH, TFTW, TFT_BLACK); // grass and stripe - ttgo->eTFT->fillRect(0, GAMEH + 1, TFTW2, GRASSH, GRASSCOL); - ttgo->eTFT->fillRect(TFTW2, GAMEH + 1, TFTW2, GRASSH, GRASSCOL2); + ttgo->tft->fillRect(0, GAMEH + 1, TFTW2, GRASSH, GRASSCOL); + ttgo->tft->fillRect(TFTW2, GAMEH + 1, TFTW2, GRASSH, GRASSCOL2); // black line - ttgo->eTFT->drawFastHLine(0, GAMEH + GRASSH, TFTW, TFT_BLACK); + ttgo->tft->drawFastHLine(0, GAMEH + GRASSH, TFTW, TFT_BLACK); // mud - ttgo->eTFT->fillRect(0, GAMEH + GRASSH + 1, TFTW, FLOORH - GRASSH, FLOORCOL); + ttgo->tft->fillRect(0, GAMEH + GRASSH + 1, TFTW, FLOORH - GRASSH, FLOORCOL); // grass x position (for stripe animation) long grassx = TFTW; // game loop time variables @@ -193,11 +193,11 @@ void game_loop() // we save cycles if we avoid drawing the pipe when outside the screen if (pipes.x >= 0 && pipes.x < TFTW) { // pipe color - ttgo->eTFT->drawFastVLine(pipes.x + 3, 0, pipes.gap_y, PIPECOL); - ttgo->eTFT->drawFastVLine(pipes.x + 3, pipes.gap_y + GAPHEIGHT + 1, GAMEH - (pipes.gap_y + GAPHEIGHT + 1), PIPECOL); + ttgo->tft->drawFastVLine(pipes.x + 3, 0, pipes.gap_y, PIPECOL); + ttgo->tft->drawFastVLine(pipes.x + 3, pipes.gap_y + GAPHEIGHT + 1, GAMEH - (pipes.gap_y + GAPHEIGHT + 1), PIPECOL); // highlight - ttgo->eTFT->drawFastVLine(pipes.x, 0, pipes.gap_y, PIPEHIGHCOL); - ttgo->eTFT->drawFastVLine(pipes.x, pipes.gap_y + GAPHEIGHT + 1, GAMEH - (pipes.gap_y + GAPHEIGHT + 1), PIPEHIGHCOL); + ttgo->tft->drawFastVLine(pipes.x, 0, pipes.gap_y, PIPEHIGHCOL); + ttgo->tft->drawFastVLine(pipes.x, pipes.gap_y + GAPHEIGHT + 1, GAMEH - (pipes.gap_y + GAPHEIGHT + 1), PIPEHIGHCOL); // bottom and top border of pipe drawPixel(pipes.x, pipes.gap_y, PIPESEAMCOL); drawPixel(pipes.x, pipes.gap_y + GAPHEIGHT, PIPESEAMCOL); @@ -208,7 +208,7 @@ void game_loop() drawPixel(pipes.x + 3, pipes.gap_y + GAPHEIGHT + 6, PIPESEAMCOL); } // erase behind pipe - if (pipes.x <= TFTW) ttgo->eTFT->drawFastVLine(pipes.x + PIPEW, 0, GAMEH, BCKGRDCOL); + if (pipes.x <= TFTW) ttgo->tft->drawFastVLine(pipes.x + PIPEW, 0, GAMEH, BCKGRDCOL); // bird // --------------- @@ -235,8 +235,8 @@ void game_loop() // --------------- grassx -= SPEED; if (grassx < 0) grassx = TFTW; - ttgo->eTFT->drawFastVLine( grassx % TFTW, GAMEH + 1, GRASSH - 1, GRASSCOL); - ttgo->eTFT->drawFastVLine((grassx + 64) % TFTW, GAMEH + 1, GRASSH - 1, GRASSCOL2); + ttgo->tft->drawFastVLine( grassx % TFTW, GAMEH + 1, GRASSH - 1, GRASSCOL); + ttgo->tft->drawFastVLine((grassx + 64) % TFTW, GAMEH + 1, GRASSH - 1, GRASSCOL2); // =============== // collision @@ -253,19 +253,19 @@ void game_loop() else if (bird.x > pipes.x + PIPEW - BIRDW && passed_pipe) { passed_pipe = false; // erase score with background color - ttgo->eTFT->setTextColor(BCKGRDCOL); - ttgo->eTFT->setCursor( TFTW2, 4); - ttgo->eTFT->print(score); + ttgo->tft->setTextColor(BCKGRDCOL); + ttgo->tft->setCursor( TFTW2, 4); + ttgo->tft->print(score); // set text color back to white for new score - ttgo->eTFT->setTextColor(TFT_WHITE); + ttgo->tft->setTextColor(TFT_WHITE); // increase score since we successfully passed a pipe score++; } // update score // --------------- - ttgo->eTFT->setCursor( TFTW2, 4); - ttgo->eTFT->print(score); + ttgo->tft->setCursor( TFTW2, 4); + ttgo->tft->print(score); } // add a small delay to show how the player lost @@ -278,23 +278,23 @@ void game_loop() // --------------- void game_start() { - ttgo->eTFT->setTextFont(1); - ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->fillRect(10, TFTH2 - 20, TFTW - 20, 1, TFT_WHITE); - ttgo->eTFT->fillRect(10, TFTH2 + 32, TFTW - 20, 1, TFT_WHITE); - ttgo->eTFT->setTextColor(TFT_WHITE); - ttgo->eTFT->setTextSize(3); + ttgo->tft->setTextFont(1); + ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->fillRect(10, TFTH2 - 20, TFTW - 20, 1, TFT_WHITE); + ttgo->tft->fillRect(10, TFTH2 + 32, TFTW - 20, 1, TFT_WHITE); + ttgo->tft->setTextColor(TFT_WHITE); + ttgo->tft->setTextSize(3); // half width - num char * char width in pixels - ttgo->eTFT->setCursor( TFTW2 - (6 * 9), TFTH2 - 16); - ttgo->eTFT->println("FLAPPY"); - ttgo->eTFT->setTextSize(3); - ttgo->eTFT->setCursor( TFTW2 - (6 * 9), TFTH2 + 8); - ttgo->eTFT->println("-BIRD-"); - ttgo->eTFT->setTextSize(2); - ttgo->eTFT->setCursor( 10, TFTH2 - 36); - ttgo->eTFT->println("T-Watch"); - ttgo->eTFT->setCursor( TFTW2 - (17 * 9), TFTH2 + 36); - ttgo->eTFT->println("Premi il bottone centrale"); + ttgo->tft->setCursor( TFTW2 - (6 * 9), TFTH2 - 16); + ttgo->tft->println("FLAPPY"); + ttgo->tft->setTextSize(3); + ttgo->tft->setCursor( TFTW2 - (6 * 9), TFTH2 + 8); + ttgo->tft->println("-BIRD-"); + ttgo->tft->setTextSize(2); + ttgo->tft->setCursor( 10, TFTH2 - 36); + ttgo->tft->println("T-Watch"); + ttgo->tft->setCursor( TFTW2 - (17 * 9), TFTH2 + 36); + ttgo->tft->println("Premi il bottone centrale"); while (1) { delay(1000); // wait for push button @@ -311,7 +311,7 @@ void game_start() void game_init() { // clear screen - ttgo->eTFT->fillScreen(BCKGRDCOL); + ttgo->tft->fillScreen(BCKGRDCOL); // reset score score = 0; // init bird @@ -332,32 +332,32 @@ void game_init() // --------------- void game_over() { - ttgo->eTFT->fillScreen(TFT_BLACK); + ttgo->tft->fillScreen(TFT_BLACK); EEPROM_Read(&maxScore, 0); if (score > maxScore) { EEPROM_Write(&score, 0); maxScore = score; - ttgo->eTFT->setTextColor(TFT_RED); - ttgo->eTFT->setTextSize(2); - ttgo->eTFT->setCursor( TFTW2 - (13 * 6), TFTH2 - 26); - ttgo->eTFT->println("NEW HIGHSCORE"); + ttgo->tft->setTextColor(TFT_RED); + ttgo->tft->setTextSize(2); + ttgo->tft->setCursor( TFTW2 - (13 * 6), TFTH2 - 26); + ttgo->tft->println("NEW HIGHSCORE"); } - ttgo->eTFT->setTextColor(TFT_WHITE); - ttgo->eTFT->setTextSize(3); + ttgo->tft->setTextColor(TFT_WHITE); + ttgo->tft->setTextSize(3); // half width - num char * char width in pixels - ttgo->eTFT->setCursor( TFTW2 - (9 * 9), TFTH2 - 6); - ttgo->eTFT->println("GAME OVER"); - ttgo->eTFT->setTextSize(2); - ttgo->eTFT->setCursor( 10, 10); - ttgo->eTFT->print("score: "); - ttgo->eTFT->print(score); - ttgo->eTFT->setCursor( TFTW2 - (12 * 6), TFTH2 + 18); - ttgo->eTFT->println("press button"); - ttgo->eTFT->setCursor( 10, 28); - ttgo->eTFT->print("Max Score:"); - ttgo->eTFT->print(maxScore); + ttgo->tft->setCursor( TFTW2 - (9 * 9), TFTH2 - 6); + ttgo->tft->println("GAME OVER"); + ttgo->tft->setTextSize(2); + ttgo->tft->setCursor( 10, 10); + ttgo->tft->print("score: "); + ttgo->tft->print(score); + ttgo->tft->setCursor( TFTW2 - (12 * 6), TFTH2 + 18); + ttgo->tft->println("press button"); + ttgo->tft->setCursor( 10, 28); + ttgo->tft->print("Max Score:"); + ttgo->tft->print(maxScore); while (1) { // wait for push button if (ttgo->button->isPressed()) { diff --git a/examples/Other/IOTA_Price/IOTA_Price.ino b/examples/Other/IOTA_Price/IOTA_Price.ino index 3692426..de1b886 100644 --- a/examples/Other/IOTA_Price/IOTA_Price.ino +++ b/examples/Other/IOTA_Price/IOTA_Price.ino @@ -49,7 +49,7 @@ void setup() ttgo->begin(); ttgo->openBL(); ttgo->lvgl_begin(); - tft = ttgo->eTFT; + tft = ttgo->tft; uint16_t time = millis(); time = millis() - time; diff --git a/examples/Shield/BBQKeyboard/BBQKeyboard.ino b/examples/Shield/BBQKeyboard/BBQKeyboard.ino index bb8874a..bce50de 100644 --- a/examples/Shield/BBQKeyboard/BBQKeyboard.ino +++ b/examples/Shield/BBQKeyboard/BBQKeyboard.ino @@ -34,7 +34,7 @@ void setup() ttgo = TTGOClass::getWatch(); ttgo->begin(); - tft = ttgo->eTFT; + tft = ttgo->tft; tft->fillScreen(TFT_BLACK); ttgo->openBL(); tft->setTextFont(2); diff --git a/examples/Shield/GameControl/GameControl.ino b/examples/Shield/GameControl/GameControl.ino index 60f5f9e..e8cfece 100644 --- a/examples/Shield/GameControl/GameControl.ino +++ b/examples/Shield/GameControl/GameControl.ino @@ -3,12 +3,12 @@ TTGOClass *ttgo; -void pressed(const char * str) +void pressed(const char *str) { uint16_t color = random(0xFFFF); - ttgo->eTFT->fillScreen(color); - ttgo->eTFT->setTextColor(color, TFT_WHITE); - ttgo->eTFT->drawString(str, 80, 100, 4); + ttgo->tft->fillScreen(color); + ttgo->tft->setTextColor(color, TFT_WHITE); + ttgo->tft->drawString(str, 80, 100, 4); } void setup() @@ -18,9 +18,9 @@ void setup() ttgo->begin(); ttgo->openBL(); ttgo->gameControlBegin(); - ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->setTextColor(TFT_WHITE, TFT_BLACK); - ttgo->eTFT->setTextFont(4); + ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->setTextColor(TFT_WHITE, TFT_BLACK); + ttgo->tft->setTextFont(4); } void loop() diff --git a/examples/Shield/HeartRate/HeartRate.ino b/examples/Shield/HeartRate/HeartRate.ino index 471cde1..b3b0182 100644 --- a/examples/Shield/HeartRate/HeartRate.ino +++ b/examples/Shield/HeartRate/HeartRate.ino @@ -14,7 +14,7 @@ git clone https://github.com/sparkfun/SparkFun_MAX3010x_Sensor_Library TTGOClass *ttgo; MAX30105 particleSensor; -const uint8_t RATE_SIZE = 20; //Increase this for more averaging. +const uint8_t RATE_SIZE = 20; //Increase this for more averaging. uint8_t rates[RATE_SIZE]; //Array of heart rates uint8_t rateSpot = 0; long lastBeat = 0; //Time at which the last beat occurred @@ -31,10 +31,10 @@ void setup() ttgo = TTGOClass::getWatch(); ttgo->begin(); ttgo->openBL(); - ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->setTextColor(TFT_WHITE, TFT_BLACK); - ttgo->eTFT->setTextFont(4); - ttgo->eTFT->drawCentreString("T-Watch HeartRate", 120, 60, 2); + ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->setTextColor(TFT_WHITE, TFT_BLACK); + ttgo->tft->setTextFont(4); + ttgo->tft->drawCentreString("T-Watch HeartRate", 120, 60, 2); // Initialize sensor if (!particleSensor.begin(Wire, I2C_SPEED_FAST)) { //Use default I2C port, 400kHz speed @@ -80,11 +80,11 @@ void loop() if (prevBPM != beatAvg) { prevBPM = beatAvg; - ttgo->eTFT->setTextColor(TFT_GREEN); + ttgo->tft->setTextColor(TFT_GREEN); static char buffer[256]; - ttgo->eTFT->fillRect(0, 120, 240, 30, TFT_RED); + ttgo->tft->fillRect(0, 120, 240, 30, TFT_RED); snprintf(buffer, sizeof(buffer), "Avg BPM:%d", beatAvg); - ttgo->eTFT->drawCentreString(buffer, 240 / 2, 120, 2); + ttgo->tft->drawCentreString(buffer, 240 / 2, 120, 2); } particleSensor.nextSample(); //We're finished with this sample so move to next sample } diff --git a/examples/Shield/LoRa_SX127x/LoRa_SX127x.ino b/examples/Shield/LoRa_SX127x/LoRa_SX127x.ino index c2379cd..f54fd03 100644 --- a/examples/Shield/LoRa_SX127x/LoRa_SX127x.ino +++ b/examples/Shield/LoRa_SX127x/LoRa_SX127x.ino @@ -119,7 +119,7 @@ void setup(void) ttgo = TTGOClass::getWatch(); ttgo->begin(); - ttgo->eTFT->fillScreen(TFT_BLACK); + ttgo->tft->fillScreen(TFT_BLACK); ttgo->openBL(); ttgo->lvgl_begin(); diff --git a/examples/Shield/M6_GPS/M6_GPS.ino b/examples/Shield/M6_GPS/M6_GPS.ino index 7d86e5c..40333c0 100644 --- a/examples/Shield/M6_GPS/M6_GPS.ino +++ b/examples/Shield/M6_GPS/M6_GPS.ino @@ -14,7 +14,7 @@ void setup(void) ttgo->begin(); ttgo->openBL(); //! Create a new pointer to save the display object - tft = ttgo->eTFT; + tft = ttgo->tft; tft->fillScreen(TFT_BLACK); tft->setTextFont(2); diff --git a/examples/Shield/NFC_Lock/NFC_Lock.ino b/examples/Shield/NFC_Lock/NFC_Lock.ino index cb04349..728fbcd 100644 --- a/examples/Shield/NFC_Lock/NFC_Lock.ino +++ b/examples/Shield/NFC_Lock/NFC_Lock.ino @@ -18,7 +18,7 @@ void setup(void) ttgo->begin(); ttgo->openBL(); //! Create a new pointer to save the display object - tft = ttgo->eTFT; + tft = ttgo->tft; tft->fillScreen(TFT_BLACK); tft->setTextFont(2); diff --git a/examples/Shield/S7xG_GPS/S7xG_GPS.ino b/examples/Shield/S7xG_GPS/S7xG_GPS.ino index 27cb755..ce72418 100644 --- a/examples/Shield/S7xG_GPS/S7xG_GPS.ino +++ b/examples/Shield/S7xG_GPS/S7xG_GPS.ino @@ -13,7 +13,7 @@ void setup(void) ttgo->begin(); ttgo->openBL(); //! Create a new pointer to save the display object - tft = ttgo->eTFT; + tft = ttgo->tft; tft->fillScreen(TFT_BLACK); tft->setTextFont(2); @@ -49,7 +49,7 @@ void setup(void) s7xg->gpsSetPortUplink(20); s7xg->gpsSetFormatUplink(1); s7xg->gpsSetMode(1); - + tft->setCursor(0, 0); tft->fillScreen(TFT_BLACK); tft->println("Positioning..."); diff --git a/examples/Shield/S7xG_LoRa/S7xG_LoRa.ino b/examples/Shield/S7xG_LoRa/S7xG_LoRa.ino index 1f49358..9e29b23 100644 --- a/examples/Shield/S7xG_LoRa/S7xG_LoRa.ino +++ b/examples/Shield/S7xG_LoRa/S7xG_LoRa.ino @@ -173,7 +173,7 @@ void setup(void) ttgo = TTGOClass::getWatch(); ttgo->begin(); - ttgo->eTFT->fillScreen(TFT_BLACK); + ttgo->tft->fillScreen(TFT_BLACK); ttgo->openBL(); ttgo->lvgl_begin(); diff --git a/examples/TFT_eSPI/All_Free_Fonts_Demo/All_Free_Fonts_Demo.ino b/examples/TFT_eSPI/All_Free_Fonts_Demo/All_Free_Fonts_Demo.ino index 9d2cab4..387bc17 100644 --- a/examples/TFT_eSPI/All_Free_Fonts_Demo/All_Free_Fonts_Demo.ino +++ b/examples/TFT_eSPI/All_Free_Fonts_Demo/All_Free_Fonts_Demo.ino @@ -38,14 +38,18 @@ ######################################################################### */ -#define TEXT "aA MWyz~12" // Text that will be printed on screen in any font +// => Hardware select +// #define LILYGO_WATCH_2019_WITH_TOUCH // To use T-Watch2019 with touchscreen, please uncomment this line +// #define LILYGO_WATCH_2019_NO_TOUCH // To use T-Watch2019 Not touchscreen , please uncomment this line +// #define LILYGO_WATCH_2020_V1 //To use T-Watch2020, please uncomment this line + +#include #include "Free_Fonts.h" // Include the header file attached to this sketch -#include - TTGOClass *ttgo; +#define TEXT "aA MWyz~12" // Text that will be printed on screen in any font unsigned long drawTime = 0; @@ -67,309 +71,309 @@ void loop() // the smaller one with the background colour. // Set text datum to middle centre - ttgo->eTFT->setTextDatum(MC_DATUM); + ttgo->tft->setTextDatum(MC_DATUM); // Set text colour to orange with black background - ttgo->eTFT->setTextColor(TFT_WHITE, TFT_BLACK); + ttgo->tft->setTextColor(TFT_WHITE, TFT_BLACK); - ttgo->eTFT->fillScreen(TFT_BLACK); // Clear screen - ttgo->eTFT->setFreeFont(FF18); // Select the font - ttgo->eTFT->drawString(sFF1, 160, 60, GFXFF);// Print the string name of the font - ttgo->eTFT->setFreeFont(FF1); // Select the font - ttgo->eTFT->drawString(TEXT, 160, 120, GFXFF);// Print the string name of the font + ttgo->tft->fillScreen(TFT_BLACK); // Clear screen + ttgo->tft->setFreeFont(FF18); // Select the font + ttgo->tft->drawString(sFF1, 160, 60, GFXFF);// Print the string name of the font + ttgo->tft->setFreeFont(FF1); // Select the font + ttgo->tft->drawString(TEXT, 160, 120, GFXFF);// Print the string name of the font delay(1000); - //ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->setFreeFont(FF18); // Select the font - ttgo->eTFT->drawString(sFF2, 160, 60, GFXFF);// Print the string name of the font - ttgo->eTFT->setFreeFont(FF2); - ttgo->eTFT->drawString(TEXT, 160, 120, GFXFF); + //ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->setFreeFont(FF18); // Select the font + ttgo->tft->drawString(sFF2, 160, 60, GFXFF);// Print the string name of the font + ttgo->tft->setFreeFont(FF2); + ttgo->tft->drawString(TEXT, 160, 120, GFXFF); delay(1000); - //ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->setFreeFont(FF18); // Select the font - ttgo->eTFT->drawString(sFF3, 160, 60, GFXFF);// Print the string name of the font - ttgo->eTFT->setFreeFont(FF3); - ttgo->eTFT->drawString(TEXT, 160, 120, GFXFF); + //ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->setFreeFont(FF18); // Select the font + ttgo->tft->drawString(sFF3, 160, 60, GFXFF);// Print the string name of the font + ttgo->tft->setFreeFont(FF3); + ttgo->tft->drawString(TEXT, 160, 120, GFXFF); delay(1000); - //ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->setFreeFont(FF18); // Select the font - ttgo->eTFT->drawString(sFF4, 160, 60, GFXFF);// Print the string name of the font - ttgo->eTFT->setFreeFont(FF4); - ttgo->eTFT->drawString(TEXT, 160, 120, GFXFF); + //ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->setFreeFont(FF18); // Select the font + ttgo->tft->drawString(sFF4, 160, 60, GFXFF);// Print the string name of the font + ttgo->tft->setFreeFont(FF4); + ttgo->tft->drawString(TEXT, 160, 120, GFXFF); delay(1000); - ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->setFreeFont(FF18); // Select the font - ttgo->eTFT->drawString(sFF5, 160, 60, GFXFF);// Print the string name of the font - ttgo->eTFT->setFreeFont(FF5); - ttgo->eTFT->drawString(TEXT, 160, 120, GFXFF); + ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->setFreeFont(FF18); // Select the font + ttgo->tft->drawString(sFF5, 160, 60, GFXFF);// Print the string name of the font + ttgo->tft->setFreeFont(FF5); + ttgo->tft->drawString(TEXT, 160, 120, GFXFF); delay(1000); - //ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->setFreeFont(FF18); // Select the font - ttgo->eTFT->drawString(sFF6, 160, 60, GFXFF);// Print the string name of the font - ttgo->eTFT->setFreeFont(FF6); - ttgo->eTFT->drawString(TEXT, 160, 120, GFXFF); + //ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->setFreeFont(FF18); // Select the font + ttgo->tft->drawString(sFF6, 160, 60, GFXFF);// Print the string name of the font + ttgo->tft->setFreeFont(FF6); + ttgo->tft->drawString(TEXT, 160, 120, GFXFF); delay(1000); - //ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->setFreeFont(FF18); // Select the font - ttgo->eTFT->drawString(sFF7, 160, 60, GFXFF);// Print the string name of the font - ttgo->eTFT->setFreeFont(FF7); - ttgo->eTFT->drawString(TEXT, 160, 120, GFXFF); + //ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->setFreeFont(FF18); // Select the font + ttgo->tft->drawString(sFF7, 160, 60, GFXFF);// Print the string name of the font + ttgo->tft->setFreeFont(FF7); + ttgo->tft->drawString(TEXT, 160, 120, GFXFF); delay(1000); - //ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->setFreeFont(FF18); // Select the font - ttgo->eTFT->drawString(sFF8, 160, 60, GFXFF);// Print the string name of the font - ttgo->eTFT->setFreeFont(FF8); - ttgo->eTFT->drawString(TEXT, 160, 120, GFXFF); + //ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->setFreeFont(FF18); // Select the font + ttgo->tft->drawString(sFF8, 160, 60, GFXFF);// Print the string name of the font + ttgo->tft->setFreeFont(FF8); + ttgo->tft->drawString(TEXT, 160, 120, GFXFF); delay(1000); - ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->setFreeFont(FF18); // Select the font - ttgo->eTFT->drawString(sFF9, 160, 60, GFXFF);// Print the string name of the font - ttgo->eTFT->setFreeFont(FF9); - ttgo->eTFT->drawString(TEXT, 160, 120, GFXFF); + ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->setFreeFont(FF18); // Select the font + ttgo->tft->drawString(sFF9, 160, 60, GFXFF);// Print the string name of the font + ttgo->tft->setFreeFont(FF9); + ttgo->tft->drawString(TEXT, 160, 120, GFXFF); delay(1000); - //ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->setFreeFont(FF18); // Select the font - ttgo->eTFT->drawString(sFF10, 160, 60, GFXFF);// Print the string name of the font - ttgo->eTFT->setFreeFont(FF10); - ttgo->eTFT->drawString(TEXT, 160, 120, GFXFF); + //ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->setFreeFont(FF18); // Select the font + ttgo->tft->drawString(sFF10, 160, 60, GFXFF);// Print the string name of the font + ttgo->tft->setFreeFont(FF10); + ttgo->tft->drawString(TEXT, 160, 120, GFXFF); delay(1000); - //ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->setFreeFont(FF18); // Select the font - ttgo->eTFT->drawString(sFF11, 160, 60, GFXFF);// Print the string name of the font - ttgo->eTFT->setFreeFont(FF11); - ttgo->eTFT->drawString(TEXT, 160, 120, GFXFF); + //ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->setFreeFont(FF18); // Select the font + ttgo->tft->drawString(sFF11, 160, 60, GFXFF);// Print the string name of the font + ttgo->tft->setFreeFont(FF11); + ttgo->tft->drawString(TEXT, 160, 120, GFXFF); delay(1000); - //ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->setFreeFont(FF18); // Select the font - ttgo->eTFT->drawString(sFF12, 160, 60, GFXFF);// Print the string name of the font - ttgo->eTFT->setFreeFont(FF12); - ttgo->eTFT->drawString(TEXT, 160, 120, GFXFF); + //ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->setFreeFont(FF18); // Select the font + ttgo->tft->drawString(sFF12, 160, 60, GFXFF);// Print the string name of the font + ttgo->tft->setFreeFont(FF12); + ttgo->tft->drawString(TEXT, 160, 120, GFXFF); delay(1000); - ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->setFreeFont(FF18); // Select the font - ttgo->eTFT->drawString(sFF13, 160, 60, GFXFF);// Print the string name of the font - ttgo->eTFT->setFreeFont(FF13); - ttgo->eTFT->drawString(TEXT, 160, 120, GFXFF); + ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->setFreeFont(FF18); // Select the font + ttgo->tft->drawString(sFF13, 160, 60, GFXFF);// Print the string name of the font + ttgo->tft->setFreeFont(FF13); + ttgo->tft->drawString(TEXT, 160, 120, GFXFF); delay(1000); - //ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->setFreeFont(FF18); // Select the font - ttgo->eTFT->drawString(sFF14, 160, 60, GFXFF);// Print the string name of the font - ttgo->eTFT->setFreeFont(FF14); - ttgo->eTFT->drawString(TEXT, 160, 120, GFXFF); + //ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->setFreeFont(FF18); // Select the font + ttgo->tft->drawString(sFF14, 160, 60, GFXFF);// Print the string name of the font + ttgo->tft->setFreeFont(FF14); + ttgo->tft->drawString(TEXT, 160, 120, GFXFF); delay(1000); - //ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->setFreeFont(FF18); // Select the font - ttgo->eTFT->drawString(sFF15, 160, 60, GFXFF);// Print the string name of the font - ttgo->eTFT->setFreeFont(FF15); - ttgo->eTFT->drawString(TEXT, 160, 120, GFXFF); + //ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->setFreeFont(FF18); // Select the font + ttgo->tft->drawString(sFF15, 160, 60, GFXFF);// Print the string name of the font + ttgo->tft->setFreeFont(FF15); + ttgo->tft->drawString(TEXT, 160, 120, GFXFF); delay(1000); - //ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->setFreeFont(FF18); // Select the font - ttgo->eTFT->drawString(sFF16, 160, 60, GFXFF);// Print the string name of the font - ttgo->eTFT->setFreeFont(FF16); - ttgo->eTFT->drawString(TEXT, 160, 120, GFXFF); + //ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->setFreeFont(FF18); // Select the font + ttgo->tft->drawString(sFF16, 160, 60, GFXFF);// Print the string name of the font + ttgo->tft->setFreeFont(FF16); + ttgo->tft->drawString(TEXT, 160, 120, GFXFF); delay(1000); - ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->setFreeFont(FF18); // Select the font - ttgo->eTFT->drawString(sFF17, 160, 60, GFXFF);// Print the string name of the font - ttgo->eTFT->setFreeFont(FF17); - ttgo->eTFT->drawString(TEXT, 160, 120, GFXFF); + ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->setFreeFont(FF18); // Select the font + ttgo->tft->drawString(sFF17, 160, 60, GFXFF);// Print the string name of the font + ttgo->tft->setFreeFont(FF17); + ttgo->tft->drawString(TEXT, 160, 120, GFXFF); delay(1000); - //ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->setFreeFont(FF18); // Select the font - ttgo->eTFT->drawString(sFF18, 160, 60, GFXFF);// Print the string name of the font - ttgo->eTFT->setFreeFont(FF18); - ttgo->eTFT->drawString(TEXT, 160, 120, GFXFF); + //ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->setFreeFont(FF18); // Select the font + ttgo->tft->drawString(sFF18, 160, 60, GFXFF);// Print the string name of the font + ttgo->tft->setFreeFont(FF18); + ttgo->tft->drawString(TEXT, 160, 120, GFXFF); delay(1000); - //ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->setFreeFont(FF18); // Select the font - ttgo->eTFT->drawString(sFF19, 160, 60, GFXFF);// Print the string name of the font - ttgo->eTFT->setFreeFont(FF19); - ttgo->eTFT->drawString(TEXT, 160, 120, GFXFF); + //ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->setFreeFont(FF18); // Select the font + ttgo->tft->drawString(sFF19, 160, 60, GFXFF);// Print the string name of the font + ttgo->tft->setFreeFont(FF19); + ttgo->tft->drawString(TEXT, 160, 120, GFXFF); delay(1000); - //ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->setFreeFont(FF18); // Select the font - ttgo->eTFT->drawString(sFF20, 160, 60, GFXFF);// Print the string name of the font - ttgo->eTFT->setFreeFont(FF20); - ttgo->eTFT->drawString(TEXT, 160, 120, GFXFF); + //ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->setFreeFont(FF18); // Select the font + ttgo->tft->drawString(sFF20, 160, 60, GFXFF);// Print the string name of the font + ttgo->tft->setFreeFont(FF20); + ttgo->tft->drawString(TEXT, 160, 120, GFXFF); delay(1000); - ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->setFreeFont(FF18); // Select the font - ttgo->eTFT->drawString(sFF21, 160, 60, GFXFF);// Print the string name of the font - ttgo->eTFT->setFreeFont(FF21); - ttgo->eTFT->drawString(TEXT, 160, 120, GFXFF); + ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->setFreeFont(FF18); // Select the font + ttgo->tft->drawString(sFF21, 160, 60, GFXFF);// Print the string name of the font + ttgo->tft->setFreeFont(FF21); + ttgo->tft->drawString(TEXT, 160, 120, GFXFF); delay(1000); - //ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->setFreeFont(FF18); // Select the font - ttgo->eTFT->drawString(sFF22, 160, 60, GFXFF);// Print the string name of the font - ttgo->eTFT->setFreeFont(FF22); - ttgo->eTFT->drawString(TEXT, 160, 120, GFXFF); + //ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->setFreeFont(FF18); // Select the font + ttgo->tft->drawString(sFF22, 160, 60, GFXFF);// Print the string name of the font + ttgo->tft->setFreeFont(FF22); + ttgo->tft->drawString(TEXT, 160, 120, GFXFF); delay(1000); - //ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->setFreeFont(FF18); // Select the font - ttgo->eTFT->drawString(sFF23, 160, 60, GFXFF);// Print the string name of the font - ttgo->eTFT->setFreeFont(FF23); - ttgo->eTFT->drawString(TEXT, 160, 120, GFXFF); + //ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->setFreeFont(FF18); // Select the font + ttgo->tft->drawString(sFF23, 160, 60, GFXFF);// Print the string name of the font + ttgo->tft->setFreeFont(FF23); + ttgo->tft->drawString(TEXT, 160, 120, GFXFF); delay(1000); - //ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->setFreeFont(FF18); // Select the font - ttgo->eTFT->drawString(sFF24, 160, 60, GFXFF);// Print the string name of the font - ttgo->eTFT->setFreeFont(FF24); - ttgo->eTFT->drawString(TEXT, 160, 120, GFXFF); + //ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->setFreeFont(FF18); // Select the font + ttgo->tft->drawString(sFF24, 160, 60, GFXFF);// Print the string name of the font + ttgo->tft->setFreeFont(FF24); + ttgo->tft->drawString(TEXT, 160, 120, GFXFF); delay(1000); - ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->setFreeFont(FF18); // Select the font - ttgo->eTFT->drawString(sFF25, 160, 60, GFXFF);// Print the string name of the font - ttgo->eTFT->setFreeFont(FF25); - ttgo->eTFT->drawString(TEXT, 160, 120, GFXFF); + ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->setFreeFont(FF18); // Select the font + ttgo->tft->drawString(sFF25, 160, 60, GFXFF);// Print the string name of the font + ttgo->tft->setFreeFont(FF25); + ttgo->tft->drawString(TEXT, 160, 120, GFXFF); delay(1000); - //ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->setFreeFont(FF18); // Select the font - ttgo->eTFT->drawString(sFF26, 160, 60, GFXFF);// Print the string name of the font - ttgo->eTFT->setFreeFont(FF26); - ttgo->eTFT->drawString(TEXT, 160, 120, GFXFF); + //ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->setFreeFont(FF18); // Select the font + ttgo->tft->drawString(sFF26, 160, 60, GFXFF);// Print the string name of the font + ttgo->tft->setFreeFont(FF26); + ttgo->tft->drawString(TEXT, 160, 120, GFXFF); delay(1000); - //ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->setFreeFont(FF18); // Select the font - ttgo->eTFT->drawString(sFF27, 160, 60, GFXFF);// Print the string name of the font - ttgo->eTFT->setFreeFont(FF27); - ttgo->eTFT->drawString(TEXT, 160, 120, GFXFF); + //ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->setFreeFont(FF18); // Select the font + ttgo->tft->drawString(sFF27, 160, 60, GFXFF);// Print the string name of the font + ttgo->tft->setFreeFont(FF27); + ttgo->tft->drawString(TEXT, 160, 120, GFXFF); delay(1000); - //ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->setFreeFont(FF18); // Select the font - ttgo->eTFT->drawString(sFF28, 160, 60, GFXFF);// Print the string name of the font - ttgo->eTFT->setFreeFont(FF28); - ttgo->eTFT->drawString(TEXT, 160, 120, GFXFF); + //ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->setFreeFont(FF18); // Select the font + ttgo->tft->drawString(sFF28, 160, 60, GFXFF);// Print the string name of the font + ttgo->tft->setFreeFont(FF28); + ttgo->tft->drawString(TEXT, 160, 120, GFXFF); delay(1000); - ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->setFreeFont(FF18); // Select the font - ttgo->eTFT->drawString(sFF29, 160, 60, GFXFF);// Print the string name of the font - ttgo->eTFT->setFreeFont(FF29); - ttgo->eTFT->drawString(TEXT, 160, 120, GFXFF); + ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->setFreeFont(FF18); // Select the font + ttgo->tft->drawString(sFF29, 160, 60, GFXFF);// Print the string name of the font + ttgo->tft->setFreeFont(FF29); + ttgo->tft->drawString(TEXT, 160, 120, GFXFF); delay(1000); - //ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->setFreeFont(FF18); // Select the font - ttgo->eTFT->drawString(sFF30, 160, 60, GFXFF);// Print the string name of the font - ttgo->eTFT->setFreeFont(FF30); - ttgo->eTFT->drawString(TEXT, 160, 120, GFXFF); + //ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->setFreeFont(FF18); // Select the font + ttgo->tft->drawString(sFF30, 160, 60, GFXFF);// Print the string name of the font + ttgo->tft->setFreeFont(FF30); + ttgo->tft->drawString(TEXT, 160, 120, GFXFF); delay(1000); - //ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->setFreeFont(FF18); // Select the font - ttgo->eTFT->drawString(sFF31, 160, 60, GFXFF);// Print the string name of the font - ttgo->eTFT->setFreeFont(FF31); - ttgo->eTFT->drawString(TEXT, 160, 120, GFXFF); + //ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->setFreeFont(FF18); // Select the font + ttgo->tft->drawString(sFF31, 160, 60, GFXFF);// Print the string name of the font + ttgo->tft->setFreeFont(FF31); + ttgo->tft->drawString(TEXT, 160, 120, GFXFF); delay(1000); - //ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->setFreeFont(FF18); // Select the font - ttgo->eTFT->drawString(sFF32, 160, 60, GFXFF);// Print the string name of the font - ttgo->eTFT->setFreeFont(FF32); - ttgo->eTFT->drawString(TEXT, 160, 120, GFXFF); + //ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->setFreeFont(FF18); // Select the font + ttgo->tft->drawString(sFF32, 160, 60, GFXFF);// Print the string name of the font + ttgo->tft->setFreeFont(FF32); + ttgo->tft->drawString(TEXT, 160, 120, GFXFF); delay(1000); - ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->setFreeFont(FF18); // Select the font - ttgo->eTFT->drawString(sFF33, 160, 60, GFXFF);// Print the string name of the font - ttgo->eTFT->setFreeFont(FF33); - ttgo->eTFT->drawString(TEXT, 160, 120, GFXFF); + ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->setFreeFont(FF18); // Select the font + ttgo->tft->drawString(sFF33, 160, 60, GFXFF);// Print the string name of the font + ttgo->tft->setFreeFont(FF33); + ttgo->tft->drawString(TEXT, 160, 120, GFXFF); delay(1000); - //ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->setFreeFont(FF18); // Select the font - ttgo->eTFT->drawString(sFF34, 160, 60, GFXFF);// Print the string name of the font - ttgo->eTFT->setFreeFont(FF34); - ttgo->eTFT->drawString(TEXT, 160, 120, GFXFF); + //ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->setFreeFont(FF18); // Select the font + ttgo->tft->drawString(sFF34, 160, 60, GFXFF);// Print the string name of the font + ttgo->tft->setFreeFont(FF34); + ttgo->tft->drawString(TEXT, 160, 120, GFXFF); delay(1000); - //ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->setFreeFont(FF18); // Select the font - ttgo->eTFT->drawString(sFF35, 160, 60, GFXFF);// Print the string name of the font - ttgo->eTFT->setFreeFont(FF35); - ttgo->eTFT->drawString(TEXT, 160, 120, GFXFF); + //ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->setFreeFont(FF18); // Select the font + ttgo->tft->drawString(sFF35, 160, 60, GFXFF);// Print the string name of the font + ttgo->tft->setFreeFont(FF35); + ttgo->tft->drawString(TEXT, 160, 120, GFXFF); delay(1000); - //ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->setFreeFont(FF18); // Select the font - ttgo->eTFT->drawString(sFF36, 160, 60, GFXFF);// Print the string name of the font - ttgo->eTFT->setFreeFont(FF36); - ttgo->eTFT->drawString(TEXT, 160, 120, GFXFF); + //ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->setFreeFont(FF18); // Select the font + ttgo->tft->drawString(sFF36, 160, 60, GFXFF);// Print the string name of the font + ttgo->tft->setFreeFont(FF36); + ttgo->tft->drawString(TEXT, 160, 120, GFXFF); delay(1000); - ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->setFreeFont(FF18); // Select the font - ttgo->eTFT->drawString(sFF37, 160, 60, GFXFF);// Print the string name of the font - ttgo->eTFT->setFreeFont(FF37); - ttgo->eTFT->drawString(TEXT, 160, 120, GFXFF); + ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->setFreeFont(FF18); // Select the font + ttgo->tft->drawString(sFF37, 160, 60, GFXFF);// Print the string name of the font + ttgo->tft->setFreeFont(FF37); + ttgo->tft->drawString(TEXT, 160, 120, GFXFF); delay(1000); - //ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->setFreeFont(FF18); // Select the font - ttgo->eTFT->drawString(sFF38, 160, 60, GFXFF);// Print the string name of the font - ttgo->eTFT->setFreeFont(FF38); - ttgo->eTFT->drawString(TEXT, 160, 120, GFXFF); + //ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->setFreeFont(FF18); // Select the font + ttgo->tft->drawString(sFF38, 160, 60, GFXFF);// Print the string name of the font + ttgo->tft->setFreeFont(FF38); + ttgo->tft->drawString(TEXT, 160, 120, GFXFF); delay(1000); - //ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->setFreeFont(FF18); // Select the font - ttgo->eTFT->drawString(sFF39, 160, 60, GFXFF);// Print the string name of the font - ttgo->eTFT->setFreeFont(FF39); - ttgo->eTFT->drawString(TEXT, 160, 120, GFXFF); + //ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->setFreeFont(FF18); // Select the font + ttgo->tft->drawString(sFF39, 160, 60, GFXFF);// Print the string name of the font + ttgo->tft->setFreeFont(FF39); + ttgo->tft->drawString(TEXT, 160, 120, GFXFF); delay(1000); - //ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->setFreeFont(FF18); // Select the font - ttgo->eTFT->drawString(sFF40, 160, 60, GFXFF);// Print the string name of the font - ttgo->eTFT->setFreeFont(FF40); - ttgo->eTFT->drawString(TEXT, 160, 120, GFXFF); + //ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->setFreeFont(FF18); // Select the font + ttgo->tft->drawString(sFF40, 160, 60, GFXFF);// Print the string name of the font + ttgo->tft->setFreeFont(FF40); + ttgo->tft->drawString(TEXT, 160, 120, GFXFF); delay(1000); - ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->setFreeFont(FF18); // Select the font - ttgo->eTFT->drawString(sFF41, 160, 60, GFXFF);// Print the string name of the font - ttgo->eTFT->setFreeFont(FF41); - ttgo->eTFT->drawString(TEXT, 160, 120, GFXFF); + ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->setFreeFont(FF18); // Select the font + ttgo->tft->drawString(sFF41, 160, 60, GFXFF);// Print the string name of the font + ttgo->tft->setFreeFont(FF41); + ttgo->tft->drawString(TEXT, 160, 120, GFXFF); delay(1000); - //ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->setFreeFont(FF18); // Select the font - ttgo->eTFT->drawString(sFF42, 160, 60, GFXFF);// Print the string name of the font - ttgo->eTFT->setFreeFont(FF42); - ttgo->eTFT->drawString(TEXT, 160, 120, GFXFF); + //ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->setFreeFont(FF18); // Select the font + ttgo->tft->drawString(sFF42, 160, 60, GFXFF);// Print the string name of the font + ttgo->tft->setFreeFont(FF42); + ttgo->tft->drawString(TEXT, 160, 120, GFXFF); delay(1000); - //ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->setFreeFont(FF18); // Select the font - ttgo->eTFT->drawString(sFF43, 160, 60, GFXFF);// Print the string name of the font - ttgo->eTFT->setFreeFont(FF43); - ttgo->eTFT->drawString(TEXT, 160, 120, GFXFF); + //ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->setFreeFont(FF18); // Select the font + ttgo->tft->drawString(sFF43, 160, 60, GFXFF);// Print the string name of the font + ttgo->tft->setFreeFont(FF43); + ttgo->tft->drawString(TEXT, 160, 120, GFXFF); delay(1000); - //ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->setFreeFont(FF18); // Select the font - ttgo->eTFT->drawString(sFF44, 160, 60, GFXFF);// Print the string name of the font - ttgo->eTFT->setFreeFont(FF44); - ttgo->eTFT->drawString(TEXT, 160, 120, GFXFF); + //ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->setFreeFont(FF18); // Select the font + ttgo->tft->drawString(sFF44, 160, 60, GFXFF);// Print the string name of the font + ttgo->tft->setFreeFont(FF44); + ttgo->tft->drawString(TEXT, 160, 120, GFXFF); delay(1000); - ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->setFreeFont(FF18); // Select the font - ttgo->eTFT->drawString(sFF45, 160, 60, GFXFF);// Print the string name of the font - ttgo->eTFT->setFreeFont(FF45); - ttgo->eTFT->drawString(TEXT, 160, 120, GFXFF); + ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->setFreeFont(FF18); // Select the font + ttgo->tft->drawString(sFF45, 160, 60, GFXFF);// Print the string name of the font + ttgo->tft->setFreeFont(FF45); + ttgo->tft->drawString(TEXT, 160, 120, GFXFF); delay(1000); - //ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->setFreeFont(FF18); // Select the font - ttgo->eTFT->drawString(sFF46, 160, 60, GFXFF);// Print the string name of the font - ttgo->eTFT->setFreeFont(FF46); - ttgo->eTFT->drawString(TEXT, 160, 120, GFXFF); + //ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->setFreeFont(FF18); // Select the font + ttgo->tft->drawString(sFF46, 160, 60, GFXFF);// Print the string name of the font + ttgo->tft->setFreeFont(FF46); + ttgo->tft->drawString(TEXT, 160, 120, GFXFF); delay(1000); - //ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->setFreeFont(FF18); // Select the font - ttgo->eTFT->drawString(sFF47, 160, 60, GFXFF);// Print the string name of the font - ttgo->eTFT->setFreeFont(FF47); - ttgo->eTFT->drawString(TEXT, 160, 120, GFXFF); + //ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->setFreeFont(FF18); // Select the font + ttgo->tft->drawString(sFF47, 160, 60, GFXFF);// Print the string name of the font + ttgo->tft->setFreeFont(FF47); + ttgo->tft->drawString(TEXT, 160, 120, GFXFF); delay(1000); - //ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->setFreeFont(FF18); // Select the font - ttgo->eTFT->drawString(sFF48, 160, 60, GFXFF);// Print the string name of the font - ttgo->eTFT->setFreeFont(FF48); - ttgo->eTFT->drawString(TEXT, 160, 120, GFXFF); + //ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->setFreeFont(FF18); // Select the font + ttgo->tft->drawString(sFF48, 160, 60, GFXFF);// Print the string name of the font + ttgo->tft->setFreeFont(FF48); + ttgo->tft->drawString(TEXT, 160, 120, GFXFF); delay(1000); } diff --git a/examples/TFT_eSPI/Arduino_Life/Arduino_Life.ino b/examples/TFT_eSPI/Arduino_Life/Arduino_Life.ino index 2251ed4..8baa8fd 100644 --- a/examples/TFT_eSPI/Arduino_Life/Arduino_Life.ino +++ b/examples/TFT_eSPI/Arduino_Life/Arduino_Life.ino @@ -6,21 +6,21 @@ // Adapted by Bodmer -#include +// => Hardware select +// #define LILYGO_WATCH_2019_WITH_TOUCH // To use T-Watch2019 with touchscreen, please uncomment this line +// #define LILYGO_WATCH_2019_NO_TOUCH // To use T-Watch2019 Not touchscreen , please uncomment this line +// #define LILYGO_WATCH_2020_V1 //To use T-Watch2020, please uncomment this line + + +#include TTGOClass *ttgo; // Maximum number of generations until the screen is refreshed #define MAX_GEN_COUNT 500 -// The ESP8266 has plenty of memory so we can create a large array -// 2 x 2 pixel cells, array size = 5120 bytes per array, runs fast -// #define GRIDX 80 -// #define GRIDY 80 -// #define CELLXY 2 - // 1 x 1 pixel cells, array size = 20480 bytes per array -#define GRIDX 160 +#define GRIDX 240 #define GRIDY 128 #define CELLXY 1 @@ -36,61 +36,6 @@ uint8_t newgrid[GRIDX][GRIDY]; uint16_t genCount = 0; - - -void setup() -{ - //Set up the display - ttgo = TTGOClass::getWatch(); - ttgo->begin(); - ttgo->openBL(); - - // ttgo->eTFT->setRotation(3); - ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->setTextFont(2); - ttgo->eTFT->setTextSize(1); - ttgo->eTFT->setTextColor(TFT_WHITE); - ttgo->eTFT->setCursor(0, 0); -} - -void loop() -{ - - //Display a simple splash screen - ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->setTextSize(2); - ttgo->eTFT->setTextColor(TFT_WHITE); - ttgo->eTFT->setCursor(40, 5); - ttgo->eTFT->println(F("Arduino")); - ttgo->eTFT->setCursor(35, 25); - ttgo->eTFT->println(F("Cellular")); - ttgo->eTFT->setCursor(35, 45); - ttgo->eTFT->println(F("Automata")); - - delay(1000); - - ttgo->eTFT->fillScreen(TFT_BLACK); - - initGrid(); - - genCount = MAX_GEN_COUNT; - - drawGrid(); - - //Compute generations - for (int gen = 0; gen < genCount; gen++) { - computeCA(); - drawGrid(); - delay(GEN_DELAY); - for (int16_t x = 1; x < GRIDX - 1; x++) { - for (int16_t y = 1; y < GRIDY - 1; y++) { - grid[x][y] = newgrid[x][y]; - } - } - - } -} - //Draws the grid on the display void drawGrid(void) { @@ -101,7 +46,7 @@ void drawGrid(void) if ((grid[x][y]) != (newgrid[x][y])) { if (newgrid[x][y] == 1) color = 0xFFFF; //random(0xFFFF); else color = 0; - ttgo->eTFT->fillRect(CELLXY * x, CELLXY * y, CELLXY, CELLXY, color); + ttgo->tft->fillRect(CELLXY * x, CELLXY * y, CELLXY, CELLXY, color); } } } @@ -127,6 +72,14 @@ void initGrid(void) } } + +// Check the Moore neighborhood +int getNumberOfNeighbors(int x, int y) +{ + return grid[x - 1][y] + grid[x - 1][y - 1] + grid[x][y - 1] + grid[x + 1][y - 1] + grid[x + 1][y] + grid[x + 1][y + 1] + grid[x][y + 1] + grid[x - 1][y + 1]; +} + + //Compute the CA. Basically everything related to CA starts here void computeCA() { @@ -143,12 +96,60 @@ void computeCA() } } -// Check the Moore neighborhood -int getNumberOfNeighbors(int x, int y) +void setup() { - return grid[x - 1][y] + grid[x - 1][y - 1] + grid[x][y - 1] + grid[x + 1][y - 1] + grid[x + 1][y] + grid[x + 1][y + 1] + grid[x][y + 1] + grid[x - 1][y + 1]; + //Set up the display + ttgo = TTGOClass::getWatch(); + ttgo->begin(); + ttgo->openBL(); + + // ttgo->tft->setRotation(3); + ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->setTextFont(2); + ttgo->tft->setTextSize(1); + ttgo->tft->setTextColor(TFT_WHITE); + ttgo->tft->setCursor(0, 0); } +void loop() +{ + + //Display a simple splash screen + ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->setTextSize(2); + ttgo->tft->setTextColor(TFT_WHITE); + ttgo->tft->setCursor(40, 5); + ttgo->tft->println(F("Arduino")); + ttgo->tft->setCursor(35, 25); + ttgo->tft->println(F("Cellular")); + ttgo->tft->setCursor(35, 45); + ttgo->tft->println(F("Automata")); + + delay(1000); + + ttgo->tft->fillScreen(TFT_BLACK); + + initGrid(); + + genCount = MAX_GEN_COUNT; + + drawGrid(); + + //Compute generations + for (int gen = 0; gen < genCount; gen++) { + computeCA(); + drawGrid(); + delay(GEN_DELAY); + for (int16_t x = 1; x < GRIDX - 1; x++) { + for (int16_t y = 1; y < GRIDY - 1; y++) { + grid[x][y] = newgrid[x][y]; + } + } + + } +} + + /* The MIT License (MIT) diff --git a/examples/TFT_eSPI/Pong_v3/Pong_v3.ino b/examples/TFT_eSPI/Pong_v3/Pong_v3.ino index 5329c35..495f111 100644 --- a/examples/TFT_eSPI/Pong_v3/Pong_v3.ino +++ b/examples/TFT_eSPI/Pong_v3/Pong_v3.ino @@ -4,12 +4,18 @@ * */ +// => Hardware select +// #define LILYGO_WATCH_2019_WITH_TOUCH // To use T-Watch2019 with touchscreen, please uncomment this line +// #define LILYGO_WATCH_2019_NO_TOUCH // To use T-Watch2019 Not touchscreen , please uncomment this line +// #define LILYGO_WATCH_2020_V1 //To use T-Watch2020, please uncomment this line + + +#include + #define BLACK 0x0000 #define WHITE 0xFFFF #define GREY 0x5AEB -#include - TTGOClass *ttgo; int16_t h = 240; @@ -54,123 +60,6 @@ int16_t dashline_y = dashline_h / 2; int16_t lscore = 12; int16_t rscore = 4; -void setup(void) -{ - - randomSeed(analogRead(0)*analogRead(1)); - - ttgo = TTGOClass::getWatch(); - ttgo->begin(); - ttgo->openBL(); - - - ttgo->eTFT->fillScreen(BLACK); - - initgame(); - - ttgo->eTFT->setTextColor(WHITE, BLACK); - - delay(2000); - -} - -void loop() -{ - delay(dly); - - lpaddle(); - rpaddle(); - - midline(); - - ball(); -} - -void initgame() -{ - lpaddle_y = random(0, h - paddle_h); - rpaddle_y = random(0, h - paddle_h); - - // ball is placed on the center of the left paddle - ball_y = lpaddle_y + (paddle_h / 2); - - calc_target_y(); - - midline(); - - ttgo->eTFT->fillRect(0, h - 26, w, h - 1, BLACK); - - ttgo->eTFT->setTextDatum(TC_DATUM); - ttgo->eTFT->setTextColor(WHITE); - ttgo->eTFT->drawString("TFT_eSPI example", w / 2, h - 26, 2); -} - -void midline() -{ - - // If the ball is not on the line then don't redraw the line - if ((ball_x < dashline_x - ball_w) && (ball_x > dashline_x + dashline_w)) return; - - ttgo->eTFT->startWrite(); - - // Quick way to draw a dashed line - ttgo->eTFT->setAddrWindow(dashline_x, 0, dashline_w, h); - - for (int16_t i = 0; i < dashline_n; i += 2) { - ttgo->eTFT->pushColor(WHITE, dashline_w * dashline_h); // push dash pixels - ttgo->eTFT->pushColor(BLACK, dashline_w * dashline_h); // push gap pixels - } - - ttgo->eTFT->endWrite(); -} - -void lpaddle() -{ - - if (lpaddle_d == 1) { - ttgo->eTFT->fillRect(lpaddle_x, lpaddle_y, paddle_w, 1, BLACK); - } else if (lpaddle_d == -1) { - ttgo->eTFT->fillRect(lpaddle_x, lpaddle_y + paddle_h - 1, paddle_w, 1, BLACK); - } - - lpaddle_y = lpaddle_y + lpaddle_d; - - if (ball_dx == 1) lpaddle_d = 0; - else { - if (lpaddle_y + paddle_h / 2 == target_y) lpaddle_d = 0; - else if (lpaddle_y + paddle_h / 2 > target_y) lpaddle_d = -1; - else lpaddle_d = 1; - } - - if (lpaddle_y + paddle_h >= h && lpaddle_d == 1) lpaddle_d = 0; - else if (lpaddle_y <= 0 && lpaddle_d == -1) lpaddle_d = 0; - - ttgo->eTFT->fillRect(lpaddle_x, lpaddle_y, paddle_w, paddle_h, WHITE); -} - -void rpaddle() -{ - - if (rpaddle_d == 1) { - ttgo->eTFT->fillRect(rpaddle_x, rpaddle_y, paddle_w, 1, BLACK); - } else if (rpaddle_d == -1) { - ttgo->eTFT->fillRect(rpaddle_x, rpaddle_y + paddle_h - 1, paddle_w, 1, BLACK); - } - - rpaddle_y = rpaddle_y + rpaddle_d; - - if (ball_dx == -1) rpaddle_d = 0; - else { - if (rpaddle_y + paddle_h / 2 == target_y) rpaddle_d = 0; - else if (rpaddle_y + paddle_h / 2 > target_y) rpaddle_d = -1; - else rpaddle_d = 1; - } - - if (rpaddle_y + paddle_h >= h && rpaddle_d == 1) rpaddle_d = 0; - else if (rpaddle_y <= 0 && rpaddle_d == -1) rpaddle_d = 0; - - ttgo->eTFT->fillRect(rpaddle_x, rpaddle_y, paddle_w, paddle_h, WHITE); -} void calc_target_y() { @@ -195,6 +84,90 @@ void calc_target_y() } } + +void midline() +{ + // If the ball is not on the line then don't redraw the line + if ((ball_x < dashline_x - ball_w) && (ball_x > dashline_x + dashline_w)) return; + ttgo->tft->startWrite(); + // Quick way to draw a dashed line + ttgo->tft->setAddrWindow(dashline_x, 0, dashline_w, h); + for (int16_t i = 0; i < dashline_n; i += 2) { + ttgo->tft->pushColor(WHITE, dashline_w * dashline_h); // push dash pixels + ttgo->tft->pushColor(BLACK, dashline_w * dashline_h); // push gap pixels + } + ttgo->tft->endWrite(); +} + + +void initgame() +{ + lpaddle_y = random(0, h - paddle_h); + rpaddle_y = random(0, h - paddle_h); + + // ball is placed on the center of the left paddle + ball_y = lpaddle_y + (paddle_h / 2); + + calc_target_y(); + + midline(); + + ttgo->tft->fillRect(0, h - 26, w, h - 1, BLACK); + + ttgo->tft->setTextDatum(TC_DATUM); + ttgo->tft->setTextColor(WHITE); + ttgo->tft->drawString("TFT_eSPI example", w / 2, h - 26, 2); +} + +void lpaddle() +{ + + if (lpaddle_d == 1) { + ttgo->tft->fillRect(lpaddle_x, lpaddle_y, paddle_w, 1, BLACK); + } else if (lpaddle_d == -1) { + ttgo->tft->fillRect(lpaddle_x, lpaddle_y + paddle_h - 1, paddle_w, 1, BLACK); + } + + lpaddle_y = lpaddle_y + lpaddle_d; + + if (ball_dx == 1) lpaddle_d = 0; + else { + if (lpaddle_y + paddle_h / 2 == target_y) lpaddle_d = 0; + else if (lpaddle_y + paddle_h / 2 > target_y) lpaddle_d = -1; + else lpaddle_d = 1; + } + + if (lpaddle_y + paddle_h >= h && lpaddle_d == 1) lpaddle_d = 0; + else if (lpaddle_y <= 0 && lpaddle_d == -1) lpaddle_d = 0; + + ttgo->tft->fillRect(lpaddle_x, lpaddle_y, paddle_w, paddle_h, WHITE); +} + +void rpaddle() +{ + + if (rpaddle_d == 1) { + ttgo->tft->fillRect(rpaddle_x, rpaddle_y, paddle_w, 1, BLACK); + } else if (rpaddle_d == -1) { + ttgo->tft->fillRect(rpaddle_x, rpaddle_y + paddle_h - 1, paddle_w, 1, BLACK); + } + + rpaddle_y = rpaddle_y + rpaddle_d; + + if (ball_dx == -1) rpaddle_d = 0; + else { + if (rpaddle_y + paddle_h / 2 == target_y) rpaddle_d = 0; + else if (rpaddle_y + paddle_h / 2 > target_y) rpaddle_d = -1; + else rpaddle_d = 1; + } + + if (rpaddle_y + paddle_h >= h && rpaddle_d == 1) rpaddle_d = 0; + else if (rpaddle_y <= 0 && rpaddle_d == -1) rpaddle_d = 0; + + ttgo->tft->fillRect(rpaddle_x, rpaddle_y, paddle_w, paddle_h, WHITE); +} + + void ball() { ball_x = ball_x + ball_dx; @@ -217,10 +190,31 @@ void ball() ball_y += ball_dy; // Keep in bounds } - //ttgo->eTFT->fillRect(oldball_x, oldball_y, ball_w, ball_h, BLACK); - ttgo->eTFT->drawRect(oldball_x, oldball_y, ball_w, ball_h, BLACK); // Less TFT refresh aliasing than line above for large balls - ttgo->eTFT->fillRect( ball_x, ball_y, ball_w, ball_h, WHITE); + //ttgo->tft->fillRect(oldball_x, oldball_y, ball_w, ball_h, BLACK); + ttgo->tft->drawRect(oldball_x, oldball_y, ball_w, ball_h, BLACK); // Less TFT refresh aliasing than line above for large balls + ttgo->tft->fillRect( ball_x, ball_y, ball_w, ball_h, WHITE); oldball_x = ball_x; oldball_y = ball_y; } + +void setup(void) +{ + randomSeed(analogRead(0)*analogRead(1)); + ttgo = TTGOClass::getWatch(); + ttgo->begin(); + ttgo->openBL(); + ttgo->tft->fillScreen(BLACK); + initgame(); + ttgo->tft->setTextColor(WHITE, BLACK); + delay(2000); +} + +void loop() +{ + delay(dly); + lpaddle(); + rpaddle(); + midline(); + ball(); +} \ No newline at end of file diff --git a/examples/TFT_eSPI/RLE_Font_test/RLE_Font_test.ino b/examples/TFT_eSPI/RLE_Font_test/RLE_Font_test.ino index 7eb95b0..ed4fb95 100644 --- a/examples/TFT_eSPI/RLE_Font_test/RLE_Font_test.ino +++ b/examples/TFT_eSPI/RLE_Font_test/RLE_Font_test.ino @@ -11,14 +11,20 @@ ######################################################################### */ +// => Hardware select +// #define LILYGO_WATCH_2019_WITH_TOUCH // To use T-Watch2019 with touchscreen, please uncomment this line +// #define LILYGO_WATCH_2019_NO_TOUCH // To use T-Watch2019 Not touchscreen , please uncomment this line +// #define LILYGO_WATCH_2020_V1 //To use T-Watch2020, please uncomment this line + + +#include + // New background colour #define TFT_BROWN 0x38E0 // Pause in milliseconds between screens, change to 0 to time font rendering #define WAIT 500 -#include - TTGOClass *ttgo; @@ -36,155 +42,155 @@ void loop() targetTime = millis(); // First we test them with a background colour set - ttgo->eTFT->setTextSize(1); - ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->setTextColor(TFT_GREEN, TFT_BLACK); + ttgo->tft->setTextSize(1); + ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->setTextColor(TFT_GREEN, TFT_BLACK); - ttgo->eTFT->drawString(" !\"#$%&'()*+,-./0123456", 0, 0, 2); - ttgo->eTFT->drawString("789:;<=>?@ABCDEFGHIJKL", 0, 16, 2); - ttgo->eTFT->drawString("MNOPQRSTUVWXYZ[\\]^_`", 0, 32, 2); - ttgo->eTFT->drawString("abcdefghijklmnopqrstuvw", 0, 48, 2); + ttgo->tft->drawString(" !\"#$%&'()*+,-./0123456", 0, 0, 2); + ttgo->tft->drawString("789:;<=>?@ABCDEFGHIJKL", 0, 16, 2); + ttgo->tft->drawString("MNOPQRSTUVWXYZ[\\]^_`", 0, 32, 2); + ttgo->tft->drawString("abcdefghijklmnopqrstuvw", 0, 48, 2); int xpos = 0; - xpos += ttgo->eTFT->drawString("xyz{|}~", 0, 64, 2); - ttgo->eTFT->drawChar(127, xpos, 64, 2); + xpos += ttgo->tft->drawString("xyz{|}~", 0, 64, 2); + ttgo->tft->drawChar(127, xpos, 64, 2); delay(WAIT); - ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->setTextColor(TFT_GREEN, TFT_BLACK); + ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->setTextColor(TFT_GREEN, TFT_BLACK); - ttgo->eTFT->drawString(" !\"#$%&'()*+,-.", 0, 0, 4); - ttgo->eTFT->drawString("/0123456789:;", 0, 26, 4); - ttgo->eTFT->drawString("<=>?@ABCDE", 0, 52, 4); - ttgo->eTFT->drawString("FGHIJKLMNO", 0, 78, 4); - ttgo->eTFT->drawString("PQRSTUVWX", 0, 104, 4); + ttgo->tft->drawString(" !\"#$%&'()*+,-.", 0, 0, 4); + ttgo->tft->drawString("/0123456789:;", 0, 26, 4); + ttgo->tft->drawString("<=>?@ABCDE", 0, 52, 4); + ttgo->tft->drawString("FGHIJKLMNO", 0, 78, 4); + ttgo->tft->drawString("PQRSTUVWX", 0, 104, 4); delay(WAIT); - ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->drawString("YZ[\\]^_`abc", 0, 0, 4); - ttgo->eTFT->drawString("defghijklmno", 0, 26, 4); - ttgo->eTFT->drawString("pqrstuvwxyz", 0, 52, 4); + ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->drawString("YZ[\\]^_`abc", 0, 0, 4); + ttgo->tft->drawString("defghijklmno", 0, 26, 4); + ttgo->tft->drawString("pqrstuvwxyz", 0, 52, 4); xpos = 0; - xpos += ttgo->eTFT->drawString("{|}~", 0, 78, 4); - ttgo->eTFT->drawChar(127, xpos, 78, 4); + xpos += ttgo->tft->drawString("{|}~", 0, 78, 4); + ttgo->tft->drawChar(127, xpos, 78, 4); delay(WAIT); - ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->setTextColor(TFT_BLUE, TFT_BLACK); + ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->setTextColor(TFT_BLUE, TFT_BLACK); - ttgo->eTFT->drawString("012345", 0, 0, 6); - ttgo->eTFT->drawString("6789", 0, 40, 6); - ttgo->eTFT->drawString("apm-:.", 0, 80, 6); + ttgo->tft->drawString("012345", 0, 0, 6); + ttgo->tft->drawString("6789", 0, 40, 6); + ttgo->tft->drawString("apm-:.", 0, 80, 6); delay(WAIT); - ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->setTextColor(TFT_RED, TFT_BLACK); + ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->setTextColor(TFT_RED, TFT_BLACK); - ttgo->eTFT->drawString("0123", 0, 0, 7); - ttgo->eTFT->drawString("4567", 0, 60, 7); + ttgo->tft->drawString("0123", 0, 0, 7); + ttgo->tft->drawString("4567", 0, 60, 7); delay(WAIT); - ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->drawString("890:.", 0, 0, 7); - ttgo->eTFT->drawString("", 0, 60, 7); + ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->drawString("890:.", 0, 0, 7); + ttgo->tft->drawString("", 0, 60, 7); delay(WAIT); - ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->setTextColor(TFT_YELLOW, TFT_BLACK); + ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->setTextColor(TFT_YELLOW, TFT_BLACK); - ttgo->eTFT->drawString("01", 0, 0, 8); + ttgo->tft->drawString("01", 0, 0, 8); delay(WAIT); - ttgo->eTFT->drawString("23", 0, 0, 8); + ttgo->tft->drawString("23", 0, 0, 8); delay(WAIT); - ttgo->eTFT->drawString("45", 0, 0, 8); + ttgo->tft->drawString("45", 0, 0, 8); delay(WAIT); - ttgo->eTFT->drawString("67", 0, 0, 8); + ttgo->tft->drawString("67", 0, 0, 8); delay(WAIT); - ttgo->eTFT->drawString("89", 0, 0, 8); + ttgo->tft->drawString("89", 0, 0, 8); delay(WAIT); - ttgo->eTFT->drawString("0:.", 0, 0, 8); + ttgo->tft->drawString("0:.", 0, 0, 8); delay(WAIT); - ttgo->eTFT->setTextColor(TFT_MAGENTA); - ttgo->eTFT->drawNumber(millis() - targetTime, 0, 100, 4); + ttgo->tft->setTextColor(TFT_MAGENTA); + ttgo->tft->drawNumber(millis() - targetTime, 0, 100, 4); delay(4000); // Now test them with transparent background targetTime = millis(); - ttgo->eTFT->setTextSize(1); - ttgo->eTFT->fillScreen(TFT_BROWN); - ttgo->eTFT->setTextColor(TFT_GREEN); + ttgo->tft->setTextSize(1); + ttgo->tft->fillScreen(TFT_BROWN); + ttgo->tft->setTextColor(TFT_GREEN); - ttgo->eTFT->drawString(" !\"#$%&'()*+,-./0123456", 0, 0, 2); - ttgo->eTFT->drawString("789:;<=>?@ABCDEFGHIJKL", 0, 16, 2); - ttgo->eTFT->drawString("MNOPQRSTUVWXYZ[\\]^_`", 0, 32, 2); - ttgo->eTFT->drawString("abcdefghijklmnopqrstuvw", 0, 48, 2); + ttgo->tft->drawString(" !\"#$%&'()*+,-./0123456", 0, 0, 2); + ttgo->tft->drawString("789:;<=>?@ABCDEFGHIJKL", 0, 16, 2); + ttgo->tft->drawString("MNOPQRSTUVWXYZ[\\]^_`", 0, 32, 2); + ttgo->tft->drawString("abcdefghijklmnopqrstuvw", 0, 48, 2); xpos = 0; - xpos += ttgo->eTFT->drawString("xyz{|}~", 0, 64, 2); - ttgo->eTFT->drawChar(127, xpos, 64, 2); + xpos += ttgo->tft->drawString("xyz{|}~", 0, 64, 2); + ttgo->tft->drawChar(127, xpos, 64, 2); delay(WAIT); - ttgo->eTFT->fillScreen(TFT_BROWN); - ttgo->eTFT->setTextColor(TFT_GREEN); + ttgo->tft->fillScreen(TFT_BROWN); + ttgo->tft->setTextColor(TFT_GREEN); - ttgo->eTFT->drawString(" !\"#$%&'()*+,-.", 0, 0, 4); - ttgo->eTFT->drawString("/0123456789:;", 0, 26, 4); - ttgo->eTFT->drawString("<=>?@ABCDE", 0, 52, 4); - ttgo->eTFT->drawString("FGHIJKLMNO", 0, 78, 4); - ttgo->eTFT->drawString("PQRSTUVWX", 0, 104, 4); + ttgo->tft->drawString(" !\"#$%&'()*+,-.", 0, 0, 4); + ttgo->tft->drawString("/0123456789:;", 0, 26, 4); + ttgo->tft->drawString("<=>?@ABCDE", 0, 52, 4); + ttgo->tft->drawString("FGHIJKLMNO", 0, 78, 4); + ttgo->tft->drawString("PQRSTUVWX", 0, 104, 4); delay(WAIT); - ttgo->eTFT->fillScreen(TFT_BROWN); - ttgo->eTFT->drawString("YZ[\\]^_`abc", 0, 0, 4); - ttgo->eTFT->drawString("defghijklmno", 0, 26, 4); - ttgo->eTFT->drawString("pqrstuvwxyz", 0, 52, 4); + ttgo->tft->fillScreen(TFT_BROWN); + ttgo->tft->drawString("YZ[\\]^_`abc", 0, 0, 4); + ttgo->tft->drawString("defghijklmno", 0, 26, 4); + ttgo->tft->drawString("pqrstuvwxyz", 0, 52, 4); xpos = 0; - xpos += ttgo->eTFT->drawString("{|}~", 0, 78, 4); - ttgo->eTFT->drawChar(127, xpos, 78, 4); + xpos += ttgo->tft->drawString("{|}~", 0, 78, 4); + ttgo->tft->drawChar(127, xpos, 78, 4); delay(WAIT); - ttgo->eTFT->fillScreen(TFT_BROWN); - ttgo->eTFT->setTextColor(TFT_BLUE); + ttgo->tft->fillScreen(TFT_BROWN); + ttgo->tft->setTextColor(TFT_BLUE); - ttgo->eTFT->drawString("012345", 0, 0, 6); - ttgo->eTFT->drawString("6789", 0, 40, 6); - ttgo->eTFT->drawString("apm-:.", 0, 80, 6); + ttgo->tft->drawString("012345", 0, 0, 6); + ttgo->tft->drawString("6789", 0, 40, 6); + ttgo->tft->drawString("apm-:.", 0, 80, 6); delay(WAIT); - ttgo->eTFT->fillScreen(TFT_BROWN); - ttgo->eTFT->setTextColor(TFT_RED); + ttgo->tft->fillScreen(TFT_BROWN); + ttgo->tft->setTextColor(TFT_RED); - ttgo->eTFT->drawString("0123", 0, 0, 7); - ttgo->eTFT->drawString("4567", 0, 60, 7); + ttgo->tft->drawString("0123", 0, 0, 7); + ttgo->tft->drawString("4567", 0, 60, 7); delay(WAIT); - ttgo->eTFT->fillScreen(TFT_BROWN); - ttgo->eTFT->drawString("890:.", 0, 0, 7); - ttgo->eTFT->drawString("", 0, 60, 7); + ttgo->tft->fillScreen(TFT_BROWN); + ttgo->tft->drawString("890:.", 0, 0, 7); + ttgo->tft->drawString("", 0, 60, 7); delay(WAIT); - ttgo->eTFT->fillScreen(TFT_BROWN); - ttgo->eTFT->setTextColor(TFT_YELLOW); + ttgo->tft->fillScreen(TFT_BROWN); + ttgo->tft->setTextColor(TFT_YELLOW); - ttgo->eTFT->drawString("0123", 0, 0, 8); + ttgo->tft->drawString("0123", 0, 0, 8); delay(WAIT); - ttgo->eTFT->fillScreen(TFT_BROWN); - ttgo->eTFT->drawString("4567", 0, 0, 8); + ttgo->tft->fillScreen(TFT_BROWN); + ttgo->tft->drawString("4567", 0, 0, 8); delay(WAIT); - ttgo->eTFT->fillScreen(TFT_BROWN); - ttgo->eTFT->drawString("890:.", 0, 0, 8); + ttgo->tft->fillScreen(TFT_BROWN); + ttgo->tft->drawString("890:.", 0, 0, 8); delay(WAIT); - ttgo->eTFT->setTextColor(TFT_MAGENTA); + ttgo->tft->setTextColor(TFT_MAGENTA); - ttgo->eTFT->drawNumber(millis() - targetTime, 0, 100, 4); + ttgo->tft->drawNumber(millis() - targetTime, 0, 100, 4); delay(4000);; } diff --git a/examples/TFT_eSPI/TFT_Char_times/TFT_Char_times.ino b/examples/TFT_eSPI/TFT_Char_times/TFT_Char_times.ino index 5754a6f..f157ded 100644 --- a/examples/TFT_eSPI/TFT_Char_times/TFT_Char_times.ino +++ b/examples/TFT_eSPI/TFT_Char_times/TFT_Char_times.ino @@ -17,8 +17,13 @@ ######################################################################### */ +// => Hardware select +// #define LILYGO_WATCH_2019_WITH_TOUCH // To use T-Watch2019 with touchscreen, please uncomment this line +// #define LILYGO_WATCH_2019_NO_TOUCH // To use T-Watch2019 Not touchscreen , please uncomment this line +// #define LILYGO_WATCH_2020_V1 //To use T-Watch2020, please uncomment this line -#include + +#include TTGOClass *ttgo; @@ -29,101 +34,101 @@ void setup(void) ttgo = TTGOClass::getWatch(); ttgo->begin(); ttgo->openBL(); - ttgo->eTFT->setTextFont(2); + ttgo->tft->setTextFont(2); } void loop() { - ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->setTextColor(TFT_WHITE, TFT_BLACK); + ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->setTextColor(TFT_WHITE, TFT_BLACK); drawTime = millis(); for (int i = 0; i < 1000; i++) { - ttgo->eTFT->drawNumber(i, 0, 0, 1); + ttgo->tft->drawNumber(i, 0, 0, 1); } drawTime = millis() - drawTime; - ttgo->eTFT->setTextColor(TFT_RED, TFT_BLACK); - ttgo->eTFT->drawFloat(drawTime / 2890.0, 3, 0, 80, 4); - if (drawTime < 100) ttgo->eTFT->drawString("Font 1 not loaded!", 0, 108, 2); + ttgo->tft->setTextColor(TFT_RED, TFT_BLACK); + ttgo->tft->drawFloat(drawTime / 2890.0, 3, 0, 80, 4); + if (drawTime < 100) ttgo->tft->drawString("Font 1 not loaded!", 0, 108, 2); delay(4000); - ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->setTextColor(TFT_WHITE, TFT_BLACK); + ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->setTextColor(TFT_WHITE, TFT_BLACK); drawTime = millis(); for (int i = 0; i < 1000; i++) { - ttgo->eTFT->drawNumber(i, 0, 0, 2); + ttgo->tft->drawNumber(i, 0, 0, 2); } drawTime = millis() - drawTime; - ttgo->eTFT->setTextColor(TFT_RED, TFT_BLACK); - ttgo->eTFT->drawFloat(drawTime / 2890.0, 3, 0, 80, 4); - if (drawTime < 200) ttgo->eTFT->drawString("Font 2 not loaded!", 0, 108, 2); + ttgo->tft->setTextColor(TFT_RED, TFT_BLACK); + ttgo->tft->drawFloat(drawTime / 2890.0, 3, 0, 80, 4); + if (drawTime < 200) ttgo->tft->drawString("Font 2 not loaded!", 0, 108, 2); delay(4000); - ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->setTextColor(TFT_WHITE, TFT_BLACK); + ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->setTextColor(TFT_WHITE, TFT_BLACK); drawTime = millis(); for (int i = 0; i < 1000; i++) { - ttgo->eTFT->drawNumber(i, 0, 0, 4); + ttgo->tft->drawNumber(i, 0, 0, 4); } drawTime = millis() - drawTime; - ttgo->eTFT->setTextColor(TFT_RED, TFT_BLACK); - ttgo->eTFT->drawFloat(drawTime / 2890.0, 3, 0, 80, 4); - if (drawTime < 200) ttgo->eTFT->drawString("Font 4 not loaded!", 0, 108, 2); + ttgo->tft->setTextColor(TFT_RED, TFT_BLACK); + ttgo->tft->drawFloat(drawTime / 2890.0, 3, 0, 80, 4); + if (drawTime < 200) ttgo->tft->drawString("Font 4 not loaded!", 0, 108, 2); delay(4000); - ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->setTextColor(TFT_WHITE, TFT_BLACK); + ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->setTextColor(TFT_WHITE, TFT_BLACK); drawTime = millis(); for (int i = 0; i < 1000; i++) { - yield(); ttgo->eTFT->drawNumber(i, 0, 0, 6); + yield(); ttgo->tft->drawNumber(i, 0, 0, 6); } drawTime = millis() - drawTime; - ttgo->eTFT->setTextColor(TFT_RED, TFT_BLACK); - ttgo->eTFT->drawFloat(drawTime / 2890.0, 3, 0, 80, 4); - if (drawTime < 200) ttgo->eTFT->drawString("Font 6 not loaded!", 0, 108, 2); + ttgo->tft->setTextColor(TFT_RED, TFT_BLACK); + ttgo->tft->drawFloat(drawTime / 2890.0, 3, 0, 80, 4); + if (drawTime < 200) ttgo->tft->drawString("Font 6 not loaded!", 0, 108, 2); delay(4000); - ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->setTextColor(TFT_WHITE, TFT_BLACK); + ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->setTextColor(TFT_WHITE, TFT_BLACK); drawTime = millis(); for (int i = 0; i < 1000; i++) { - yield(); ttgo->eTFT->drawNumber(i, 0, 0, 7); + yield(); ttgo->tft->drawNumber(i, 0, 0, 7); } drawTime = millis() - drawTime; - ttgo->eTFT->setTextColor(TFT_RED, TFT_BLACK); - ttgo->eTFT->drawFloat(drawTime / 2890.0, 3, 0, 80, 4); - if (drawTime < 200) ttgo->eTFT->drawString("Font 7 not loaded!", 0, 108, 2); + ttgo->tft->setTextColor(TFT_RED, TFT_BLACK); + ttgo->tft->drawFloat(drawTime / 2890.0, 3, 0, 80, 4); + if (drawTime < 200) ttgo->tft->drawString("Font 7 not loaded!", 0, 108, 2); delay(4000); - ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->setTextColor(TFT_WHITE, TFT_BLACK); + ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->setTextColor(TFT_WHITE, TFT_BLACK); drawTime = millis(); for (int i = 0; i < 100; i++) { - yield(); ttgo->eTFT->drawNumber(i, 0, 0, 8); + yield(); ttgo->tft->drawNumber(i, 0, 0, 8); } drawTime = millis() - drawTime; - ttgo->eTFT->setTextColor(TFT_RED, TFT_BLACK); - ttgo->eTFT->drawFloat(drawTime / 190.0, 3, 0, 80, 4); - if (drawTime < 200) ttgo->eTFT->drawString("Font 8 not loaded!", 0, 108, 2); + ttgo->tft->setTextColor(TFT_RED, TFT_BLACK); + ttgo->tft->drawFloat(drawTime / 190.0, 3, 0, 80, 4); + if (drawTime < 200) ttgo->tft->drawString("Font 8 not loaded!", 0, 108, 2); delay(4000); } diff --git a/examples/TFT_eSPI/TFT_Clock/TFT_Clock.ino b/examples/TFT_eSPI/TFT_Clock/TFT_Clock.ino index f18220a..1e6a6e0 100644 --- a/examples/TFT_eSPI/TFT_Clock/TFT_Clock.ino +++ b/examples/TFT_eSPI/TFT_Clock/TFT_Clock.ino @@ -17,7 +17,12 @@ Based on a sketch by Gilchrist 6/2/2014 1.0 */ -#include +// => Hardware select +// #define LILYGO_WATCH_2019_WITH_TOUCH // To use T-Watch2019 with touchscreen, please uncomment this line +// #define LILYGO_WATCH_2019_NO_TOUCH // To use T-Watch2019 Not touchscreen , please uncomment this line +// #define LILYGO_WATCH_2020_V1 //To use T-Watch2020, please uncomment this line + +#include TTGOClass *ttgo; @@ -34,6 +39,16 @@ uint8_t hh = conv2d(__TIME__), mm = conv2d(__TIME__ + 3), ss = conv2d(__TIME__ + boolean initial = 1; + +static uint8_t conv2d(const char *p) +{ + uint8_t v = 0; + if ('0' <= *p && *p <= '9') + v = *p - '0'; + return 10 * v + *++p - '0'; +} + + void setup(void) { Serial.begin(115200); @@ -42,12 +57,12 @@ void setup(void) ttgo->begin(); ttgo->openBL(); - ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->setTextColor(TFT_WHITE, TFT_BLACK); // Adding a background colour erases previous text automatically + ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->setTextColor(TFT_WHITE, TFT_BLACK); // Adding a background colour erases previous text automatically // Draw clock face - ttgo->eTFT->fillCircle(120, 120, 118, TFT_WHITE); - ttgo->eTFT->fillCircle(120, 120, 110, TFT_BLACK); + ttgo->tft->fillCircle(120, 120, 118, TFT_WHITE); + ttgo->tft->fillCircle(120, 120, 110, TFT_BLACK); // Draw 12 lines for (int i = 0; i < 360; i += 30) { @@ -58,7 +73,7 @@ void setup(void) x1 = sx * 100 + 120; yy1 = sy * 100 + 120; - ttgo->eTFT->drawLine(x0, yy0, x1, yy1, TFT_RED); + ttgo->tft->drawLine(x0, yy0, x1, yy1, TFT_RED); } // Draw 60 dots @@ -68,19 +83,19 @@ void setup(void) x0 = sx * 102 + 120; yy0 = sy * 102 + 120; // Draw minute markers - ttgo->eTFT->drawPixel(x0, yy0, TFT_WHITE); + ttgo->tft->drawPixel(x0, yy0, TFT_WHITE); // Draw main quadrant dots - if (i == 0 || i == 180) ttgo->eTFT->fillCircle(x0, yy0, 2, TFT_WHITE); - if (i == 90 || i == 270) ttgo->eTFT->fillCircle(x0, yy0, 2, TFT_WHITE); + if (i == 0 || i == 180) ttgo->tft->fillCircle(x0, yy0, 2, TFT_WHITE); + if (i == 90 || i == 270) ttgo->tft->fillCircle(x0, yy0, 2, TFT_WHITE); } - ttgo->eTFT->fillCircle(120, 121, 3, TFT_WHITE); + ttgo->tft->fillCircle(120, 121, 3, TFT_WHITE); // Draw text at position 120,260 using fonts 4 // Only font numbers 2,4,6,7 are valid. Font 6 only contains characters [space] 0 1 2 3 4 5 6 7 8 9 : . - a p m // Font 7 is a 7 segment font and only contains characters [space] 0 1 2 3 4 5 6 7 8 9 : . - // ttgo->eTFT->drawCentreString("Time flies", 120, 260, 4); + // ttgo->tft->drawCentreString("Time flies", 120, 260, 4); targetTime = millis() + 1000; } @@ -115,31 +130,22 @@ void loop() if (ss == 0 || initial) { initial = 0; // Erase hour and minute hand positions every minute - ttgo->eTFT->drawLine(ohx, ohy, 120, 121, TFT_BLACK); + ttgo->tft->drawLine(ohx, ohy, 120, 121, TFT_BLACK); ohx = hx * 62 + 121; ohy = hy * 62 + 121; - ttgo->eTFT->drawLine(omx, omy, 120, 121, TFT_BLACK); + ttgo->tft->drawLine(omx, omy, 120, 121, TFT_BLACK); omx = mx * 84 + 120; omy = my * 84 + 121; } // Redraw new hand positions, hour and minute hands not erased here to avoid flicker - ttgo->eTFT->drawLine(osx, osy, 120, 121, TFT_BLACK); + ttgo->tft->drawLine(osx, osy, 120, 121, TFT_BLACK); osx = sx * 90 + 121; osy = sy * 90 + 121; - ttgo->eTFT->drawLine(osx, osy, 120, 121, TFT_RED); - ttgo->eTFT->drawLine(ohx, ohy, 120, 121, TFT_WHITE); - ttgo->eTFT->drawLine(omx, omy, 120, 121, TFT_WHITE); - ttgo->eTFT->drawLine(osx, osy, 120, 121, TFT_RED); - ttgo->eTFT->fillCircle(120, 121, 3, TFT_RED); + ttgo->tft->drawLine(osx, osy, 120, 121, TFT_RED); + ttgo->tft->drawLine(ohx, ohy, 120, 121, TFT_WHITE); + ttgo->tft->drawLine(omx, omy, 120, 121, TFT_WHITE); + ttgo->tft->drawLine(osx, osy, 120, 121, TFT_RED); + ttgo->tft->fillCircle(120, 121, 3, TFT_RED); } } - -static uint8_t conv2d(const char *p) -{ - uint8_t v = 0; - if ('0' <= *p && *p <= '9') - v = *p - '0'; - return 10 * v + *++p - '0'; -} - diff --git a/examples/TFT_eSPI/TFT_Clock_Digital/TFT_Clock_Digital.ino b/examples/TFT_eSPI/TFT_Clock_Digital/TFT_Clock_Digital.ino index dd513e6..2d7618f 100644 --- a/examples/TFT_eSPI/TFT_Clock_Digital/TFT_Clock_Digital.ino +++ b/examples/TFT_eSPI/TFT_Clock_Digital/TFT_Clock_Digital.ino @@ -28,7 +28,12 @@ code color */ -#include +// => Hardware select +// #define LILYGO_WATCH_2019_WITH_TOUCH // To use T-Watch2019 with touchscreen, please uncomment this line +// #define LILYGO_WATCH_2019_NO_TOUCH // To use T-Watch2019 Not touchscreen , please uncomment this line +// #define LILYGO_WATCH_2020_V1 //To use T-Watch2020, please uncomment this line + +#include TTGOClass *ttgo; @@ -55,11 +60,9 @@ void setup(void) ttgo = TTGOClass::getWatch(); ttgo->begin(); ttgo->openBL(); - - ttgo->eTFT->fillScreen(TFT_BLACK); - - ttgo->eTFT->setTextColor(TFT_YELLOW, TFT_BLACK); // Note: the new fonts do not draw the background colour - + ttgo->tft->setTextFont(1); + ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->setTextColor(TFT_YELLOW, TFT_BLACK); // Note: the new fonts do not draw the background colour targetTime = millis() + 1000; } @@ -83,15 +86,15 @@ void loop() if (ss == 0 || initial) { initial = 0; - ttgo->eTFT->setTextColor(TFT_GREEN, TFT_BLACK); - ttgo->eTFT->setCursor (8, 52); - ttgo->eTFT->print(__DATE__); // This uses the standard ADAFruit small font + ttgo->tft->setTextColor(TFT_GREEN, TFT_BLACK); + ttgo->tft->setCursor (8, 52); + ttgo->tft->print(__DATE__); // This uses the standard ADAFruit small font - ttgo->eTFT->setTextColor(TFT_BLUE, TFT_BLACK); - ttgo->eTFT->drawCentreString("It is windy", 120, 48, 2); // Next size up font 2 + ttgo->tft->setTextColor(TFT_BLUE, TFT_BLACK); + ttgo->tft->drawCentreString("It is windy", 120, 48, 2); // Next size up font 2 - //ttgo->eTFT->setTextColor(0xF81F, TFT_BLACK); // Pink - //ttgo->eTFT->drawCentreString("12.34",80,100,6); // Large font 6 only contains characters [space] 0 1 2 3 4 5 6 7 8 9 . : a p m + //ttgo->tft->setTextColor(0xF81F, TFT_BLACK); // Pink + //ttgo->tft->drawCentreString("12.34",80,100,6); // Large font 6 only contains characters [space] 0 1 2 3 4 5 6 7 8 9 . : a p m } // Update digital time @@ -99,38 +102,38 @@ void loop() byte ypos = 0; if (omm != mm) { // Only redraw every minute to minimise flicker // Uncomment ONE of the next 2 lines, using the ghost image demonstrates text overlay as time is drawn over it - ttgo->eTFT->setTextColor(0x39C4, TFT_BLACK); // Leave a 7 segment ghost image, comment out next line! - //ttgo->eTFT->setTextColor(TFT_BLACK, TFT_BLACK); // Set font colour to black to wipe image + ttgo->tft->setTextColor(0x39C4, TFT_BLACK); // Leave a 7 segment ghost image, comment out next line! + //ttgo->tft->setTextColor(TFT_BLACK, TFT_BLACK); // Set font colour to black to wipe image // Font 7 is to show a pseudo 7 segment display. // Font 7 only contains characters [space] 0 1 2 3 4 5 6 7 8 9 0 : . - ttgo->eTFT->drawString("88:88", xpos, ypos, 7); // Overwrite the text to clear it - ttgo->eTFT->setTextColor(0xFBE0, TFT_BLACK); // Orange + ttgo->tft->drawString("88:88", xpos, ypos, 7); // Overwrite the text to clear it + ttgo->tft->setTextColor(0xFBE0, TFT_BLACK); // Orange omm = mm; - if (hh < 10) xpos += ttgo->eTFT->drawChar('0', xpos, ypos, 7); - xpos += ttgo->eTFT->drawNumber(hh, xpos, ypos, 7); + if (hh < 10) xpos += ttgo->tft->drawChar('0', xpos, ypos, 7); + xpos += ttgo->tft->drawNumber(hh, xpos, ypos, 7); xcolon = xpos; - xpos += ttgo->eTFT->drawChar(':', xpos, ypos, 7); - if (mm < 10) xpos += ttgo->eTFT->drawChar('0', xpos, ypos, 7); - ttgo->eTFT->drawNumber(mm, xpos, ypos, 7); + xpos += ttgo->tft->drawChar(':', xpos, ypos, 7); + if (mm < 10) xpos += ttgo->tft->drawChar('0', xpos, ypos, 7); + ttgo->tft->drawNumber(mm, xpos, ypos, 7); } if (ss % 2) { // Flash the colon - ttgo->eTFT->setTextColor(0x39C4, TFT_BLACK); - xpos += ttgo->eTFT->drawChar(':', xcolon, ypos, 7); - ttgo->eTFT->setTextColor(0xFBE0, TFT_BLACK); + ttgo->tft->setTextColor(0x39C4, TFT_BLACK); + xpos += ttgo->tft->drawChar(':', xcolon, ypos, 7); + ttgo->tft->setTextColor(0xFBE0, TFT_BLACK); } else { - ttgo->eTFT->drawChar(':', xcolon, ypos, 7); + ttgo->tft->drawChar(':', xcolon, ypos, 7); colour = random(0xFFFF); // Erase the old text with a rectangle, the disadvantage of this method is increased display flicker - ttgo->eTFT->fillRect (0, 64, 160, 20, TFT_BLACK); - ttgo->eTFT->setTextColor(colour); - ttgo->eTFT->drawRightString("Colour", 75, 64, 4); // Right justified string drawing to x position 75 + ttgo->tft->fillRect (0, 64, 160, 20, TFT_BLACK); + ttgo->tft->setTextColor(colour); + ttgo->tft->drawRightString("Colour", 75, 64, 4); // Right justified string drawing to x position 75 String scolour = String(colour, HEX); scolour.toUpperCase(); char buffer[20]; scolour.toCharArray(buffer, 20); - ttgo->eTFT->drawString(buffer, 82, 64, 4); + ttgo->tft->drawString(buffer, 82, 64, 4); } } } diff --git a/examples/TFT_eSPI/TFT_Ellipse/TFT_Ellipse.ino b/examples/TFT_eSPI/TFT_Ellipse/TFT_Ellipse.ino index 731cc6a..4b060ea 100644 --- a/examples/TFT_eSPI/TFT_Ellipse/TFT_Ellipse.ino +++ b/examples/TFT_eSPI/TFT_Ellipse/TFT_Ellipse.ino @@ -4,7 +4,12 @@ This sketch does not use any fonts. */ -#include +// => Hardware select +// #define LILYGO_WATCH_2019_WITH_TOUCH // To use T-Watch2019 with touchscreen, please uncomment this line +// #define LILYGO_WATCH_2019_NO_TOUCH // To use T-Watch2019 Not touchscreen , please uncomment this line +// #define LILYGO_WATCH_2020_V1 //To use T-Watch2020, please uncomment this line + +#include TTGOClass *ttgo; @@ -17,30 +22,26 @@ void setup(void) void loop() { - - ttgo->eTFT->fillScreen(TFT_BLACK); - + ttgo->tft->fillScreen(TFT_BLACK); // Draw some random filled elipses for (int i = 0; i < 20; i++) { int rx = random(40); int ry = random(40); int x = rx + random(160 - rx - rx); int y = ry + random(128 - ry - ry); - ttgo->eTFT->fillEllipse(x, y, rx, ry, random(0xFFFF)); + ttgo->tft->fillEllipse(x, y, rx, ry, random(0xFFFF)); } delay(2000); - ttgo->eTFT->fillScreen(TFT_BLACK); - + ttgo->tft->fillScreen(TFT_BLACK); // Draw some random outline elipses for (int i = 0; i < 20; i++) { int rx = random(40); int ry = random(40); int x = rx + random(160 - rx - rx); int y = ry + random(128 - ry - ry); - ttgo->eTFT->drawEllipse(x, y, rx, ry, random(0xFFFF)); + ttgo->tft->drawEllipse(x, y, rx, ry, random(0xFFFF)); } - delay(2000); } diff --git a/examples/TFT_eSPI/TFT_Meter_5/TFT_Meter_5.ino b/examples/TFT_eSPI/TFT_Meter_5/TFT_Meter_5.ino index e47102d..c076656 100644 --- a/examples/TFT_eSPI/TFT_Meter_5/TFT_Meter_5.ino +++ b/examples/TFT_eSPI/TFT_Meter_5/TFT_Meter_5.ino @@ -7,11 +7,18 @@ Updated by Bodmer for variable meter size */ + + +// => Hardware select +// #define LILYGO_WATCH_2019_WITH_TOUCH // To use T-Watch2019 with touchscreen, please uncomment this line +// #define LILYGO_WATCH_2019_NO_TOUCH // To use T-Watch2019 Not touchscreen , please uncomment this line +// #define LILYGO_WATCH_2020_V1 //To use T-Watch2020, please uncomment this line + +#include + // Define meter size #define M_SIZE 0.667 -#include - void plotNeedle(int value, byte ms_delay); void analogMeter(); @@ -30,37 +37,6 @@ int value[6] = {0, 0, 0, 0, 0, 0}; int old_value[6] = { -1, -1, -1, -1, -1, -1}; int d = 0; -void setup(void) -{ - Serial.begin(115200); // For debug - - ttgo = TTGOClass::getWatch(); - ttgo->begin(); - ttgo->openBL(); - ttgo->eTFT->setTextFont(1); - ttgo->eTFT->fillScreen(TFT_BLACK); - - analogMeter(); // Draw analogue meter - - updateTime = millis(); // Next update time -} - - -void loop() -{ - if (updateTime <= millis()) { - updateTime = millis() + 35; // Update meter every 35 milliseconds - - // Create a Sine wave for testing - d += 4; if (d >= 360) d = 0; - value[0] = 50 + 50 * sin((d + 0) * 0.0174532925); - //value[0] = random(0,100); - //unsigned long tt = millis(); - plotNeedle(value[0], 0); // It takes between 2 and 14ms to replot the needle with zero delay - //Serial.println(millis()-tt); - } -} - // ######################################################################### // Draw the analogue meter on the screen @@ -69,10 +45,10 @@ void analogMeter() { // Meter outline - ttgo->eTFT->fillRect(0, 0, M_SIZE * 239, M_SIZE * 131, TFT_GREY); - ttgo->eTFT->fillRect(1, M_SIZE * 3, M_SIZE * 234, M_SIZE * 125, TFT_WHITE); + ttgo->tft->fillRect(0, 0, M_SIZE * 239, M_SIZE * 131, TFT_GREY); + ttgo->tft->fillRect(1, M_SIZE * 3, M_SIZE * 234, M_SIZE * 125, TFT_WHITE); - ttgo->eTFT->setTextColor(TFT_BLACK); // Text colour + ttgo->tft->setTextColor(TFT_BLACK); // Text colour // Draw ticks every 5 degrees from -50 to +50 degrees (100 deg. FSD swing) for (int i = -50; i < 51; i += 5) { @@ -97,20 +73,20 @@ void analogMeter() // Yellow zone limits //if (i >= -50 && i < 0) { - // ttgo->eTFT->fillTriangle(x0, y0, x1, y1, x2, y2, TFT_YELLOW); - // ttgo->eTFT->fillTriangle(x1, y1, x2, y2, x3, y3, TFT_YELLOW); + // ttgo->tft->fillTriangle(x0, y0, x1, y1, x2, y2, TFT_YELLOW); + // ttgo->tft->fillTriangle(x1, y1, x2, y2, x3, y3, TFT_YELLOW); //} // Green zone limits if (i >= 0 && i < 25) { - ttgo->eTFT->fillTriangle(x0, y0, x1, y1, x2, y2, TFT_GREEN); - ttgo->eTFT->fillTriangle(x1, y1, x2, y2, x3, y3, TFT_GREEN); + ttgo->tft->fillTriangle(x0, y0, x1, y1, x2, y2, TFT_GREEN); + ttgo->tft->fillTriangle(x1, y1, x2, y2, x3, y3, TFT_GREEN); } // Orange zone limits if (i >= 25 && i < 50) { - ttgo->eTFT->fillTriangle(x0, y0, x1, y1, x2, y2, TFT_ORANGE); - ttgo->eTFT->fillTriangle(x1, y1, x2, y2, x3, y3, TFT_ORANGE); + ttgo->tft->fillTriangle(x0, y0, x1, y1, x2, y2, TFT_ORANGE); + ttgo->tft->fillTriangle(x1, y1, x2, y2, x3, y3, TFT_ORANGE); } // Short scale tick length @@ -123,7 +99,7 @@ void analogMeter() y1 = sy * M_SIZE * 100 + M_SIZE * 150; // Draw tick - ttgo->eTFT->drawLine(x0, y0, x1, y1, TFT_BLACK); + ttgo->tft->drawLine(x0, y0, x1, y1, TFT_BLACK); // Check if labels should be drawn, with position tweaks if (i % 25 == 0) { @@ -131,11 +107,11 @@ void analogMeter() x0 = sx * (M_SIZE * 100 + tl + 10) + M_SIZE * 120; y0 = sy * (M_SIZE * 100 + tl + 10) + M_SIZE * 150; switch (i / 25) { - case -2: ttgo->eTFT->drawCentreString("0", x0 + 4, y0 - 4, 1); break; - case -1: ttgo->eTFT->drawCentreString("25", x0 + 2, y0, 1); break; - case 0: ttgo->eTFT->drawCentreString("50", x0, y0, 1); break; - case 1: ttgo->eTFT->drawCentreString("75", x0, y0, 1); break; - case 2: ttgo->eTFT->drawCentreString("100", x0 - 2, y0 - 4, 1); break; + case -2: ttgo->tft->drawCentreString("0", x0 + 4, y0 - 4, 1); break; + case -1: ttgo->tft->drawCentreString("25", x0 + 2, y0, 1); break; + case 0: ttgo->tft->drawCentreString("50", x0, y0, 1); break; + case 1: ttgo->tft->drawCentreString("75", x0, y0, 1); break; + case 2: ttgo->tft->drawCentreString("100", x0 - 2, y0 - 4, 1); break; } } @@ -145,12 +121,12 @@ void analogMeter() x0 = sx * M_SIZE * 100 + M_SIZE * 120; y0 = sy * M_SIZE * 100 + M_SIZE * 150; // Draw scale arc, don't draw the last part - if (i < 50) ttgo->eTFT->drawLine(x0, y0, x1, y1, TFT_BLACK); + if (i < 50) ttgo->tft->drawLine(x0, y0, x1, y1, TFT_BLACK); } - ttgo->eTFT->drawString("%RH", M_SIZE * (3 + 230 - 40), M_SIZE * (119 - 20), 2); // Units at bottom right - ttgo->eTFT->drawCentreString("%RH", M_SIZE * 120, M_SIZE * 75, 4); // Comment out to avoid font 4 - ttgo->eTFT->drawRect(1, M_SIZE * 3, M_SIZE * 236, M_SIZE * 126, TFT_BLACK); // Draw bezel line + ttgo->tft->drawString("%RH", M_SIZE * (3 + 230 - 40), M_SIZE * (119 - 20), 2); // Units at bottom right + ttgo->tft->drawCentreString("%RH", M_SIZE * 120, M_SIZE * 75, 4); // Comment out to avoid font 4 + ttgo->tft->drawRect(1, M_SIZE * 3, M_SIZE * 236, M_SIZE * 126, TFT_BLACK); // Draw bezel line plotNeedle(0, 0); // Put meter needle at 0 } @@ -164,9 +140,9 @@ void analogMeter() // ######################################################################### void plotNeedle(int value, byte ms_delay) { - ttgo->eTFT->setTextColor(TFT_BLACK, TFT_WHITE); + ttgo->tft->setTextColor(TFT_BLACK, TFT_WHITE); char buf[8]; dtostrf(value, 4, 0, buf); - ttgo->eTFT->drawRightString(buf, 33, M_SIZE * (119 - 20), 2); + ttgo->tft->drawRightString(buf, 33, M_SIZE * (119 - 20), 2); if (value < -10) value = -10; // Limit value to emulate needle end stops if (value > 110) value = 110; @@ -187,13 +163,13 @@ void plotNeedle(int value, byte ms_delay) float tx = tan((sdeg + 90) * 0.0174532925); // Erase old needle image - ttgo->eTFT->drawLine(M_SIZE * (120 + 24 * ltx) - 1, M_SIZE * (150 - 24), osx - 1, osy, TFT_WHITE); - ttgo->eTFT->drawLine(M_SIZE * (120 + 24 * ltx), M_SIZE * (150 - 24), osx, osy, TFT_WHITE); - ttgo->eTFT->drawLine(M_SIZE * (120 + 24 * ltx) + 1, M_SIZE * (150 - 24), osx + 1, osy, TFT_WHITE); + ttgo->tft->drawLine(M_SIZE * (120 + 24 * ltx) - 1, M_SIZE * (150 - 24), osx - 1, osy, TFT_WHITE); + ttgo->tft->drawLine(M_SIZE * (120 + 24 * ltx), M_SIZE * (150 - 24), osx, osy, TFT_WHITE); + ttgo->tft->drawLine(M_SIZE * (120 + 24 * ltx) + 1, M_SIZE * (150 - 24), osx + 1, osy, TFT_WHITE); // Re-plot text under needle - ttgo->eTFT->setTextColor(TFT_BLACK, TFT_WHITE); - ttgo->eTFT->drawCentreString("%RH", M_SIZE * 120, M_SIZE * 75, 4); // // Comment out to avoid font 4 + ttgo->tft->setTextColor(TFT_BLACK, TFT_WHITE); + ttgo->tft->drawCentreString("%RH", M_SIZE * 120, M_SIZE * 75, 4); // // Comment out to avoid font 4 // Store new needle end coords for next erase ltx = tx; @@ -202,9 +178,9 @@ void plotNeedle(int value, byte ms_delay) // Draw the needle in the new postion, magenta makes needle a bit bolder // draws 3 lines to thicken needle - ttgo->eTFT->drawLine(M_SIZE * (120 + 24 * ltx) - 1, M_SIZE * (150 - 24), osx - 1, osy, TFT_RED); - ttgo->eTFT->drawLine(M_SIZE * (120 + 24 * ltx), M_SIZE * (150 - 24), osx, osy, TFT_MAGENTA); - ttgo->eTFT->drawLine(M_SIZE * (120 + 24 * ltx) + 1, M_SIZE * (150 - 24), osx + 1, osy, TFT_RED); + ttgo->tft->drawLine(M_SIZE * (120 + 24 * ltx) - 1, M_SIZE * (150 - 24), osx - 1, osy, TFT_RED); + ttgo->tft->drawLine(M_SIZE * (120 + 24 * ltx), M_SIZE * (150 - 24), osx, osy, TFT_MAGENTA); + ttgo->tft->drawLine(M_SIZE * (120 + 24 * ltx) + 1, M_SIZE * (150 - 24), osx + 1, osy, TFT_RED); // Slow needle down slightly as it approaches new postion if (abs(old_analog - value) < 10) ms_delay += ms_delay / 5; @@ -214,3 +190,31 @@ void plotNeedle(int value, byte ms_delay) } } + +void setup(void) +{ + Serial.begin(115200); // For debug + ttgo = TTGOClass::getWatch(); + ttgo->begin(); + ttgo->openBL(); + ttgo->tft->setTextFont(1); + ttgo->tft->fillScreen(TFT_BLACK); + analogMeter(); // Draw analogue meter + updateTime = millis(); // Next update time +} + + +void loop() +{ + if (updateTime <= millis()) { + updateTime = millis() + 35; // Update meter every 35 milliseconds + // Create a Sine wave for testing + d += 4; if (d >= 360) d = 0; + value[0] = 50 + 50 * sin((d + 0) * 0.0174532925); + //value[0] = random(0,100); + //unsigned long tt = millis(); + plotNeedle(value[0], 0); // It takes between 2 and 14ms to replot the needle with zero delay + //Serial.println(millis()-tt); + } +} + diff --git a/examples/TFT_eSPI/TFT_graphicstest_PDQ3/TFT_graphicstest_PDQ3.ino b/examples/TFT_eSPI/TFT_graphicstest_PDQ3/TFT_graphicstest_PDQ3.ino index 3e1837b..335d231 100644 --- a/examples/TFT_eSPI/TFT_graphicstest_PDQ3/TFT_graphicstest_PDQ3.ino +++ b/examples/TFT_eSPI/TFT_graphicstest_PDQ3/TFT_graphicstest_PDQ3.ino @@ -15,8 +15,12 @@ */ -#include +// => Hardware select +// #define LILYGO_WATCH_2019_WITH_TOUCH // To use T-Watch2019 with touchscreen, please uncomment this line +// #define LILYGO_WATCH_2019_NO_TOUCH // To use T-Watch2019 Not touchscreen , please uncomment this line +// #define LILYGO_WATCH_2020_V1 //To use T-Watch2020, please uncomment this line +#include TTGOClass *ttgo; // These are used to get information about static SRAM and flash memory sizes @@ -25,216 +29,11 @@ extern "C" char _end[]; // end of SRAM data (used to check amount of SRA extern "C" char __data_load_end[]; // end of FLASH (used to check amount of Flash this program's code and data uses) -void setup() -{ - Serial.begin(115200); - - Serial.println(F("TFT 1.8\" SPI TFT Test! ")); - - ttgo = TTGOClass::getWatch(); - ttgo->begin(); - ttgo->openBL(); -} - -// NOTE: This demo should run, but may look odd on 128x128 LCD (vs 128x160) - -void loop(void) -{ - - Serial.print(F(__DATE__ " " __TIME__ " - Flash=0x")); - // These are not compatible with the ESP8266 core library - //Serial.print((uint16_t)__data_load_end, HEX); - //Serial.print(F(" RAM=0x")); - //Serial.println((uint16_t)_end - (uint16_t)__data_start, HEX); - Serial.println(F("Benchmark Time (microseconds)")); - - uint32_t usecHaD = testHaD(); - Serial.print(F("HaD pushColor ")); - Serial.println(usecHaD); - delay(100); - - - uint32_t usecFillScreen = testFillScreen(); - Serial.print(F("Screen fill ")); - Serial.println(usecFillScreen); - delay(100); - - ttgo->eTFT->setRotation(1); - uint32_t usecText = testText(); - Serial.print(F("Text ")); - Serial.println(usecText); - delay(100); - ttgo->eTFT->setRotation(0); - - uint32_t usecPixels = testPixels(); - Serial.print(F("Pixels ")); - Serial.println(usecPixels); - delay(100); - - uint32_t usecLines = testLines(TFT_BLUE); - Serial.print(F("Lines ")); - Serial.println(usecLines); - delay(100); - - uint32_t usecFastLines = testFastLines(TFT_RED, TFT_BLUE); - Serial.print(F("Horiz/Vert Lines ")); - Serial.println(usecFastLines); - delay(100); - - uint32_t usecRects = testRects(TFT_GREEN); - Serial.print(F("Rectangles (outline) ")); - Serial.println(usecRects); - delay(100); - - uint32_t usecFilledRects = testFilledRects(TFT_YELLOW, TFT_MAGENTA); - Serial.print(F("Rectangles (filled) ")); - Serial.println(usecFilledRects); - delay(100); - - uint32_t usecFilledCircles = testFilledCircles(10, TFT_MAGENTA); - Serial.print(F("Circles (filled) ")); - Serial.println(usecFilledCircles); - delay(100); - - uint32_t usecCircles = testCircles(10, TFT_WHITE); - Serial.print(F("Circles (outline) ")); - Serial.println(usecCircles); - delay(100); - - uint32_t usecTriangles = testTriangles(); - Serial.print(F("Triangles (outline) ")); - Serial.println(usecTriangles); - delay(100); - - uint32_t usecFilledTrangles = testFilledTriangles(); - Serial.print(F("Triangles (filled) ")); - Serial.println(usecFilledTrangles); - delay(100); - - uint32_t usecRoundRects = testRoundRects(); - Serial.print(F("Rounded rects (outline) ")); - Serial.println(usecRoundRects); - delay(100); - - uint32_t usedFilledRoundRects = testFilledRoundRects(); - Serial.print(F("Rounded rects (filled) ")); - Serial.println(usedFilledRoundRects); - delay(100); - - Serial.println(F("Done!")); - - uint16_t c = 4; - int8_t d = 1; - for (int32_t i = 0; i < ttgo->eTFT->height(); i++) { - ttgo->eTFT->drawFastHLine(0, i, ttgo->eTFT->width(), c); - c += d; - if (c <= 4 || c >= 11) - d = -d; - } - - ttgo->eTFT->setCursor(0, 0); - ttgo->eTFT->setTextColor(TFT_MAGENTA); - - ttgo->eTFT->println(F("Bodmer's TFT_eSPI")); - - ttgo->eTFT->setTextSize(1); - ttgo->eTFT->setTextColor(TFT_WHITE); - ttgo->eTFT->println(F("SPI TFT on ESP8266")); - ttgo->eTFT->println(F("")); - ttgo->eTFT->setTextSize(1); - ttgo->eTFT->setTextColor(ttgo->eTFT->color565(0x80, 0x80, 0x80)); - - // These are not compatible with the ESP8266 core library - //ttgo->eTFT->print(F("Flash=0x")); - //ttgo->eTFT->print((uint16_t)__data_load_end, HEX); - //ttgo->eTFT->print(F(" RAM=0x")); - //ttgo->eTFT->print((uint16_t)_end - (uint16_t)__data_start, HEX); - - ttgo->eTFT->setTextColor(TFT_GREEN); - ttgo->eTFT->print(F("Benchmark usec")); - - ttgo->eTFT->setTextColor(TFT_CYAN); - ttgo->eTFT->print(F("HaD logo ")); - ttgo->eTFT->setTextColor(TFT_YELLOW); - printnice(usecHaD); - - ttgo->eTFT->setTextColor(TFT_CYAN); - ttgo->eTFT->print(F("Clear ")); - ttgo->eTFT->setTextColor(TFT_YELLOW); - printnice(usecFillScreen); - - ttgo->eTFT->setTextColor(TFT_CYAN); - ttgo->eTFT->print(F("Text ")); - ttgo->eTFT->setTextColor(TFT_YELLOW); - printnice(usecText); - - ttgo->eTFT->setTextColor(TFT_CYAN); - ttgo->eTFT->print(F("Pixels ")); - ttgo->eTFT->setTextColor(TFT_YELLOW); - printnice(usecPixels); - - ttgo->eTFT->setTextColor(TFT_CYAN); - ttgo->eTFT->print(F("Lines ")); - ttgo->eTFT->setTextColor(TFT_YELLOW); - printnice(usecLines); - - ttgo->eTFT->setTextColor(TFT_CYAN); - ttgo->eTFT->print(F("H/V Lines ")); - ttgo->eTFT->setTextColor(TFT_YELLOW); - printnice(usecFastLines); - - ttgo->eTFT->setTextColor(TFT_CYAN); - ttgo->eTFT->print(F("Rectangles ")); - ttgo->eTFT->setTextColor(TFT_YELLOW); - printnice(usecRects); - - ttgo->eTFT->setTextColor(TFT_CYAN); - ttgo->eTFT->print(F("Rects-Fill ")); - ttgo->eTFT->setTextColor(TFT_YELLOW); - printnice(usecFilledRects); - - ttgo->eTFT->setTextColor(TFT_CYAN); - ttgo->eTFT->print(F("Circles ")); - ttgo->eTFT->setTextColor(TFT_YELLOW); - printnice(usecCircles); - - ttgo->eTFT->setTextColor(TFT_CYAN); - ttgo->eTFT->print(F("CircleFill ")); - ttgo->eTFT->setTextColor(TFT_YELLOW); - printnice(usecFilledCircles); - - ttgo->eTFT->setTextColor(TFT_CYAN); - ttgo->eTFT->print(F("Triangles ")); - ttgo->eTFT->setTextColor(TFT_YELLOW); - printnice(usecTriangles); - - ttgo->eTFT->setTextColor(TFT_CYAN); - ttgo->eTFT->print(F("Tris-Fill ")); - ttgo->eTFT->setTextColor(TFT_YELLOW); - printnice(usecFilledTrangles); - - ttgo->eTFT->setTextColor(TFT_CYAN); - ttgo->eTFT->print(F("Rnd-Rects ")); - ttgo->eTFT->setTextColor(TFT_YELLOW); - printnice(usecRoundRects); - - ttgo->eTFT->setTextColor(TFT_CYAN); - ttgo->eTFT->print(F("RRects-Fill")); - ttgo->eTFT->setTextColor(TFT_YELLOW); - printnice(usedFilledRoundRects); - - ttgo->eTFT->setTextSize(1); - ttgo->eTFT->println(F("")); - ttgo->eTFT->setTextColor(TFT_GREEN); - ttgo->eTFT->print(F("Benchmark Completed!")); - - delay(15 * 1000L); -} void printnice(int32_t v) { char str[32] = { 0 }; - sprintf(str, "%lu", v); + sprintf(str, "%ld", v); for (char *p = (str + strlen(str)) - 3; p > str; p -= 3) { memmove(p + 1, p, strlen(p) + 1); *p = ','; @@ -244,7 +43,7 @@ void printnice(int32_t v) memmove(str + 1, str, strlen(str) + 1); *str = ' '; } - ttgo->eTFT->print(str); + ttgo->tft->print(str); } static inline uint32_t micros_start() __attribute__ ((always_inline)); @@ -306,41 +105,41 @@ uint32_t testHaD() 0x09, 0x23, 0x08, 0x4e, 0x08, 0x96, 0x12 }; - ttgo->eTFT->fillScreen(TFT_BLACK); + ttgo->tft->fillScreen(TFT_BLACK); uint32_t start = micros_start(); - ttgo->eTFT->startWrite(); + ttgo->tft->startWrite(); for (int i = 0; i < 0x10; i++) { - ttgo->eTFT->setAddrWindow(0, 0, ttgo->eTFT->width(), ttgo->eTFT->height()); + ttgo->tft->setAddrWindow(0, 0, ttgo->tft->width(), ttgo->tft->height()); uint16_t cnt = 0; - uint16_t color = ttgo->eTFT->color565((i << 4) | i, (i << 4) | i, (i << 4) | i); + uint16_t color = ttgo->tft->color565((i << 4) | i, (i << 4) | i, (i << 4) | i); uint16_t curcolor = 0; const uint8_t *cmp = &HaD_128x160[0]; - ttgo->eTFT->startWrite(); + ttgo->tft->startWrite(); while (cmp < &HaD_128x160[sizeof(HaD_128x160)]) { cnt = pgm_read_byte(cmp++); if (cnt & 0x80) cnt = ((cnt & 0x7f) << 8) | pgm_read_byte(cmp++); - ttgo->eTFT->pushColor(curcolor, cnt); // PDQ_GFX has count + ttgo->tft->pushColor(curcolor, cnt); // PDQ_GFX has count curcolor ^= color; } - ttgo->eTFT->endWrite(); + ttgo->tft->endWrite(); } - ttgo->eTFT->endWrite(); + ttgo->tft->endWrite(); uint32_t t = micros() - start; - ttgo->eTFT->setTextColor(TFT_YELLOW); - ttgo->eTFT->setCursor(0, 145); - ttgo->eTFT->print(F(" http://hackaday.io/")); - ttgo->eTFT->print(F(" Xark")); + ttgo->tft->setTextColor(TFT_YELLOW); + ttgo->tft->setCursor(0, 145); + ttgo->tft->print(F(" http://hackaday.io/")); + ttgo->tft->print(F(" Xark")); delay(3 * 1000L); @@ -352,11 +151,11 @@ uint32_t testFillScreen() uint32_t start = micros_start(); for (uint8_t i = 0; i < 12; i++) { - ttgo->eTFT->fillScreen(TFT_WHITE); - ttgo->eTFT->fillScreen(TFT_RED); - ttgo->eTFT->fillScreen(TFT_GREEN); - ttgo->eTFT->fillScreen(TFT_BLUE); - ttgo->eTFT->fillScreen(TFT_BLACK); + ttgo->tft->fillScreen(TFT_WHITE); + ttgo->tft->fillScreen(TFT_RED); + ttgo->tft->fillScreen(TFT_GREEN); + ttgo->tft->fillScreen(TFT_BLUE); + ttgo->tft->fillScreen(TFT_BLACK); } return micros() - start; @@ -364,36 +163,36 @@ uint32_t testFillScreen() uint32_t testText() { - ttgo->eTFT->fillScreen(TFT_BLACK); + ttgo->tft->fillScreen(TFT_BLACK); uint32_t start = micros_start(); - ttgo->eTFT->setCursor(0, 0); - ttgo->eTFT->setTextColor(TFT_WHITE); ttgo->eTFT->setTextSize(1); - ttgo->eTFT->println(F("Hello World!")); - ttgo->eTFT->setTextColor(ttgo->eTFT->color565(0xff, 0x00, 0x00)); - ttgo->eTFT->print(F("RED ")); - ttgo->eTFT->setTextColor(ttgo->eTFT->color565(0x00, 0xff, 0x00)); - ttgo->eTFT->print(F("GREEN ")); - ttgo->eTFT->setTextColor(ttgo->eTFT->color565(0x00, 0x00, 0xff)); - ttgo->eTFT->println(F("BLUE")); - ttgo->eTFT->setTextColor(TFT_YELLOW); - ttgo->eTFT->println(1234.56); - ttgo->eTFT->setTextColor(TFT_RED); - ttgo->eTFT->println(0xDEADBEEF, HEX); - ttgo->eTFT->setTextColor(TFT_GREEN); - ttgo->eTFT->setTextSize(2); - ttgo->eTFT->println(F("Groop")); - ttgo->eTFT->println(F("I implore thee,")); - ttgo->eTFT->setTextSize(1); - ttgo->eTFT->println(F("my foonting turlingdromes.")); - ttgo->eTFT->println(F("And hooptiously drangle me")); - ttgo->eTFT->println(F("with crinkly bindlewurdles,")); - ttgo->eTFT->println(F("Or I will rend thee")); - ttgo->eTFT->println(F("in the gobberwarts")); - ttgo->eTFT->println(F("with my blurglecruncheon,")); - ttgo->eTFT->println(F("see if I don't!")); - ttgo->eTFT->println(F("")); - ttgo->eTFT->setTextColor(TFT_MAGENTA); - ttgo->eTFT->println(F("Woot!")); + ttgo->tft->setCursor(0, 0); + ttgo->tft->setTextColor(TFT_WHITE); ttgo->tft->setTextSize(1); + ttgo->tft->println(F("Hello World!")); + ttgo->tft->setTextColor(ttgo->tft->color565(0xff, 0x00, 0x00)); + ttgo->tft->print(F("RED ")); + ttgo->tft->setTextColor(ttgo->tft->color565(0x00, 0xff, 0x00)); + ttgo->tft->print(F("GREEN ")); + ttgo->tft->setTextColor(ttgo->tft->color565(0x00, 0x00, 0xff)); + ttgo->tft->println(F("BLUE")); + ttgo->tft->setTextColor(TFT_YELLOW); + ttgo->tft->println(1234.56); + ttgo->tft->setTextColor(TFT_RED); + ttgo->tft->println(0xDEADBEEF, HEX); + ttgo->tft->setTextColor(TFT_GREEN); + ttgo->tft->setTextSize(2); + ttgo->tft->println(F("Groop")); + ttgo->tft->println(F("I implore thee,")); + ttgo->tft->setTextSize(1); + ttgo->tft->println(F("my foonting turlingdromes.")); + ttgo->tft->println(F("And hooptiously drangle me")); + ttgo->tft->println(F("with crinkly bindlewurdles,")); + ttgo->tft->println(F("Or I will rend thee")); + ttgo->tft->println(F("in the gobberwarts")); + ttgo->tft->println(F("with my blurglecruncheon,")); + ttgo->tft->println(F("see if I don't!")); + ttgo->tft->println(F("")); + ttgo->tft->setTextColor(TFT_MAGENTA); + ttgo->tft->println(F("Woot!")); uint32_t t = micros() - start; delay(1000); return t; @@ -401,17 +200,17 @@ uint32_t testText() uint32_t testPixels() { - int32_t w = ttgo->eTFT->width(); - int32_t h = ttgo->eTFT->height(); + int32_t w = ttgo->tft->width(); + int32_t h = ttgo->tft->height(); uint32_t start = micros_start(); - ttgo->eTFT->startWrite(); + ttgo->tft->startWrite(); for (uint16_t y = 0; y < h; y++) { for (uint16_t x = 0; x < w; x++) { - ttgo->eTFT->drawPixel(x, y, ttgo->eTFT->color565(x << 3, y << 3, x * y)); + ttgo->tft->drawPixel(x, y, ttgo->tft->color565(x << 3, y << 3, x * y)); } } - ttgo->eTFT->endWrite(); + ttgo->tft->endWrite(); return micros() - start; } @@ -420,10 +219,10 @@ uint32_t testLines(uint16_t color) { uint32_t start, t; int32_t x1, y1, x2, y2; - int32_t w = ttgo->eTFT->width(); - int32_t h = ttgo->eTFT->height(); + int32_t w = ttgo->tft->width(); + int32_t h = ttgo->tft->height(); - ttgo->eTFT->fillScreen(TFT_BLACK); + ttgo->tft->fillScreen(TFT_BLACK); x1 = y1 = 0; y2 = h - 1; @@ -431,18 +230,18 @@ uint32_t testLines(uint16_t color) start = micros_start(); for (x2 = 0; x2 < w; x2 += 6) { - ttgo->eTFT->drawLine(x1, y1, x2, y2, color); + ttgo->tft->drawLine(x1, y1, x2, y2, color); } x2 = w - 1; for (y2 = 0; y2 < h; y2 += 6) { - ttgo->eTFT->drawLine(x1, y1, x2, y2, color); + ttgo->tft->drawLine(x1, y1, x2, y2, color); } t = micros() - start; // fillScreen doesn't count against timing - ttgo->eTFT->fillScreen(TFT_BLACK); + ttgo->tft->fillScreen(TFT_BLACK); x1 = w - 1; y1 = 0; @@ -451,17 +250,17 @@ uint32_t testLines(uint16_t color) start = micros_start(); for (x2 = 0; x2 < w; x2 += 6) { - ttgo->eTFT->drawLine(x1, y1, x2, y2, color); + ttgo->tft->drawLine(x1, y1, x2, y2, color); } x2 = 0; for (y2 = 0; y2 < h; y2 += 6) { - ttgo->eTFT->drawLine(x1, y1, x2, y2, color); + ttgo->tft->drawLine(x1, y1, x2, y2, color); } t += micros() - start; - ttgo->eTFT->fillScreen(TFT_BLACK); + ttgo->tft->fillScreen(TFT_BLACK); x1 = 0; y1 = h - 1; @@ -470,15 +269,15 @@ uint32_t testLines(uint16_t color) start = micros_start(); for (x2 = 0; x2 < w; x2 += 6) { - ttgo->eTFT->drawLine(x1, y1, x2, y2, color); + ttgo->tft->drawLine(x1, y1, x2, y2, color); } x2 = w - 1; for (y2 = 0; y2 < h; y2 += 6) { - ttgo->eTFT->drawLine(x1, y1, x2, y2, color); + ttgo->tft->drawLine(x1, y1, x2, y2, color); } t += micros() - start; - ttgo->eTFT->fillScreen(TFT_BLACK); + ttgo->tft->fillScreen(TFT_BLACK); x1 = w - 1; y1 = h - 1; @@ -487,12 +286,12 @@ uint32_t testLines(uint16_t color) start = micros_start(); for (x2 = 0; x2 < w; x2 += 6) { - ttgo->eTFT->drawLine(x1, y1, x2, y2, color); + ttgo->tft->drawLine(x1, y1, x2, y2, color); } x2 = 0; for (y2 = 0; y2 < h; y2 += 6) { - ttgo->eTFT->drawLine(x1, y1, x2, y2, color); + ttgo->tft->drawLine(x1, y1, x2, y2, color); } t += micros() - start; @@ -504,17 +303,17 @@ uint32_t testFastLines(uint16_t color1, uint16_t color2) { uint32_t start; int32_t x, y; - int32_t w = ttgo->eTFT->width(); - int32_t h = ttgo->eTFT->height(); + int32_t w = ttgo->tft->width(); + int32_t h = ttgo->tft->height(); - ttgo->eTFT->fillScreen(TFT_BLACK); + ttgo->tft->fillScreen(TFT_BLACK); start = micros_start(); for (y = 0; y < h; y += 5) - ttgo->eTFT->drawFastHLine(0, y, w, color1); + ttgo->tft->drawFastHLine(0, y, w, color1); for (x = 0; x < w; x += 5) - ttgo->eTFT->drawFastVLine(x, 0, h, color2); + ttgo->tft->drawFastVLine(x, 0, h, color2); return micros() - start; } @@ -523,15 +322,15 @@ uint32_t testRects(uint16_t color) { uint32_t start; int32_t n, i, i2; - int32_t cx = ttgo->eTFT->width() / 2; - int32_t cy = ttgo->eTFT->height() / 2; + int32_t cx = ttgo->tft->width() / 2; + int32_t cy = ttgo->tft->height() / 2; - ttgo->eTFT->fillScreen(TFT_BLACK); - n = min(ttgo->eTFT->width(), ttgo->eTFT->height()); + ttgo->tft->fillScreen(TFT_BLACK); + n = min(ttgo->tft->width(), ttgo->tft->height()); start = micros_start(); for (i = 2; i < n; i += 6) { i2 = i / 2; - ttgo->eTFT->drawRect(cx - i2, cy - i2, i, i, color); + ttgo->tft->drawRect(cx - i2, cy - i2, i, i, color); } return micros() - start; @@ -541,22 +340,22 @@ uint32_t testFilledRects(uint16_t color1, uint16_t color2) { uint32_t start, t = 0; int32_t n, i, i2; - int32_t cx = ttgo->eTFT->width() / 2 - 1; - int32_t cy = ttgo->eTFT->height() / 2 - 1; + int32_t cx = ttgo->tft->width() / 2 - 1; + int32_t cy = ttgo->tft->height() / 2 - 1; - ttgo->eTFT->fillScreen(TFT_BLACK); - n = min(ttgo->eTFT->width(), ttgo->eTFT->height()); + ttgo->tft->fillScreen(TFT_BLACK); + n = min(ttgo->tft->width(), ttgo->tft->height()); for (i = n; i > 0; i -= 6) { i2 = i / 2; start = micros_start(); - ttgo->eTFT->fillRect(cx - i2, cy - i2, i, i, color1); + ttgo->tft->fillRect(cx - i2, cy - i2, i, i, color1); t += micros() - start; // Outlines are not included in timing results - ttgo->eTFT->drawRect(cx - i2, cy - i2, i, i, color2); + ttgo->tft->drawRect(cx - i2, cy - i2, i, i, color2); } return t; @@ -565,15 +364,15 @@ uint32_t testFilledRects(uint16_t color1, uint16_t color2) uint32_t testFilledCircles(uint8_t radius, uint16_t color) { uint32_t start; - int32_t x, y, w = ttgo->eTFT->width(), h = ttgo->eTFT->height(), r2 = radius * 2; + int32_t x, y, w = ttgo->tft->width(), h = ttgo->tft->height(), r2 = radius * 2; - ttgo->eTFT->fillScreen(TFT_BLACK); + ttgo->tft->fillScreen(TFT_BLACK); start = micros_start(); for (x = radius; x < w; x += r2) { for (y = radius; y < h; y += r2) { - ttgo->eTFT->fillCircle(x, y, radius, color); + ttgo->tft->fillCircle(x, y, radius, color); } } @@ -584,8 +383,8 @@ uint32_t testCircles(uint8_t radius, uint16_t color) { uint32_t start; int32_t x, y, r2 = radius * 2; - int32_t w = ttgo->eTFT->width() + radius; - int32_t h = ttgo->eTFT->height() + radius; + int32_t w = ttgo->tft->width() + radius; + int32_t h = ttgo->tft->height() + radius; // Screen is not cleared for this one -- this is // intentional and does not affect the reported time. @@ -593,7 +392,7 @@ uint32_t testCircles(uint8_t radius, uint16_t color) for (x = 0; x < w; x += r2) { for (y = 0; y < h; y += r2) { - ttgo->eTFT->drawCircle(x, y, radius, color); + ttgo->tft->drawCircle(x, y, radius, color); } } @@ -604,20 +403,20 @@ uint32_t testTriangles() { uint32_t start; int32_t n, i; - int32_t cx = ttgo->eTFT->width() / 2 - 1; - int32_t cy = ttgo->eTFT->height() / 2 - 1; + int32_t cx = ttgo->tft->width() / 2 - 1; + int32_t cy = ttgo->tft->height() / 2 - 1; - ttgo->eTFT->fillScreen(TFT_BLACK); + ttgo->tft->fillScreen(TFT_BLACK); n = min(cx, cy); start = micros_start(); for (i = 0; i < n; i += 5) { - ttgo->eTFT->drawTriangle( + ttgo->tft->drawTriangle( cx, cy - i, // peak cx - i, cy + i, // bottom left cx + i, cy + i, // bottom right - ttgo->eTFT->color565(0, 0, i)); + ttgo->tft->color565(0, 0, i)); } return micros() - start; @@ -627,20 +426,20 @@ uint32_t testFilledTriangles() { uint32_t start, t = 0; int32_t i; - int32_t cx = ttgo->eTFT->width() / 2 - 1; - int32_t cy = ttgo->eTFT->height() / 2 - 1; + int32_t cx = ttgo->tft->width() / 2 - 1; + int32_t cy = ttgo->tft->height() / 2 - 1; - ttgo->eTFT->fillScreen(TFT_BLACK); + ttgo->tft->fillScreen(TFT_BLACK); start = micros_start(); for (i = min(cx, cy); i > 10; i -= 5) { start = micros_start(); - ttgo->eTFT->fillTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i, - ttgo->eTFT->color565(0, i, i)); + ttgo->tft->fillTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i, + ttgo->tft->color565(0, i, i)); t += micros() - start; - ttgo->eTFT->drawTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i, - ttgo->eTFT->color565(i, i, 0)); + ttgo->tft->drawTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i, + ttgo->tft->color565(i, i, 0)); } return t; @@ -650,18 +449,18 @@ uint32_t testRoundRects() { uint32_t start; int32_t w, i, i2; - int32_t cx = ttgo->eTFT->width() / 2 - 1; - int32_t cy = ttgo->eTFT->height() / 2 - 1; + int32_t cx = ttgo->tft->width() / 2 - 1; + int32_t cy = ttgo->tft->height() / 2 - 1; - ttgo->eTFT->fillScreen(TFT_BLACK); + ttgo->tft->fillScreen(TFT_BLACK); - w = min(ttgo->eTFT->width(), ttgo->eTFT->height()); + w = min(ttgo->tft->width(), ttgo->tft->height()); start = micros_start(); for (i = 0; i < w; i += 6) { i2 = i / 2; - ttgo->eTFT->drawRoundRect(cx - i2, cy - i2, i, i, i / 8, ttgo->eTFT->color565(i, 0, 0)); + ttgo->tft->drawRoundRect(cx - i2, cy - i2, i, i, i / 8, ttgo->tft->color565(i, 0, 0)); } return micros() - start; @@ -671,17 +470,223 @@ uint32_t testFilledRoundRects() { uint32_t start; int32_t i, i2; - int32_t cx = ttgo->eTFT->width() / 2 - 1; - int32_t cy = ttgo->eTFT->height() / 2 - 1; + int32_t cx = ttgo->tft->width() / 2 - 1; + int32_t cy = ttgo->tft->height() / 2 - 1; - ttgo->eTFT->fillScreen(TFT_BLACK); + ttgo->tft->fillScreen(TFT_BLACK); start = micros_start(); - for (i = min(ttgo->eTFT->width(), ttgo->eTFT->height()); i > 20; i -= 6) { + for (i = min(ttgo->tft->width(), ttgo->tft->height()); i > 20; i -= 6) { i2 = i / 2; - ttgo->eTFT->fillRoundRect(cx - i2, cy - i2, i, i, i / 8, ttgo->eTFT->color565(0, i, 0)); + ttgo->tft->fillRoundRect(cx - i2, cy - i2, i, i, i / 8, ttgo->tft->color565(0, i, 0)); } return micros() - start; } + + +void setup() +{ + Serial.begin(115200); + Serial.println(F("TFT 1.8\" SPI TFT Test! ")); + ttgo = TTGOClass::getWatch(); + ttgo->begin(); + ttgo->openBL(); + ttgo->tft->setTextFont(1); +} + +// NOTE: This demo should run, but may look odd on 128x128 LCD (vs 128x160) + +void loop(void) +{ + + Serial.print(F(__DATE__ " " __TIME__ " - Flash=0x")); + // These are not compatible with the ESP8266 core library + //Serial.print((uint16_t)__data_load_end, HEX); + //Serial.print(F(" RAM=0x")); + //Serial.println((uint16_t)_end - (uint16_t)__data_start, HEX); + Serial.println(F("Benchmark Time (microseconds)")); + + uint32_t usecHaD = testHaD(); + Serial.print(F("HaD pushColor ")); + Serial.println(usecHaD); + delay(100); + + + uint32_t usecFillScreen = testFillScreen(); + Serial.print(F("Screen fill ")); + Serial.println(usecFillScreen); + delay(100); + + ttgo->tft->setRotation(1); + uint32_t usecText = testText(); + Serial.print(F("Text ")); + Serial.println(usecText); + delay(100); + ttgo->tft->setRotation(0); + + uint32_t usecPixels = testPixels(); + Serial.print(F("Pixels ")); + Serial.println(usecPixels); + delay(100); + + uint32_t usecLines = testLines(TFT_BLUE); + Serial.print(F("Lines ")); + Serial.println(usecLines); + delay(100); + + uint32_t usecFastLines = testFastLines(TFT_RED, TFT_BLUE); + Serial.print(F("Horiz/Vert Lines ")); + Serial.println(usecFastLines); + delay(100); + + uint32_t usecRects = testRects(TFT_GREEN); + Serial.print(F("Rectangles (outline) ")); + Serial.println(usecRects); + delay(100); + + uint32_t usecFilledRects = testFilledRects(TFT_YELLOW, TFT_MAGENTA); + Serial.print(F("Rectangles (filled) ")); + Serial.println(usecFilledRects); + delay(100); + + uint32_t usecFilledCircles = testFilledCircles(10, TFT_MAGENTA); + Serial.print(F("Circles (filled) ")); + Serial.println(usecFilledCircles); + delay(100); + + uint32_t usecCircles = testCircles(10, TFT_WHITE); + Serial.print(F("Circles (outline) ")); + Serial.println(usecCircles); + delay(100); + + uint32_t usecTriangles = testTriangles(); + Serial.print(F("Triangles (outline) ")); + Serial.println(usecTriangles); + delay(100); + + uint32_t usecFilledTrangles = testFilledTriangles(); + Serial.print(F("Triangles (filled) ")); + Serial.println(usecFilledTrangles); + delay(100); + + uint32_t usecRoundRects = testRoundRects(); + Serial.print(F("Rounded rects (outline) ")); + Serial.println(usecRoundRects); + delay(100); + + uint32_t usedFilledRoundRects = testFilledRoundRects(); + Serial.print(F("Rounded rects (filled) ")); + Serial.println(usedFilledRoundRects); + delay(100); + + Serial.println(F("Done!")); + + uint16_t c = 4; + int8_t d = 1; + for (int32_t i = 0; i < ttgo->tft->height(); i++) { + ttgo->tft->drawFastHLine(0, i, ttgo->tft->width(), c); + c += d; + if (c <= 4 || c >= 11) + d = -d; + } + + ttgo->tft->setCursor(0, 0); + ttgo->tft->setTextColor(TFT_MAGENTA); + + ttgo->tft->println(F("Bodmer's TFT_eSPI")); + + ttgo->tft->setTextSize(1); + ttgo->tft->setTextColor(TFT_WHITE); + ttgo->tft->println(F("SPI TFT on ESP8266")); + ttgo->tft->println(F("")); + ttgo->tft->setTextSize(1); + ttgo->tft->setTextColor(ttgo->tft->color565(0x80, 0x80, 0x80)); + + // These are not compatible with the ESP8266 core library + //ttgo->tft->print(F("Flash=0x")); + //ttgo->tft->print((uint16_t)__data_load_end, HEX); + //ttgo->tft->print(F(" RAM=0x")); + //ttgo->tft->print((uint16_t)_end - (uint16_t)__data_start, HEX); + + ttgo->tft->setTextColor(TFT_GREEN); + ttgo->tft->print(F("Benchmark usec")); + + ttgo->tft->setTextColor(TFT_CYAN); + ttgo->tft->print(F("HaD logo ")); + ttgo->tft->setTextColor(TFT_YELLOW); + printnice(usecHaD); + + ttgo->tft->setTextColor(TFT_CYAN); + ttgo->tft->print(F("Clear ")); + ttgo->tft->setTextColor(TFT_YELLOW); + printnice(usecFillScreen); + + ttgo->tft->setTextColor(TFT_CYAN); + ttgo->tft->print(F("Text ")); + ttgo->tft->setTextColor(TFT_YELLOW); + printnice(usecText); + + ttgo->tft->setTextColor(TFT_CYAN); + ttgo->tft->print(F("Pixels ")); + ttgo->tft->setTextColor(TFT_YELLOW); + printnice(usecPixels); + + ttgo->tft->setTextColor(TFT_CYAN); + ttgo->tft->print(F("Lines ")); + ttgo->tft->setTextColor(TFT_YELLOW); + printnice(usecLines); + + ttgo->tft->setTextColor(TFT_CYAN); + ttgo->tft->print(F("H/V Lines ")); + ttgo->tft->setTextColor(TFT_YELLOW); + printnice(usecFastLines); + + ttgo->tft->setTextColor(TFT_CYAN); + ttgo->tft->print(F("Rectangles ")); + ttgo->tft->setTextColor(TFT_YELLOW); + printnice(usecRects); + + ttgo->tft->setTextColor(TFT_CYAN); + ttgo->tft->print(F("Rects-Fill ")); + ttgo->tft->setTextColor(TFT_YELLOW); + printnice(usecFilledRects); + + ttgo->tft->setTextColor(TFT_CYAN); + ttgo->tft->print(F("Circles ")); + ttgo->tft->setTextColor(TFT_YELLOW); + printnice(usecCircles); + + ttgo->tft->setTextColor(TFT_CYAN); + ttgo->tft->print(F("CircleFill ")); + ttgo->tft->setTextColor(TFT_YELLOW); + printnice(usecFilledCircles); + + ttgo->tft->setTextColor(TFT_CYAN); + ttgo->tft->print(F("Triangles ")); + ttgo->tft->setTextColor(TFT_YELLOW); + printnice(usecTriangles); + + ttgo->tft->setTextColor(TFT_CYAN); + ttgo->tft->print(F("Tris-Fill ")); + ttgo->tft->setTextColor(TFT_YELLOW); + printnice(usecFilledTrangles); + + ttgo->tft->setTextColor(TFT_CYAN); + ttgo->tft->print(F("Rnd-Rects ")); + ttgo->tft->setTextColor(TFT_YELLOW); + printnice(usecRoundRects); + + ttgo->tft->setTextColor(TFT_CYAN); + ttgo->tft->print(F("RRects-Fill")); + ttgo->tft->setTextColor(TFT_YELLOW); + printnice(usedFilledRoundRects); + + ttgo->tft->setTextSize(1); + ttgo->tft->println(F("")); + ttgo->tft->setTextColor(TFT_GREEN); + ttgo->tft->print(F("Benchmark Completed!")); + + delay(15 * 1000L); +} \ No newline at end of file diff --git a/examples/TFT_eSPI/TFT_graphicstest_small/TFT_graphicstest_small.ino b/examples/TFT_eSPI/TFT_graphicstest_small/TFT_graphicstest_small.ino index a0179e7..0b2796c 100644 --- a/examples/TFT_eSPI/TFT_graphicstest_small/TFT_graphicstest_small.ino +++ b/examples/TFT_eSPI/TFT_graphicstest_small/TFT_graphicstest_small.ino @@ -15,31 +15,231 @@ ######################################################################### */ -#include +// => Hardware select +// #define LILYGO_WATCH_2019_WITH_TOUCH // To use T-Watch2019 with touchscreen, please uncomment this line +// #define LILYGO_WATCH_2019_NO_TOUCH // To use T-Watch2019 Not touchscreen , please uncomment this line +// #define LILYGO_WATCH_2020_V1 //To use T-Watch2020, please uncomment this line + +#include TTGOClass *ttgo; float p = 3.1415926; + +void testlines(uint16_t color) +{ + ttgo->tft->fillScreen(TFT_BLACK); + for (int16_t x = 0; x < ttgo->tft->width(); x += 6) { + ttgo->tft->drawLine(0, 0, x, ttgo->tft->height() - 1, color); + } + for (int16_t y = 0; y < ttgo->tft->height(); y += 6) { + ttgo->tft->drawLine(0, 0, ttgo->tft->width() - 1, y, color); + } + + ttgo->tft->fillScreen(TFT_BLACK); + for (int16_t x = 0; x < ttgo->tft->width(); x += 6) { + ttgo->tft->drawLine(ttgo->tft->width() - 1, 0, x, ttgo->tft->height() - 1, color); + } + for (int16_t y = 0; y < ttgo->tft->height(); y += 6) { + ttgo->tft->drawLine(ttgo->tft->width() - 1, 0, 0, y, color); + } + + ttgo->tft->fillScreen(TFT_BLACK); + for (int16_t x = 0; x < ttgo->tft->width(); x += 6) { + ttgo->tft->drawLine(0, ttgo->tft->height() - 1, x, 0, color); + } + for (int16_t y = 0; y < ttgo->tft->height(); y += 6) { + ttgo->tft->drawLine(0, ttgo->tft->height() - 1, ttgo->tft->width() - 1, y, color); + } + + ttgo->tft->fillScreen(TFT_BLACK); + for (int16_t x = 0; x < ttgo->tft->width(); x += 6) { + ttgo->tft->drawLine(ttgo->tft->width() - 1, ttgo->tft->height() - 1, x, 0, color); + } + for (int16_t y = 0; y < ttgo->tft->height(); y += 6) { + ttgo->tft->drawLine(ttgo->tft->width() - 1, ttgo->tft->height() - 1, 0, y, color); + } +} + +void testdrawtext(char *text, uint16_t color) +{ + ttgo->tft->setCursor(0, 0); + ttgo->tft->setTextColor(color); + ttgo->tft->setTextWrap(true); + ttgo->tft->print(text); +} + +void testfastlines(uint16_t color1, uint16_t color2) +{ + ttgo->tft->fillScreen(TFT_BLACK); + for (int16_t y = 0; y < ttgo->tft->height(); y += 5) { + ttgo->tft->drawFastHLine(0, y, ttgo->tft->width(), color1); + } + for (int16_t x = 0; x < ttgo->tft->width(); x += 5) { + ttgo->tft->drawFastVLine(x, 0, ttgo->tft->height(), color2); + } +} + +void testdrawrects(uint16_t color) +{ + ttgo->tft->fillScreen(TFT_BLACK); + for (int16_t x = 0; x < ttgo->tft->width(); x += 6) { + ttgo->tft->drawRect(ttgo->tft->width() / 2 - x / 2, ttgo->tft->height() / 2 - x / 2, x, x, color); + } +} + +void testfillrects(uint16_t color1, uint16_t color2) +{ + ttgo->tft->fillScreen(TFT_BLACK); + for (int16_t x = ttgo->tft->width() - 1; x > 6; x -= 6) { + ttgo->tft->fillRect(ttgo->tft->width() / 2 - x / 2, ttgo->tft->height() / 2 - x / 2, x, x, color1); + ttgo->tft->drawRect(ttgo->tft->width() / 2 - x / 2, ttgo->tft->height() / 2 - x / 2, x, x, color2); + } +} + +void testfillcircles(uint8_t radius, uint16_t color) +{ + for (int16_t x = radius; x < ttgo->tft->width(); x += radius * 2) { + for (int16_t y = radius; y < ttgo->tft->height(); y += radius * 2) { + ttgo->tft->fillCircle(x, y, radius, color); + } + } +} + +void testdrawcircles(uint8_t radius, uint16_t color) +{ + for (int16_t x = 0; x < ttgo->tft->width() + radius; x += radius * 2) { + for (int16_t y = 0; y < ttgo->tft->height() + radius; y += radius * 2) { + ttgo->tft->drawCircle(x, y, radius, color); + } + } +} + +void testtriangles() +{ + ttgo->tft->fillScreen(TFT_BLACK); + int color = 0xF800; + int t; + int w = ttgo->tft->width() / 2; + int x = ttgo->tft->height() - 1; + int y = 0; + int z = ttgo->tft->width(); + for (t = 0 ; t <= 15; t += 1) { + ttgo->tft->drawTriangle(w, y, y, x, z, x, color); + x -= 4; + y += 4; + z -= 4; + color += 100; + } +} + +void testroundrects() +{ + ttgo->tft->fillScreen(TFT_BLACK); + int color = 100; + int i; + int t; + for (t = 0 ; t <= 4; t += 1) { + int x = 0; + int y = 0; + int w = ttgo->tft->width() - 2; + int h = ttgo->tft->height() - 2; + for (i = 0 ; i <= 16; i += 1) { + ttgo->tft->drawRoundRect(x, y, w, h, 5, color); + x += 2; + y += 3; + w -= 4; + h -= 6; + color += 1100; + } + color += 100; + } +} + +void tftPrintTest() +{ + ttgo->tft->setTextWrap(false); + ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->setCursor(0, 30); + ttgo->tft->setTextColor(TFT_RED); + ttgo->tft->setTextSize(1); + ttgo->tft->println("Hello World!"); + ttgo->tft->setTextColor(TFT_YELLOW); + ttgo->tft->setTextSize(2); + ttgo->tft->println("Hello World!"); + ttgo->tft->setTextColor(TFT_GREEN); + ttgo->tft->setTextSize(3); + ttgo->tft->println("Hello World!"); + ttgo->tft->setTextColor(TFT_BLUE); + ttgo->tft->setTextSize(4); + ttgo->tft->print(1234.567); + delay(1500); + ttgo->tft->setCursor(0, 0); + ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->setTextColor(TFT_WHITE); + ttgo->tft->setTextSize(0); + ttgo->tft->println("Hello World!"); + ttgo->tft->setTextSize(1); + ttgo->tft->setTextColor(TFT_GREEN); + ttgo->tft->print(p, 6); + ttgo->tft->println(" Want pi?"); + ttgo->tft->println(" "); + ttgo->tft->print(8675309, HEX); // print 8,675,309 out in HEX! + ttgo->tft->println(" Print HEX!"); + ttgo->tft->println(" "); + ttgo->tft->setTextColor(TFT_WHITE); + ttgo->tft->println("Sketch has been"); + ttgo->tft->println("running for: "); + ttgo->tft->setTextColor(TFT_MAGENTA); + ttgo->tft->print(millis() / 1000); + ttgo->tft->setTextColor(TFT_WHITE); + ttgo->tft->print(" seconds."); +} + +void mediabuttons() +{ + // play + ttgo->tft->fillScreen(TFT_BLACK); + ttgo->tft->fillRoundRect(25, 10, 78, 60, 8, TFT_WHITE); + ttgo->tft->fillTriangle(42, 20, 42, 60, 90, 40, TFT_RED); + delay(500); + // pause + ttgo->tft->fillRoundRect(25, 90, 78, 60, 8, TFT_WHITE); + ttgo->tft->fillRoundRect(39, 98, 20, 45, 5, TFT_GREEN); + ttgo->tft->fillRoundRect(69, 98, 20, 45, 5, TFT_GREEN); + delay(500); + // play color + ttgo->tft->fillTriangle(42, 20, 42, 60, 90, 40, TFT_BLUE); + delay(50); + // pause color + ttgo->tft->fillRoundRect(39, 98, 20, 45, 5, TFT_RED); + ttgo->tft->fillRoundRect(69, 98, 20, 45, 5, TFT_RED); + // play color + ttgo->tft->fillTriangle(42, 20, 42, 60, 90, 40, TFT_GREEN); +} + + void setup(void) { - Serial.begin(9600); + Serial.begin(115200); ttgo = TTGOClass::getWatch(); ttgo->begin(); ttgo->openBL(); + ttgo->tft->setTextFont(1); Serial.println("Initialized"); uint16_t time = millis(); - ttgo->eTFT->fillScreen(TFT_BLACK); + ttgo->tft->fillScreen(TFT_BLACK); time = millis() - time; Serial.println(time, DEC); delay(500); // large block of text - ttgo->eTFT->fillScreen(TFT_BLACK); + ttgo->tft->fillScreen(TFT_BLACK); testdrawtext("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur adipiscing ante sed nibh tincidunt feugiat. Maecenas enim massa, fringilla sed malesuada et, malesuada sit amet turpis. Sed porttitor neque ut ante pretium vitae malesuada nunc bibendum. Nullam aliquet ultrices massa eu hendrerit. Ut sed nisi lorem. In vestibulum purus a tortor imperdiet posuere. ", TFT_WHITE); delay(1000); @@ -48,7 +248,7 @@ void setup(void) delay(4000); // a single pixel - ttgo->eTFT->drawPixel(ttgo->eTFT->width() / 2, ttgo->eTFT->height() / 2, TFT_GREEN); + ttgo->tft->drawPixel(ttgo->tft->width() / 2, ttgo->tft->height() / 2, TFT_GREEN); delay(500); // line draw test @@ -65,7 +265,7 @@ void setup(void) testfillrects(TFT_YELLOW, TFT_MAGENTA); delay(500); - ttgo->eTFT->fillScreen(TFT_BLACK); + ttgo->tft->fillScreen(TFT_BLACK); testfillcircles(10, TFT_BLUE); testdrawcircles(10, TFT_WHITE); delay(500); @@ -85,201 +285,8 @@ void setup(void) void loop() { - ttgo->eTFT->invertDisplay(true); + ttgo->tft->invertDisplay(true); delay(500); - ttgo->eTFT->invertDisplay(false); + ttgo->tft->invertDisplay(false); delay(500); -} - -void testlines(uint16_t color) -{ - ttgo->eTFT->fillScreen(TFT_BLACK); - for (int16_t x = 0; x < ttgo->eTFT->width(); x += 6) { - ttgo->eTFT->drawLine(0, 0, x, ttgo->eTFT->height() - 1, color); - } - for (int16_t y = 0; y < ttgo->eTFT->height(); y += 6) { - ttgo->eTFT->drawLine(0, 0, ttgo->eTFT->width() - 1, y, color); - } - - ttgo->eTFT->fillScreen(TFT_BLACK); - for (int16_t x = 0; x < ttgo->eTFT->width(); x += 6) { - ttgo->eTFT->drawLine(ttgo->eTFT->width() - 1, 0, x, ttgo->eTFT->height() - 1, color); - } - for (int16_t y = 0; y < ttgo->eTFT->height(); y += 6) { - ttgo->eTFT->drawLine(ttgo->eTFT->width() - 1, 0, 0, y, color); - } - - ttgo->eTFT->fillScreen(TFT_BLACK); - for (int16_t x = 0; x < ttgo->eTFT->width(); x += 6) { - ttgo->eTFT->drawLine(0, ttgo->eTFT->height() - 1, x, 0, color); - } - for (int16_t y = 0; y < ttgo->eTFT->height(); y += 6) { - ttgo->eTFT->drawLine(0, ttgo->eTFT->height() - 1, ttgo->eTFT->width() - 1, y, color); - } - - ttgo->eTFT->fillScreen(TFT_BLACK); - for (int16_t x = 0; x < ttgo->eTFT->width(); x += 6) { - ttgo->eTFT->drawLine(ttgo->eTFT->width() - 1, ttgo->eTFT->height() - 1, x, 0, color); - } - for (int16_t y = 0; y < ttgo->eTFT->height(); y += 6) { - ttgo->eTFT->drawLine(ttgo->eTFT->width() - 1, ttgo->eTFT->height() - 1, 0, y, color); - } -} - -void testdrawtext(char *text, uint16_t color) -{ - ttgo->eTFT->setCursor(0, 0); - ttgo->eTFT->setTextColor(color); - ttgo->eTFT->setTextWrap(true); - ttgo->eTFT->print(text); -} - -void testfastlines(uint16_t color1, uint16_t color2) -{ - ttgo->eTFT->fillScreen(TFT_BLACK); - for (int16_t y = 0; y < ttgo->eTFT->height(); y += 5) { - ttgo->eTFT->drawFastHLine(0, y, ttgo->eTFT->width(), color1); - } - for (int16_t x = 0; x < ttgo->eTFT->width(); x += 5) { - ttgo->eTFT->drawFastVLine(x, 0, ttgo->eTFT->height(), color2); - } -} - -void testdrawrects(uint16_t color) -{ - ttgo->eTFT->fillScreen(TFT_BLACK); - for (int16_t x = 0; x < ttgo->eTFT->width(); x += 6) { - ttgo->eTFT->drawRect(ttgo->eTFT->width() / 2 - x / 2, ttgo->eTFT->height() / 2 - x / 2, x, x, color); - } -} - -void testfillrects(uint16_t color1, uint16_t color2) -{ - ttgo->eTFT->fillScreen(TFT_BLACK); - for (int16_t x = ttgo->eTFT->width() - 1; x > 6; x -= 6) { - ttgo->eTFT->fillRect(ttgo->eTFT->width() / 2 - x / 2, ttgo->eTFT->height() / 2 - x / 2, x, x, color1); - ttgo->eTFT->drawRect(ttgo->eTFT->width() / 2 - x / 2, ttgo->eTFT->height() / 2 - x / 2, x, x, color2); - } -} - -void testfillcircles(uint8_t radius, uint16_t color) -{ - for (int16_t x = radius; x < ttgo->eTFT->width(); x += radius * 2) { - for (int16_t y = radius; y < ttgo->eTFT->height(); y += radius * 2) { - ttgo->eTFT->fillCircle(x, y, radius, color); - } - } -} - -void testdrawcircles(uint8_t radius, uint16_t color) -{ - for (int16_t x = 0; x < ttgo->eTFT->width() + radius; x += radius * 2) { - for (int16_t y = 0; y < ttgo->eTFT->height() + radius; y += radius * 2) { - ttgo->eTFT->drawCircle(x, y, radius, color); - } - } -} - -void testtriangles() -{ - ttgo->eTFT->fillScreen(TFT_BLACK); - int color = 0xF800; - int t; - int w = ttgo->eTFT->width() / 2; - int x = ttgo->eTFT->height() - 1; - int y = 0; - int z = ttgo->eTFT->width(); - for (t = 0 ; t <= 15; t += 1) { - ttgo->eTFT->drawTriangle(w, y, y, x, z, x, color); - x -= 4; - y += 4; - z -= 4; - color += 100; - } -} - -void testroundrects() -{ - ttgo->eTFT->fillScreen(TFT_BLACK); - int color = 100; - int i; - int t; - for (t = 0 ; t <= 4; t += 1) { - int x = 0; - int y = 0; - int w = ttgo->eTFT->width() - 2; - int h = ttgo->eTFT->height() - 2; - for (i = 0 ; i <= 16; i += 1) { - ttgo->eTFT->drawRoundRect(x, y, w, h, 5, color); - x += 2; - y += 3; - w -= 4; - h -= 6; - color += 1100; - } - color += 100; - } -} - -void tftPrintTest() -{ - ttgo->eTFT->setTextWrap(false); - ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->setCursor(0, 30); - ttgo->eTFT->setTextColor(TFT_RED); - ttgo->eTFT->setTextSize(1); - ttgo->eTFT->println("Hello World!"); - ttgo->eTFT->setTextColor(TFT_YELLOW); - ttgo->eTFT->setTextSize(2); - ttgo->eTFT->println("Hello World!"); - ttgo->eTFT->setTextColor(TFT_GREEN); - ttgo->eTFT->setTextSize(3); - ttgo->eTFT->println("Hello World!"); - ttgo->eTFT->setTextColor(TFT_BLUE); - ttgo->eTFT->setTextSize(4); - ttgo->eTFT->print(1234.567); - delay(1500); - ttgo->eTFT->setCursor(0, 0); - ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->setTextColor(TFT_WHITE); - ttgo->eTFT->setTextSize(0); - ttgo->eTFT->println("Hello World!"); - ttgo->eTFT->setTextSize(1); - ttgo->eTFT->setTextColor(TFT_GREEN); - ttgo->eTFT->print(p, 6); - ttgo->eTFT->println(" Want pi?"); - ttgo->eTFT->println(" "); - ttgo->eTFT->print(8675309, HEX); // print 8,675,309 out in HEX! - ttgo->eTFT->println(" Print HEX!"); - ttgo->eTFT->println(" "); - ttgo->eTFT->setTextColor(TFT_WHITE); - ttgo->eTFT->println("Sketch has been"); - ttgo->eTFT->println("running for: "); - ttgo->eTFT->setTextColor(TFT_MAGENTA); - ttgo->eTFT->print(millis() / 1000); - ttgo->eTFT->setTextColor(TFT_WHITE); - ttgo->eTFT->print(" seconds."); -} - -void mediabuttons() -{ - // play - ttgo->eTFT->fillScreen(TFT_BLACK); - ttgo->eTFT->fillRoundRect(25, 10, 78, 60, 8, TFT_WHITE); - ttgo->eTFT->fillTriangle(42, 20, 42, 60, 90, 40, TFT_RED); - delay(500); - // pause - ttgo->eTFT->fillRoundRect(25, 90, 78, 60, 8, TFT_WHITE); - ttgo->eTFT->fillRoundRect(39, 98, 20, 45, 5, TFT_GREEN); - ttgo->eTFT->fillRoundRect(69, 98, 20, 45, 5, TFT_GREEN); - delay(500); - // play color - ttgo->eTFT->fillTriangle(42, 20, 42, 60, 90, 40, TFT_BLUE); - delay(50); - // pause color - ttgo->eTFT->fillRoundRect(39, 98, 20, 45, 5, TFT_RED); - ttgo->eTFT->fillRoundRect(69, 98, 20, 45, 5, TFT_RED); - // play color - ttgo->eTFT->fillTriangle(42, 20, 42, 60, 90, 40, TFT_GREEN); -} - +} \ No newline at end of file diff --git a/examples/TFT_eSPI/UTFT_demo_fast/UTFT_demo_fast.ino b/examples/TFT_eSPI/UTFT_demo_fast/UTFT_demo_fast.ino index 767caf9..db223c5 100644 --- a/examples/TFT_eSPI/UTFT_demo_fast/UTFT_demo_fast.ino +++ b/examples/TFT_eSPI/UTFT_demo_fast/UTFT_demo_fast.ino @@ -16,7 +16,13 @@ ###### DON'T FORGET TO UPDATE THE User_Setup.h FILE IN THE LIBRARY ###### ######################################################################### */ -#include + +// => Hardware select +// #define LILYGO_WATCH_2019_WITH_TOUCH // To use T-Watch2019 with touchscreen, please uncomment this line +// #define LILYGO_WATCH_2019_NO_TOUCH // To use T-Watch2019 Not touchscreen , please uncomment this line +// #define LILYGO_WATCH_2020_V1 //To use T-Watch2020, please uncomment this line + +#include TTGOClass *ttgo; #define DELAY 500 @@ -26,12 +32,14 @@ TTGOClass *ttgo; #define TFT_H 240 unsigned long runTime = 0; + void setup() { // Setup the LCD ttgo = TTGOClass::getWatch(); ttgo->begin(); ttgo->openBL(); + ttgo->tft->setTextFont(1); } void loop() @@ -44,51 +52,51 @@ void loop() int r; runTime = millis(); // Clear the screen and draw the frame - ttgo->eTFT->fillScreen(TFT_BLACK); + ttgo->tft->fillScreen(TFT_BLACK); - ttgo->eTFT->fillRect(0, 0, TFT_W - 1, 14, TFT_RED); + ttgo->tft->fillRect(0, 0, TFT_W - 1, 14, TFT_RED); - ttgo->eTFT->fillRect(0, TFT_H - 14, TFT_W - 1, 14, TFT_GREY); + ttgo->tft->fillRect(0, TFT_H - 14, TFT_W - 1, 14, TFT_GREY); - ttgo->eTFT->setTextColor(TFT_BLACK, TFT_RED); - ttgo->eTFT->drawCentreString("* TFT_S6D02A1 *", TFT_W / 2, 4, 1); - ttgo->eTFT->setTextColor(TFT_YELLOW, TFT_GREY); - ttgo->eTFT->drawCentreString("Adapted by Bodmer", TFT_W / 2, TFT_H - 12, 1); + ttgo->tft->setTextColor(TFT_BLACK, TFT_RED); + ttgo->tft->drawCentreString("* TFT_S6D02A1 *", TFT_W / 2, 4, 1); + ttgo->tft->setTextColor(TFT_YELLOW, TFT_GREY); + ttgo->tft->drawCentreString("Adapted by Bodmer", TFT_W / 2, TFT_H - 12, 1); - ttgo->eTFT->drawRect(0, 14, TFT_W - 1, TFT_H - 28, TFT_BLUE); + ttgo->tft->drawRect(0, 14, TFT_W - 1, TFT_H - 28, TFT_BLUE); // Draw crosshairs - ttgo->eTFT->drawLine(TFT_W / 2 - 1, 15, TFT_W / 2 - 1, TFT_H - 16, TFT_BLUE); - ttgo->eTFT->drawLine(1, TFT_H / 2 - 1, TFT_W - 2, TFT_H / 2 - 1, TFT_BLUE); + ttgo->tft->drawLine(TFT_W / 2 - 1, 15, TFT_W / 2 - 1, TFT_H - 16, TFT_BLUE); + ttgo->tft->drawLine(1, TFT_H / 2 - 1, TFT_W - 2, TFT_H / 2 - 1, TFT_BLUE); for (int i = 9; i < TFT_W - 1; i += 10) - ttgo->eTFT->drawLine(i, TFT_H / 2 - 3, i, TFT_H / 2 + 1, TFT_BLUE); + ttgo->tft->drawLine(i, TFT_H / 2 - 3, i, TFT_H / 2 + 1, TFT_BLUE); for (int i = 19; i < TFT_H - 20; i += 10) - ttgo->eTFT->drawLine(TFT_W / 2 - 3, i, TFT_W / 2 + 1, i, TFT_BLUE); + ttgo->tft->drawLine(TFT_W / 2 - 3, i, TFT_W / 2 + 1, i, TFT_BLUE); // Draw sin-, cos- and tan-lines - ttgo->eTFT->setTextColor(TFT_CYAN); - ttgo->eTFT->drawString("Sin", 5, 15, 2); + ttgo->tft->setTextColor(TFT_CYAN); + ttgo->tft->drawString("Sin", 5, 15, 2); for (int i = 1; i < TFT_W - 2; i++) { - ttgo->eTFT->drawPixel(i, TFT_H / 2 - 1 + (sin(((i * 2.26) * 3.14) / 180) * 48), TFT_CYAN); + ttgo->tft->drawPixel(i, TFT_H / 2 - 1 + (sin(((i * 2.26) * 3.14) / 180) * 48), TFT_CYAN); } - ttgo->eTFT->setTextColor(TFT_RED); - ttgo->eTFT->drawString("Cos", 5, 30, 2); + ttgo->tft->setTextColor(TFT_RED); + ttgo->tft->drawString("Cos", 5, 30, 2); for (int i = 1; i < TFT_W - 2; i++) { - ttgo->eTFT->drawPixel(i, TFT_H / 2 - 1 + (cos(((i * 2.26) * 3.14) / 180) * 48), TFT_RED); + ttgo->tft->drawPixel(i, TFT_H / 2 - 1 + (cos(((i * 2.26) * 3.14) / 180) * 48), TFT_RED); } - ttgo->eTFT->setTextColor(TFT_YELLOW); - ttgo->eTFT->drawString("Tan", 5, 45, 2); + ttgo->tft->setTextColor(TFT_YELLOW); + ttgo->tft->drawString("Tan", 5, 45, 2); for (int i = 1; i < TFT_W - 2; i++) { - ttgo->eTFT->drawPixel(i, TFT_H / 2 - 1 + (tan(((i * 2.26) * 3.14) / 180)), TFT_YELLOW); + ttgo->tft->drawPixel(i, TFT_H / 2 - 1 + (tan(((i * 2.26) * 3.14) / 180)), TFT_YELLOW); } delay(DELAY); - ttgo->eTFT->fillRect(1, 15, TFT_W - 3, TFT_H - 31, TFT_BLACK); + ttgo->tft->fillRect(1, 15, TFT_W - 3, TFT_H - 31, TFT_BLACK); - ttgo->eTFT->drawLine(TFT_W / 2 - 1, 15, TFT_W / 2 - 1, TFT_H - 16, TFT_BLUE); - ttgo->eTFT->drawLine(1, TFT_H / 2 - 1, TFT_W - 2, TFT_H / 2 - 1, TFT_BLUE); + ttgo->tft->drawLine(TFT_W / 2 - 1, 15, TFT_W / 2 - 1, TFT_H - 16, TFT_BLUE); + ttgo->tft->drawLine(1, TFT_H / 2 - 1, TFT_W - 2, TFT_H / 2 - 1, TFT_BLUE); int col = 0; // Draw a moving sinewave x = 1; @@ -100,16 +108,16 @@ void loop() if ((x == TFT_W / 2 - 1) || (buf[x - 1] == TFT_H / 2 - 1)) col = TFT_BLUE; else - ttgo->eTFT->drawPixel(x, buf[x - 1], TFT_BLACK); + ttgo->tft->drawPixel(x, buf[x - 1], TFT_BLACK); } y = TFT_H / 2 + (sin(((i * 2.2) * 3.14) / 180) * (49 - (i / 100))); - ttgo->eTFT->drawPixel(x, y, TFT_BLUE); + ttgo->tft->drawPixel(x, y, TFT_BLUE); buf[x - 1] = y; } delay(DELAY); - ttgo->eTFT->fillRect(1, 15, TFT_W - 3, TFT_H - 31, TFT_BLACK); + ttgo->tft->fillRect(1, 15, TFT_W - 3, TFT_H - 31, TFT_BLACK); // Draw some filled rectangles for (int i = 1; i < 6; i++) { @@ -130,12 +138,12 @@ void loop() col = TFT_YELLOW; break; } - ttgo->eTFT->fillRect(30 + (i * 10), 20 + (i * 10), 30, 30, col); + ttgo->tft->fillRect(30 + (i * 10), 20 + (i * 10), 30, 30, col); } delay(DELAY); - ttgo->eTFT->fillRect(1, 15, TFT_W - 3, TFT_H - 31, TFT_BLACK); + ttgo->tft->fillRect(1, 15, TFT_W - 3, TFT_H - 31, TFT_BLACK); // Draw some filled, rounded rectangles for (int i = 1; i < 6; i++) { @@ -156,12 +164,12 @@ void loop() col = TFT_YELLOW; break; } - ttgo->eTFT->fillRoundRect(TFT_W / 2 + 20 - (i * 10), 20 + (i * 10), 30, 30, 3, col); + ttgo->tft->fillRoundRect(TFT_W / 2 + 20 - (i * 10), 20 + (i * 10), 30, 30, 3, col); } delay(DELAY); - ttgo->eTFT->fillRect(1, 15, TFT_W - 3, TFT_H - 31, TFT_BLACK); + ttgo->tft->fillRect(1, 15, TFT_W - 3, TFT_H - 31, TFT_BLACK); // Draw some filled circles for (int i = 1; i < 6; i++) { @@ -182,47 +190,47 @@ void loop() col = TFT_YELLOW; break; } - ttgo->eTFT->fillCircle(45 + (i * 10), 30 + (i * 10), 15, col); + ttgo->tft->fillCircle(45 + (i * 10), 30 + (i * 10), 15, col); } delay(DELAY); - ttgo->eTFT->fillRect(1, 15, TFT_W - 3, TFT_H - 31, TFT_BLACK); + ttgo->tft->fillRect(1, 15, TFT_W - 3, TFT_H - 31, TFT_BLACK); // Draw some lines in a pattern for (int i = 15; i < TFT_H - 16; i += 5) { - ttgo->eTFT->drawLine(1, i, (i * 1.44) - 10, TFT_H - 17, TFT_RED); + ttgo->tft->drawLine(1, i, (i * 1.44) - 10, TFT_H - 17, TFT_RED); } for (int i = TFT_H - 17; i > 15; i -= 5) { - ttgo->eTFT->drawLine(TFT_W - 3, i, (i * 1.44) - 11, 15, TFT_RED); + ttgo->tft->drawLine(TFT_W - 3, i, (i * 1.44) - 11, 15, TFT_RED); } for (int i = TFT_H - 17; i > 15; i -= 5) { - ttgo->eTFT->drawLine(1, i, TFT_W + 11 - (i * 1.44), 15, TFT_CYAN); + ttgo->tft->drawLine(1, i, TFT_W + 11 - (i * 1.44), 15, TFT_CYAN); } for (int i = 15; i < TFT_H - 16; i += 5) { - ttgo->eTFT->drawLine(TFT_W - 3, i, TFT_W + 10 - (i * 1.44), TFT_H - 17, TFT_CYAN); + ttgo->tft->drawLine(TFT_W - 3, i, TFT_W + 10 - (i * 1.44), TFT_H - 17, TFT_CYAN); } delay(DELAY); - ttgo->eTFT->fillRect(1, 15, TFT_W - 3, TFT_H - 31, TFT_BLACK); + ttgo->tft->fillRect(1, 15, TFT_W - 3, TFT_H - 31, TFT_BLACK); // Draw some random circles for (int i = 0; i < 100; i++) { x = 32 + random(TFT_W - 2 - 32 - 30); y = 45 + random(TFT_H - 19 - 45 - 30); r = random(30); - ttgo->eTFT->drawCircle(x, y, r, random(0xFFFF)); + ttgo->tft->drawCircle(x, y, r, random(0xFFFF)); } delay(DELAY); - ttgo->eTFT->fillRect(1, 15, TFT_W - 3, TFT_H - 31, TFT_BLACK); + ttgo->tft->fillRect(1, 15, TFT_W - 3, TFT_H - 31, TFT_BLACK); // Draw some random rectangles for (int i = 0; i < 100; i++) { @@ -236,13 +244,13 @@ void loop() if (y2 < y) { r = y; y = y2; y2 = r; } - ttgo->eTFT->drawRect(x, y, x2 - x, y2 - y, random(0xFFFF)); + ttgo->tft->drawRect(x, y, x2 - x, y2 - y, random(0xFFFF)); } delay(DELAY); - ttgo->eTFT->fillRect(1, 15, TFT_W - 3, TFT_H - 31, TFT_BLACK); + ttgo->tft->fillRect(1, 15, TFT_W - 3, TFT_H - 31, TFT_BLACK); // Draw some random rounded rectangles for (int i = 0; i < 100; i++) { @@ -260,12 +268,12 @@ void loop() // We need a minimum size of 6 if ((x2 - x) < 6) x2 = x + 6; if ((y2 - y) < 6) y2 = y + 6; - ttgo->eTFT->drawRoundRect(x, y, x2 - x, y2 - y, 3, random(0xFFFF)); + ttgo->tft->drawRoundRect(x, y, x2 - x, y2 - y, 3, random(0xFFFF)); } delay(DELAY); - ttgo->eTFT->fillRect(1, 15, TFT_W - 3, TFT_H - 31, TFT_BLACK); + ttgo->tft->fillRect(1, 15, TFT_W - 3, TFT_H - 31, TFT_BLACK); //randomSeed(1234); int colour = 0; @@ -275,12 +283,12 @@ void loop() x2 = 2 + random(TFT_W - 4); y2 = 16 + random(TFT_H - 31); colour = random(0xFFFF); - ttgo->eTFT->drawLine(x, y, x2, y2, colour); + ttgo->tft->drawLine(x, y, x2, y2, colour); } delay(DELAY); - ttgo->eTFT->fillRect(1, 15, TFT_W - 3, TFT_H - 31, TFT_BLACK); + ttgo->tft->fillRect(1, 15, TFT_W - 3, TFT_H - 31, TFT_BLACK); #define RANDOM @@ -288,7 +296,7 @@ void loop() // Draw 10,000 pixels // It takes 30ms to calculate the 30,000 random numbers so this is not a true drawPixel speed test for (int i = 0; i < 10000; i++) { - ttgo->eTFT->drawPixel(2 + random(316), 16 + random(209), random(0xFFFF)); + ttgo->tft->drawPixel(2 + random(316), 16 + random(209), random(0xFFFF)); } #else // Draw 10,000 pixels to fill a 100x100 pixel box, better drawPixel speed test @@ -296,24 +304,24 @@ void loop() byte i = 100; while (i--) { byte j = 100; - while (j--) ttgo->eTFT->drawPixel(i + TFT_W / 2 - 50, j + TFT_H / 2 - 50, i + j); + while (j--) ttgo->tft->drawPixel(i + TFT_W / 2 - 50, j + TFT_H / 2 - 50, i + j); } #endif delay(DELAY); - ttgo->eTFT->fillScreen(TFT_BLUE); - ttgo->eTFT->fillRoundRect(20, 20, TFT_W - 40, TFT_H - 60, 6, TFT_RED); + ttgo->tft->fillScreen(TFT_BLUE); + ttgo->tft->fillRoundRect(20, 20, TFT_W - 40, TFT_H - 60, 6, TFT_RED); - ttgo->eTFT->setTextColor(TFT_WHITE, TFT_RED); - ttgo->eTFT->drawCentreString("That's it!", TFT_W / 2 - 1, 23, 2); - ttgo->eTFT->drawCentreString("Restarting in a", TFT_W / 2 - 1, 40, 2); - ttgo->eTFT->drawCentreString("few seconds...", TFT_W / 2 - 1, 57, 2); + ttgo->tft->setTextColor(TFT_WHITE, TFT_RED); + ttgo->tft->drawCentreString("That's it!", TFT_W / 2 - 1, 23, 2); + ttgo->tft->drawCentreString("Restarting in a", TFT_W / 2 - 1, 40, 2); + ttgo->tft->drawCentreString("few seconds...", TFT_W / 2 - 1, 57, 2); runTime = millis() - runTime; - ttgo->eTFT->setTextColor(TFT_GREEN, TFT_BLUE); - ttgo->eTFT->drawCentreString("Draw time: (msecs)", TFT_W / 2, TFT_H - 34, 2); - ttgo->eTFT->drawNumber(runTime - 11 * DELAY, TFT_W / 2 - 20, TFT_H - 17, 2); + ttgo->tft->setTextColor(TFT_GREEN, TFT_BLUE); + ttgo->tft->drawCentreString("Draw time: (msecs)", TFT_W / 2, TFT_H - 34, 2); + ttgo->tft->drawNumber(runTime - 11 * DELAY, TFT_W / 2 - 20, TFT_H - 17, 2); delay (5000); } diff --git a/examples/TFT_eSPI/fillScreen/fillScreen.ino b/examples/TFT_eSPI/fillScreen/fillScreen.ino index b97acae..b963519 100644 --- a/examples/TFT_eSPI/fillScreen/fillScreen.ino +++ b/examples/TFT_eSPI/fillScreen/fillScreen.ino @@ -1,5 +1,10 @@ +// => Hardware select +// #define LILYGO_WATCH_2019_WITH_TOUCH // To use T-Watch2019 with touchscreen, please uncomment this line +// #define LILYGO_WATCH_2019_NO_TOUCH // To use T-Watch2019 Not touchscreen , please uncomment this line +// #define LILYGO_WATCH_2020_V1 //To use T-Watch2020, please uncomment this line -#include + +#include TTGOClass *ttgo; @@ -14,12 +19,12 @@ void setup() void loop() { Serial.println("R"); - ttgo->eTFT->fillScreen(TFT_RED); + ttgo->tft->fillScreen(TFT_RED); delay(1000); Serial.println("G"); - ttgo->eTFT->fillScreen(TFT_GREEN); + ttgo->tft->fillScreen(TFT_GREEN); delay(1000); Serial.println("B"); - ttgo->eTFT->fillScreen(TFT_BLUE); + ttgo->tft->fillScreen(TFT_BLUE); delay(1000); }